Skip to content

Commit

Permalink
feat: visualvm을 위한 jmx설정과 테스트를 위해 다시 히카리풀 설정전으로 롤백
Browse files Browse the repository at this point in the history
  • Loading branch information
minsang-alt committed Nov 30, 2024
1 parent d3b4b0c commit 3ad150c
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 75 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/backend-prod-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ on:
branches:
- main
- develop
- staging/**
paths:
- "src/**"
jobs:
Expand Down Expand Up @@ -49,5 +50,6 @@ jobs:
docker rm -f agilehub-backend || true
docker pull ${{ env.DOCKER_HUB_REPOSITORY }}:${{ github.sha }}
docker run -v /var/log/backend:/app/logs \
-e HOST_IP=${{ secrets.NCP_HOST }} \
--env-file .env \
-d -p 8080:8080 --name agilehub-backend ${{ env.DOCKER_HUB_REPOSITORY }}:${{ github.sha }}
-d -p 8080:8080 -p 9010:9010 --name agilehub-backend ${{ env.DOCKER_HUB_REPOSITORY }}:${{ github.sha }}
14 changes: 13 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,17 @@ WORKDIR /app
COPY --from=build /app/build/libs/*.jar /app/agile.jar

EXPOSE 8080
EXPOSE 9010 # JMX 포트

ENTRYPOINT ["java"]
CMD ["-jar","-Dspring.profiles.active=prod","agile.jar"]
CMD [
"-jar",
"-Dspring.profiles.active=prod",
"-Dcom.sun.management.jmxremote",
"-Dcom.sun.management.jmxremote.port=9010",
"-Dcom.sun.management.jmxremote.rmi.port=9010",
"-Dcom.sun.management.jmxremote.ssl=false",
"-Dcom.sun.management.jmxremote.authenticate=false",
"-Djava.rmi.server.hostname=${HOST_IP}",
"agile.jar"
]
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@

import dynamicquad.agilehub.issue.domain.ProjectIssueSequence;
import dynamicquad.agilehub.issue.repository.ProjectIssueSequenceRepository;
import jakarta.annotation.PostConstruct;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

@Service
Expand All @@ -17,66 +14,66 @@
public class IssueNumberGenerator {

private final ProjectIssueSequenceRepository issueSequenceRepository;
private final RedisTemplate<String, String> redisTemplate;

@Value("${redis.issue.number.prefix}")
private String REDIS_ISSUE_PREFIX;

// @Transactional
// public String generate(String projectKey) {
// ProjectIssueSequence sequence = issueSequenceRepository.findByProjectKey(projectKey)
// .orElseThrow(() -> new IllegalArgumentException("ProjectIssueSequence not found"));
//
// sequence.updateLastNumber(sequence.getNextNumber());
// private final RedisTemplate<String, String> redisTemplate;
//
// return projectKey + "-" + sequence.getLastNumber();
// }
// @Value("${redis.issue.number.prefix}")
// private String REDIS_ISSUE_PREFIX;

@Transactional(propagation = Propagation.REQUIRES_NEW)
public String generate(String projectKey) {
String redisKey = REDIS_ISSUE_PREFIX + projectKey;
Long nextNumber = redisTemplate.opsForValue().increment(redisKey);
return projectKey + "-" + nextNumber;
}

@Scheduled(fixedDelay = 1000L * 30L)
@Transactional
public void syncWithDatabase() {
issueSequenceRepository.findAll().forEach(sequence -> {
String redisKey = REDIS_ISSUE_PREFIX + sequence.getProjectKey();
String currentValue = redisTemplate.opsForValue().get(redisKey);

if (currentValue != null) {
try {
int redisValue = Integer.parseInt(currentValue);
ProjectIssueSequence sequence = issueSequenceRepository.findByProjectKey(projectKey)
.orElseThrow(() -> new IllegalArgumentException("ProjectIssueSequence not found"));

// 현재 DB 값보다 큰 경우에만 업데이트
if (redisValue > sequence.getLastNumber()) {
sequence.updateLastNumber(redisValue);
log.debug("Synced sequence for project {}: {}",
sequence.getProjectKey(), redisValue);
}
sequence.updateLastNumber(sequence.getNextNumber());

} catch (NumberFormatException e) {
log.error("Invalid number format in Redis for key: {}", redisKey, e);
redisTemplate.delete(redisKey);
}
}
});
return projectKey + "-" + sequence.getLastNumber();
}

// public String generate(String projectKey) {
// String redisKey = REDIS_ISSUE_PREFIX + projectKey;
// Long nextNumber = redisTemplate.opsForValue().increment(redisKey);
// return projectKey + "-" + nextNumber;
// }
//
// @Scheduled(fixedDelay = 1000L * 30L)
// @Transactional
// public void syncWithDatabase() {
// issueSequenceRepository.findAll().forEach(sequence -> {
// String redisKey = REDIS_ISSUE_PREFIX + sequence.getProjectKey();
// String currentValue = redisTemplate.opsForValue().get(redisKey);
//
// if (currentValue != null) {
// try {
// int redisValue = Integer.parseInt(currentValue);
//
// // 현재 DB 값보다 큰 경우에만 업데이트
// if (redisValue > sequence.getLastNumber()) {
// sequence.updateLastNumber(redisValue);
// log.debug("Synced sequence for project {}: {}",
// sequence.getProjectKey(), redisValue);
// }
//
// } catch (NumberFormatException e) {
// log.error("Invalid number format in Redis for key: {}", redisKey, e);
// redisTemplate.delete(redisKey);
// }
// }
// });
// }

public void decrement(String projectKey) {
ProjectIssueSequence sequence = issueSequenceRepository.findByProjectKey(projectKey)
.orElseThrow(() -> new IllegalArgumentException("ProjectIssueSequence not found"));

sequence.decrement();
}

@PostConstruct
public void initializeRedis() {
issueSequenceRepository.findAll().forEach(seq -> {
String redisKey = REDIS_ISSUE_PREFIX + seq.getProjectKey();
redisTemplate.opsForValue().set(redisKey, String.valueOf(seq.getLastNumber()));
});
}
// @PostConstruct
// public void initializeRedis() {
// issueSequenceRepository.findAll().forEach(seq -> {
// String redisKey = REDIS_ISSUE_PREFIX + seq.getProjectKey();
// redisTemplate.opsForValue().set(redisKey, String.valueOf(seq.getLastNumber()));
// });
// }

}
22 changes: 0 additions & 22 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,6 @@ spring:
file-size-threshold: 0B
enabled: true

datasource:
hikari:
# 풀 사이즈 설정
maximum-pool-size: 8
minimum-idle: 8

# 시간 관련 설정
max-lifetime: 50000 # 50초, DB wait_timeout보다 작게
connection-timeout: 5000 # 5초, 빠른 응답이 필요한 API
validation-timeout: 1000 # 1초, connection-timeout보다 작게

# 톰켓 설정
server:
tomcat:
accept-count: 100 # max-connections를 초과하는 요청에 대한 대기열 크기, 대기열이 가득 차면 추가 요청은 거절됨, OS 레벨에서 관리되는 설정
max-connections: 8192 # 서버가 동시에 유지할 수 있는 최대 연결 수, 실제 활성화된 TCP 연결의 수가 아님, 시스템이 할당한 소켓 파일 디스크립터의 수를 의미, 연결이 종료되어도 TIME_WAIT 상태 때문에 파일 디스크립터는 바로 해제되지 않음
threads:
max: 10 # 최대 스레드 수
min-spare: 10 # 초기 스레드 풀 사이즈





springdoc:
Expand Down

0 comments on commit 3ad150c

Please sign in to comment.