Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 댓글과 사용자를 분리 #460

Merged
merged 8 commits into from
Mar 22, 2024
Merged

feat: 댓글과 사용자를 분리 #460

merged 8 commits into from
Mar 22, 2024

Conversation

kong-hana01
Copy link
Collaborator

관련 이슈번호

작업 사항

    1. Comment와 Member의 패키지 구조 분리
    • 객체 참조 -> ID 참조로 변경
    • 댓글 조회 시 필요한 값만 받아서 서비스에 넘겨주도록 변경(dto 반환)
    1. Comment 조회 시 인덱스 추가 설정
    • roomId가 조건절에서 쓰이기에 이를 인덱스에서 사용
    • id를 내림차순으로 정렬한 뒤 조회하는데 backward index scan은 오름차순보다 다소 느려 id desc 인덱스를 추가해 최적화 진행
    1. tomcat, hikaricp 쓰레드 및 connection 개수 튜닝
    • 톰캣 최대 쓰레드는 이전에 결정한 16개, connection 최대 개수는 성능 테스트 이후 44개로 튜닝했습니다.
  • 최종 시간: 50만개의 댓글이 있을 때 10명의 유저가 각 1000번의 댓글 조회 요청을 보내는 경우 335ms -> 209ms로 응답 시간 단축

기타 사항

    1. Comment 조회 시 커버링 인덱스를 적용하고자 몇 가지 실험을 했었습니다.
    • (1) 커버링 인덱스를 사용하지 않고 조회(1번 쿼리 발생)
    • (2) 댓글 id에 대해 커버링 인덱스 적용된 쿼리로 조회 후 in 연산자로 id에 해당하는 댓글 정보 추가 조회(2번 쿼리 발생)
    • (3) 서브 쿼리로 댓글 id에 대해 커버링 인덱스 적용된 쿼리 조회(1번 쿼리 발생)
    • (4) 댓글 id에 대해 커버링 인덱스 적용된 쿼리로 조회 후 in 연산자로 id에 해당하는 댓글 정보 및 사용자 정보 추가 조회(3번 쿼리 발생, 댓글 id, 사용자 정보 모두 커버링 인덱스 적용)
  • 위의 네 가지 케이스를 가지고 테스트를 진행했고, (4)번의 경우 쿼리가 순차적으로 나가면 오랜 시간이 걸려 빠르게 처리하고자 쓰레드 풀을 활용했고, Connetion 부족으로 인해 데드락이 발생해 tomcat max thread, hikaricp max connection을 조절했습니다.

@kong-hana01 kong-hana01 self-assigned this Mar 13, 2024
@kong-hana01 kong-hana01 changed the title Feature/459 feat: 댓글과 사용자를 분리한다. Mar 14, 2024
@kong-hana01 kong-hana01 changed the title feat: 댓글과 사용자를 분리한다. feat: 댓글과 사용자를 분리 Mar 14, 2024
@0chil
Copy link
Collaborator

0chil commented Mar 20, 2024

오랜만입니다 콩 ㅎㅎ 멋진 실험과 그에 근거한 변경사항 잘 보았습니다.
궁금한 내용들이 조금 있는데 ㅎㅎ 괜찮으시면 게더나 오프라인에서 대화 가능할까요?

질문할 내용은 다음과 같습니다.

  1. 잘 지내시나요 ㅎㅎ

  2. Comment가 분리되어야 했던 이유, DTO를 통한 조인이 필요했던 이유

  • "Comment에서 Member참조를 제거했기 때문에 객체 그래프를 통한 탐색이 불가능해졌기 때문"이 맞을까요?
  1. MemberNickname이 Projection을 통해 분리된 이유?
  • "CommentResponse에서 comment.getMember().getNickname()을 하고 있었으나, 마찬가지로 객체 그래프 탐색이 불가해졌기 때문"이 맞을까요?


import java.time.LocalDateTime;

public record CommentMember(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

: comment 와 member를 조인했으므로 commentMember

Comment on lines +75 to +77
MemberNickname memberNickname = memberRepository.getMemberNickname(memberId);

Comment comment = new Comment(roomId, request.comment(), member);
Comment comment = new Comment(roomId, request.comment(), memberId);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

: 더 재활용하기 쉬운 형태를 찾아보기로 함

@@ -0,0 +1 @@
CREATE INDEX COMMENT_ROOM_ID_COMMENT_ID_IDX ON comment (room_id, id desc);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

우리가 댓글을 Id 순으로 가져오고 있었군요
일단 OK 입니다 👍

Copy link
Collaborator

@0chil 0chil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

바쁘셨을텐데 커버링 인덱스에 대한 테스트 및 커멘트 테이블에 대한 인덱싱까지 해주셨네요.
고생하셨고 바로 머지해도 좋을 것 같습니다!

@kong-hana01 kong-hana01 merged commit 2f33705 into backend Mar 22, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants