From b9f4070fc3dd24e8985e68da526e17cd2718e630 Mon Sep 17 00:00:00 2001 From: fromitive <46563149+fromitive@users.noreply.github.com> Date: Fri, 25 Oct 2024 00:34:20 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EC=84=B1=EB=8A=A5=20=ED=8A=9C=EB=8B=9D?= =?UTF-8?q?=20=EB=B0=8F=20=EB=AC=B4=EC=A4=91=EB=8B=A8=20=EB=B0=B0=ED=8F=AC?= =?UTF-8?q?=20=EC=A0=81=EC=9A=A9=20(#651)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: HikariCP, Tomcat 튜닝 (#644) * refactor: 임시로 DEV CI/CD 스크립트 수정 * refactor: branch 경로 수정 및 docker에만 push 할 수 있도록 수정 * refactor: accept-count 200 * refactor: - accept-count 200, + hikari max pool size 50 * refactor: + hikari max pool size 200 * refactor: - hikari max pool size 30 * refactor: OfferingEntity의 Member에 FetchType.LAZY 설정 및 트랜잭션 추가 * refactor: getAllOffering에 트렌젝션 적용 * chore: actuator에 hikariCP 메트릭 지표 추가 * refactor: - hikari max pool size 20 * refactor: + hikari max pool size 40 * refactor: - hikari max pool size 30 * refactor: - hikari max pool size 20 * refactor: + hikari max pool size 50 * refactor: - hikari max pool size 4 * refactor: + hikari max pool size 40 * refactor: hikari max pool size default(10) * refactor: + hikari max pool size 8 * refactor: 테스트를 위해 공모 생성 시 알림 off * refactor: - tomcat max threads 3 * refactor: + tomcat max threads 100 * refactor: default로 회귀 * feat: HikariCP, Tomcat 설정 및 주석 해제 * refactor: metric 관련 설정 제거 --------- Co-authored-by: fromitive Co-authored-by: Choo * chore: prod yml ci/cd를 blue & green 으로 변경 (#650) --------- Co-authored-by: masonkimseoul <87306418+masonkimseoul@users.noreply.github.com> Co-authored-by: Choo --- .github/workflows/backend-dev-ci-cd.yml | 2 +- .github/workflows/backend-prod-ci-cd.yml | 43 +++++++++---------- .../repository/entity/OfferingEntity.java | 3 +- .../offering/service/OfferingService.java | 3 ++ backend/src/main/resources/application.yml | 9 ++++ 5 files changed, 36 insertions(+), 24 deletions(-) diff --git a/.github/workflows/backend-dev-ci-cd.yml b/.github/workflows/backend-dev-ci-cd.yml index 7b872a4ee..2ec670248 100644 --- a/.github/workflows/backend-dev-ci-cd.yml +++ b/.github/workflows/backend-dev-ci-cd.yml @@ -8,7 +8,7 @@ on: - ".github/workflows/backend-dev-ci-cd.yml" - "Dockerfile" # pull_request: - # branches: [ "develop" ] + # branches: [ "chongdae" ] # paths: # - "backend/**" # - ".github/workflows/backend-dev-ci-cd.yml" diff --git a/.github/workflows/backend-prod-ci-cd.yml b/.github/workflows/backend-prod-ci-cd.yml index 10f6faacb..83b353135 100644 --- a/.github/workflows/backend-prod-ci-cd.yml +++ b/.github/workflows/backend-prod-ci-cd.yml @@ -61,30 +61,29 @@ jobs: docker tag ${{ secrets.BE_DOCKER_IMAGE_NAME_PROD }} ${{ secrets.BE_DOCKERHUB_USERNAME }}/${{ secrets.BE_DOCKER_IMAGE_NAME_PROD }}:${GITHUB_SHA::7} docker push ${{ secrets.BE_DOCKERHUB_USERNAME }}/${{ secrets.BE_DOCKER_IMAGE_NAME_PROD }}:${GITHUB_SHA::7} - deploy-a: - needs: build-and-test - runs-on: prod-a - + deploy-new-container: + needs: build-and-test + strategy: + matrix: + runner: [prod-a, prod-b] + runs-on: [ self-hosted, ${{ matrix.runner }} ] steps: - - name: Pull Image And Restart Container on Production A - run: | - docker login -u ${{ secrets.BE_DOCKERHUB_USERNAME }} -p ${{ secrets.BE_DOCKERHUB_PASSWORD }} - docker stop ${{ secrets.BE_DOCKER_CONTAINER_NAME }} | true - docker rm ${{ secrets.BE_DOCKER_CONTAINER_NAME }} | true - docker image prune -a -f - docker pull ${{ secrets.BE_DOCKERHUB_USERNAME }}/${{ secrets.BE_DOCKER_IMAGE_NAME_PROD }}:${GITHUB_SHA::7} - docker run --name ${{ secrets.BE_DOCKER_CONTAINER_NAME }} -d -v /logs:/logs -p 80:8080 -e SPRING_PROFILES_ACTIVE=prod ${{ secrets.BE_DOCKERHUB_USERNAME }}/${{ secrets.BE_DOCKER_IMAGE_NAME_PROD }}:${GITHUB_SHA::7} + - name: Checkout repository + uses: actions/checkout@v4 - deploy-b: - needs: deploy-a - runs-on: prod-b + - name: Deploy new container on ${{ matrix.runner }} + run: | + bash launch_next_container.sh ${GITHUB_SHA::7} prod ${{ secrets.BE_DOCKERHUB_USERNAME }} ${{ secrets.BE_DOCKER_IMAGE_NAME_PROD }} + working-directory: backend/deploy + switch-new-container: + needs: deploy-new-container + strategy: + matrix: + runner: [prod-a, prod-b] + runs-on: [ self-hosted, ${{ matrix.runner }} ] steps: - - name: Pull Image And Restart Container on Production B + - name: Switch from old to new container on ${{ matrix.runner }} run: | - docker login -u ${{ secrets.BE_DOCKERHUB_USERNAME }} -p ${{ secrets.BE_DOCKERHUB_PASSWORD }} - docker stop ${{ secrets.BE_DOCKER_CONTAINER_NAME }} | true - docker rm ${{ secrets.BE_DOCKER_CONTAINER_NAME }} | true - docker image prune -a -f - docker pull ${{ secrets.BE_DOCKERHUB_USERNAME }}/${{ secrets.BE_DOCKER_IMAGE_NAME_PROD }}:${GITHUB_SHA::7} - docker run --name ${{ secrets.BE_DOCKER_CONTAINER_NAME }} -d -v /logs:/logs -p 80:8080 -e SPRING_PROFILES_ACTIVE=prod ${{ secrets.BE_DOCKERHUB_USERNAME }}/${{ secrets.BE_DOCKER_IMAGE_NAME_PROD }}:${GITHUB_SHA::7} + bash switch_blue_green_container.sh + working-directory: backend/deploy \ No newline at end of file diff --git a/backend/src/main/java/com/zzang/chongdae/offering/repository/entity/OfferingEntity.java b/backend/src/main/java/com/zzang/chongdae/offering/repository/entity/OfferingEntity.java index 81b0aaf85..d3d9cf802 100644 --- a/backend/src/main/java/com/zzang/chongdae/offering/repository/entity/OfferingEntity.java +++ b/backend/src/main/java/com/zzang/chongdae/offering/repository/entity/OfferingEntity.java @@ -12,6 +12,7 @@ import jakarta.persistence.Entity; import jakarta.persistence.EnumType; import jakarta.persistence.Enumerated; +import jakarta.persistence.FetchType; import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; import jakarta.persistence.Id; @@ -48,7 +49,7 @@ public class OfferingEntity extends BaseTimeEntity { private Long id; @NotNull - @ManyToOne + @ManyToOne(fetch = FetchType.LAZY) private MemberEntity member; @NotNull diff --git a/backend/src/main/java/com/zzang/chongdae/offering/service/OfferingService.java b/backend/src/main/java/com/zzang/chongdae/offering/service/OfferingService.java index c7994bc1e..2a6f682a3 100644 --- a/backend/src/main/java/com/zzang/chongdae/offering/service/OfferingService.java +++ b/backend/src/main/java/com/zzang/chongdae/offering/service/OfferingService.java @@ -54,6 +54,7 @@ public class OfferingService { private final OfferingFetcher offeringFetcher; private final Clock clock; + @Transactional(readOnly = true) public OfferingDetailResponse getOfferingDetail(Long offeringId, MemberEntity member) { OfferingEntity offering = offeringRepository.findById(offeringId) .orElseThrow(() -> new MarketException(OfferingErrorCode.NOT_FOUND)); @@ -72,6 +73,7 @@ public OfferingAllResponseItem getOffering(Long offeringId) { return new OfferingAllResponseItem(offering, offeringPrice); } + @Transactional(readOnly = true) public OfferingAllResponse getAllOffering(String filterName, String searchKeyword, Long lastId, Integer pageSize) { Pageable pageable = PageRequest.ofSize(pageSize); OfferingFilter filter = OfferingFilter.findByName(filterName); @@ -186,6 +188,7 @@ private void updateStatus(OfferingEntity offering) { // TODO : 도메인 분리 } @WriterDatabase + @Transactional public void deleteOffering(Long offeringId, MemberEntity member) { OfferingEntity offering = offeringRepository.findById(offeringId) .orElseThrow(() -> new MarketException(OfferingErrorCode.NOT_FOUND)); diff --git a/backend/src/main/resources/application.yml b/backend/src/main/resources/application.yml index afdf484dc..8ef0d9c9b 100644 --- a/backend/src/main/resources/application.yml +++ b/backend/src/main/resources/application.yml @@ -1,8 +1,17 @@ +server: + tomcat: + threads: + max: 35 + max-connections: 1024 + accept-count: 242 + spring: application: name: chongdae datasource: url: jdbc:h2:mem:database + hikari: + maximum-pool-size: 8 jpa: show-sql: true defer-datasource-initialization: true