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

Socket: ✨ GUID Configuration based on a Time-Sorted Identifier #170

Merged
merged 4 commits into from
Oct 10, 2024

Conversation

psychology50
Copy link
Member

작업 이유

  • 실시간 채팅 정보를 DB에 저장하는 것에는 무리가 있기에, NoSQL에 일정 기간 캐싱을 해둘 예정.
  • 이로 인해, auto_increment 방식의 고유 ID를 생성할 수 없음.
  • 따라서, 애플리케이션 단에서 다음의 요구 사항을 충족하는 GUID 생성기를 구축할 필요성 제기
    • ID는 유일성을 보장해야 한다.
    • ID는 숫자로만 구성되어 있어야 한다.
    • ID는 64bit로 표현 가능해야 한다.
    • ID는 발급 날짜에 따라 정렬 가능해야 한다.
    • 초당 10,000개의 ID를 만들 수 있어야 한다. (절충할 수 있는 부분)

작업 사항

image
image

  • 라이브러리는 f4b6a3을 사용했습니다.
  • 64-bit(timestamp(42bit) + node(8bit) + counter(14bit)) 크기를 가지며, 128-bit UUID에 비해 훨씬 적은 공간을 차지합니다.
    • node bit 8-bit는 Factory로 조절할 수 있지만, 저희가 채팅 서버를 8개나 띄울 일이 없습니다.
    • 분산 코디네이션 없이, 각 서버에게 node id를 할당하기도 어렵기 때문에 8-bit로 고정해버렸습니다.
  • counter bit가 14-bit이므로, ms 당 16,383개의 고유 ID를 생성할 수 있습니다.
  • 정수 데이터를 가지기 때문에 DB 조인 성능이 상당히 빠릅니다.
  • ID 순서로 정렬하면, 곧 생성 순서와 동일합니다.
    • created_at은 동일 ms에서 생성한 데이터를 정렬하지 못 하기 때문에, id가 이를 수행할 수 있어야 합니다.
  • ID 생성 시간 또한 가장 빠르진 않지만, 준수한 성능을 가집니다.

리뷰어가 중점적으로 확인해야 하는 부분

  • 직접 확인해보고 싶다면, 제 깃헙을 참조해주세요.

발견한 이슈

  • 없음.

@psychology50 psychology50 added the enhancement New feature or request label Oct 10, 2024
@psychology50 psychology50 self-assigned this Oct 10, 2024
@psychology50 psychology50 merged commit 396815d into dev Oct 10, 2024
1 check passed
@psychology50 psychology50 deleted the feat/PW-564-generate-guid branch October 10, 2024 10:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant