Skip to content

Commit

Permalink
feat: 리뷰 쿼리 성능 테스트를 위한 세팅
Browse files Browse the repository at this point in the history
* 조인을 사용하는 쿼리와 사용하지 않는 쿼리
  • Loading branch information
EunChanNam committed Dec 7, 2023
1 parent f03d439 commit 0f5fe36
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 89 deletions.
44 changes: 17 additions & 27 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,33 +32,23 @@ jobs:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}

# - name: 환경변수 파일 생성
# run: echo "${{ secrets.APPLICATION_ENV }}" > ./.env
#
# - name: 환경변수 파일을 서버로 전송한다
# uses: appleboy/[email protected]
# with:
# host: ${{ secrets.HOST }}
# username: ${{ secrets.USERNAME }}
# key: ${{ secrets.PRIVATE_KEY }}
# port: ${{ secrets.PORT }}
# source: "./.env"
# target: "./"

# - name: ubuntu Docker image build and push
# run: |
# docker-compose -f ./docker/docker-compose.yml build
# docker-compose -f ./docker/docker-compose.yml push
- name: ubuntu Docker image build
run: docker build -t ${{ secrets.DOCKER_NAME }}/we-share-wish-hair:latest -f Dockerfile-server .

- name: Redis Docker image build
run: docker build -t ${{ secrets.DOCKER_NAME }}/we-share-wish-hair:redis -f Dockerfile-redis .
- name: 환경변수 파일 생성
run: echo "${{ secrets.APPLICATION_ENV }}" > ./.env

- name: ubuntu docker Hub 푸쉬
run: docker push ${{ secrets.DOCKER_NAME }}/we-share-wish-hair:latest
- name: Redis docker Hub 푸쉬
run: docker push ${{ secrets.DOCKER_NAME }}/we-share-wish-hair:redis
- name: ubuntu Docker image build and push
run: |
docker-compose -f ./docker-compose.yml build~
docker-compose -f ./docker-compose.yml push
# - name: ubuntu Docker image build
# run: docker build -t ${{ secrets.DOCKER_NAME }}/we-share-wish-hair:latest -f Dockerfile-server .
#
# - name: Redis Docker image build
# run: docker build -t ${{ secrets.DOCKER_NAME }}/we-share-wish-hair:redis -f Dockerfile-redis .
#
# - name: ubuntu docker Hub 푸쉬
# run: docker push ${{ secrets.DOCKER_NAME }}/we-share-wish-hair:latest
# - name: Redis docker Hub 푸쉬
# run: docker push ${{ secrets.DOCKER_NAME }}/we-share-wish-hair:redis

- name: Deploy with push
uses: appleboy/[email protected]
Expand All @@ -73,7 +63,7 @@ jobs:
sudo docker stop wswh-redis || true
sudo docker container prune -f
sudo docker pull ${{ secrets.DOCKER_NAME }}/we-share-wish-hair:latest
sudo docker run -d --log-driver=syslog --env-file .env \
sudo docker run -d --log-driver=syslog \
-p 8080:8080 --name we-share-wish-hair \
${{ secrets.DOCKER_NAME }}/we-share-wish-hair:latest
sudo docker pull ${{ secrets.DOCKER_NAME }}/we-share-wish-hair:redis
Expand Down
28 changes: 28 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
version: '3'
services:
server:
image: openjdk:17-alpine
restart: always
env_file:
- .env
volumes:
- ./build/libs:/home
command: ["java", "-jar",
"-Dspring.profiles.active=prod",
"/home/advanced-we-share-wish-hair-0.0.1-SNAPSHOT.jar"]
ports:
- '8080:8080'
platform: linux/amd64
networks:
- my-net

redis:
image: redis:latest
ports:
- '6379:6379'
platform: linux/amd64
networks:
- my-net

networks:
my-net:
15 changes: 0 additions & 15 deletions docker/docker-compose.yml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ public void addInterceptors(final InterceptorRegistry registry) {
.addExcludePathPattern("/api/users/refresh/*")
.addExcludePathPattern("/api/like/test/clean")
.addExcludePathPattern("/api/like/test/count/**")
.addExcludePathPattern("/api/email/*");
.addExcludePathPattern("/api/email/*")
.addExcludePathPattern("/api/reviews/test/**");

registry
.addInterceptor(pathMatcherInterceptor)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ public void decreaseData(Long key) {
}

public Optional<Long> getData(Long key) {
Long value = redisTemplate.opsForValue().get(String.valueOf(key));
return Optional.ofNullable(
redisTemplate.opsForValue().get(String.valueOf(key))
value
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public LikeReviewResponse checkIsLiking(Long userId, Long reviewId) {

public Long getLikeCount(Long reviewId) {
return redisUtils.getData(reviewId)
.orElse(updateLikeCountFromRedis(reviewId));
.orElseGet(() -> updateLikeCountFromRedis(reviewId));
}

public List<Long> getLikeCounts(List<Long> reviewIds) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@
import java.util.List;

import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.inq.wishhair.wesharewishhair.global.dto.response.ResponseWrapper;
import com.inq.wishhair.wesharewishhair.review.application.dto.response.ReviewResponse;
import com.inq.wishhair.wesharewishhair.review.application.dto.response.ReviewResponseAssembler;
import com.inq.wishhair.wesharewishhair.review.application.LikeReviewService;
import com.inq.wishhair.wesharewishhair.review.domain.entity.Review;
import com.inq.wishhair.wesharewishhair.review.infrastructure.ReviewQueryDslRepository;
import com.inq.wishhair.wesharewishhair.review.infrastructure.ReviewQueryResponse;

import lombok.RequiredArgsConstructor;

Expand All @@ -21,19 +19,19 @@
public class ReviewQueryTestController {

private final ReviewQueryDslRepository reviewQueryDslRepository;
private final LikeReviewService likeReviewService;

@Transactional(readOnly = true)
public ResponseWrapper<ReviewResponse> withJoin() {
List<Review> reviews = reviewQueryDslRepository.joinWithLikeQuery()
.stream()
.map(ReviewQueryResponse::getReview)
.toList();
return ReviewResponseAssembler.toWrappedReviewResponse(reviews);
@GetMapping("/join")
public void withJoin() {
reviewQueryDslRepository.joinWithLikeQuery();
}

@Transactional(readOnly = true)
public ResponseWrapper<ReviewResponse> withoutJoin() {
@GetMapping("/no_join")
public void withoutJoin() {
List<Review> reviews = reviewQueryDslRepository.noJoinQuery();
return ReviewResponseAssembler.toWrappedReviewResponse(reviews);
List<Long> reviewIds = reviews.stream().map(Review::getId).toList();
likeReviewService.getLikeCounts(reviewIds);
}
}
2 changes: 1 addition & 1 deletion src/main/resources/application-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ server:
spring:
data:
redis:
host: 3.21.14.25
host: localhost
port: 6379
expire-time: 21600000

Expand Down
43 changes: 12 additions & 31 deletions src/main/resources/application-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ spring:

datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://wswh-master-db.cgr8ovkfv2rw.us-east-2.rds.amazonaws.com/wswh_db
username: admin
password: dksk7946447
url: ${URL}
username: ${USERNAME}
password: ${PW}

jpa:
hibernate:
Expand All @@ -30,8 +30,8 @@ spring:
mail:
host: smtp.gmail.com
port: 587
username: [email protected]
password: qkvpxhpgyuywcbgh
username: ${MAIL_USERNAME}
password: ${MAIL_PW}
protocol: smtp
properties:
mail:
Expand Down Expand Up @@ -60,42 +60,23 @@ decorator:

#JWT key
jwt:
secret-key: abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabc
access-token-validity: 180000000
refresh-token-validity: 259200000
secret-key: ${JWT_KEY}
access-token-validity: ${ACCESS_VALIDITY}
refresh-token-validity: ${REFRESH_VALIDITY}

# 네이버 클라우드 오브젝트 스토리지
cloud:
aws:
credentials:
access-key: N3JCSJUtgse4alKEaOqX
secret-key: rRamLrfUV8v6ZziJFEN4CVLjE9rl4kCBnEOLje5f
access-key: ${S3_ACCESS_KEY}
secret-key: ${S3_SECRET_KEY}
stack:
auto: false
region:
static: ap-northeast-2
s3:
endpoint: https://kr.object.ncloudstorage.com
bucket: wswh-storage
bucket: ${S3_BUCKET}
logging:
level:
root: info
---
spring:
config:
activate:
on-profile: dev

datasource:
master:
hikari:
username: root
password: 1234
driver-class-name: com.mysql.cj.jdbc.Driver
jdbc-url: jdbc:mysql://localhost:3306/db
slave:
hikari:
username: root
password: 1234
driver-class-name: com.mysql.cj.jdbc.Driver
jdbc-url: jdbc:mysql://localhost:3307/db
root: info

0 comments on commit 0f5fe36

Please sign in to comment.