TIL.
-
TroubleShooting - Socket Transports 설정TIL. 2024. 9. 3. 18:52
서버 부하를 효율적으로 관리하기 위해 로드밸런서를 도입하고 Redis 어댑터를 설정했지만, 지속적으로 요청이 전송되면서도 연결은 이루어지지 않는 문제가 발생했습니다.Socket.IO의 기본 전송 방식은 polling으로 설정되어 있습니다. polling은 주기적으로 HTTP 요청을 보내어 연결을 유지하지만, 분산된 환경에서는 요청이 다른 서버로 전달될 경우 소켓 연결이 끊어질 수 있습니다. Polling해당 문제를 해결하기 위해서 처음 요청이 이루어지는 서버와 지속적인 연결을 유지시켜야만 했습니다.공식 문서를 통해 전송 방식을 WebSocket 방식으로 바꿀 수 있음을 알게 되었습니다. 해결 방법 1 : Polling -> WebSocket WebSocket웹소켓 방식은 클라이언트와 서버 간에 지속적..
-
TroubleShooting - 로드밸런서 환경에서의 Socket 연결 (Redis Adapter, Redis Pub/Sub)TIL. 2024. 9. 2. 23:17
서버 부하를 효율적으로 관리하기 위해 로드밸런서를 도입한 후, 일부 유저가 Socket 연결에 실패하거나 연결이 불안정해지는 문제가 발생했습니다. 원인로드밸런서 도입으로 인해 소켓 연결이 분산된 서버들로 나누어졌고, 이로 인해 서버 간의 소켓 연결 정보가 공유되지 않아 일부 유저가 연결 오류를 겪었습니다. Redis Pub/Sub 및 Redis Adapter를 도입하여 분산된 서버 간의 소켓 연결 정보를 통합적으로 관리했습니다. 이를 통해 각 서버가 동일한 소켓 연결 상태를 공유하게 되어, 모든 유저에게 안정적인 실시간 연결을 제공할 수 있게 되었습니다. RedisAdapter 설정 기존에 사용하고 있는 Redis 클라이언트의 환경변수를 사용하고 있습니다.main.ts Socket.IO 공식문서에서 제공..
-
NestJS : 순환 참조TIL. 2024. 8. 12. 09:58
현재 진행하고 있는 프로젝트에서 소켓을 이용한 실시간 채팅을 구현하였습니다. 구현 과정에서 여러가지 문제들을 겪었고 그 중 하나로 순환 참조에 대해 작성해보겠습니다. 순환참조순환 종속성은 두 클래스가 서로 종속될 때 발생합니다. 예를 들어 클래스 A에는 클래스 B가 필요하고 클래스 B에도 클래스 A가 필요합니다. 모듈 간 및 공급자 간에 중첩에서 순환 종속성이 발생할 수 있습니다.가능한 경우 순환 종속성을 피해야 하지만 항상 그렇게 할 수는 없습니다. 이러한 경우 Nest는 두 가지 방법으로 공급자 간의 순환 종속성을 해결할 수 있습니다. 이 장에서는 정방향 참조를 하나의 기술로 사용하고 ModuleRef 클래스를 사용하여 DI 컨테이너에서 제공자 인스턴스를 검색하는 다른 기술을 설명합니다.또한 모듈 ..
-
재귀함수와 반복문TIL. 2024. 8. 6. 11:39
오늘은 알고리즘 문제 예상 대진표를 풀며 알게된 재귀 함수와 반복문의 차이점에 대해 작성해보겠습니다. 문제를 풀며 제가 사용한 재귀 함수입니다.function solution(n, a, b) { let round = 0; const recursion = (a, b, round) => { if (a !== b) { return recursion(Math.ceil(a / 2), Math.ceil(b / 2), round + 1); } return round; }; const answer = recursion(a, b, round); return answer;} a와 b가 동일한 값을 가질때까지 나눠진 뒤 올림 처리 되는 것을 볼 수 있습니다. 이를 반복문으로 표현한다면..
-
자료구조 : Linked ListTIL. 2024. 7. 19. 02:30
오늘은프로젝트에서 사용하기 위해 자료구조를 공부하며 링크드리스트에 대해 공부한 내용을 간단히 적어보겠습니다. 링크드 리스트(Linked List)는 데이터 구조의 한 유형으로, 각 요소(노드)가 데이터와 다음 요소를 가리키는 포인터를 포함하는 방식으로 구성됩니다. 이는 배열과 달리 요소들이 물리적으로 연속되어 있지 않으며, 논리적으로 연결된 구조를 갖습니다. 링크드 리스트는 데이터의 동적 할당 및 삽입, 삭제가 빈번히 일어나는 상황에서 유용합니다. 1. 링크드 리스트의 구성 요소1.1. 노드(Node): 링크드 리스트의 기본 구성 요소. 각 노드는 다음과 같은 두 부분으로 이루어져 있습니다. - 데이터(Data): 노드가 저장하는 값 - 포인터(Next): 다음 노드를 가리키는 참조(주소)1.2..
-
자료 구조 : 해시 테이블TIL. 2024. 7. 17. 03:46
오늘은 자료구조 해시 테이블에 대해 공부한 내용을 요약합니다. 해시 테이블 Key & Value로 저장되는 자료구조입니다. 빠르게 데이터를 검색할 수 있으며 이는 해시 테이블 내부에 버킷으로 데이터를 저장하기 때문입니다. 해시 테이블은 각각의 Key 값에 해시 함수를 적용하여 index를 생성하고, 이 index에 해당하는 버킷에 값을 저장하거나 검색하는 데 사용하게 됩니다. 시간 복잡도 해시 테이블은 Key값으로 Value를 한 번에 불러올 수 있기 때문에 평균적으로 0(1)에 시간 복잡도를 가집니다. 해시 충돌 해시 함수가 index를 생성할 때 전부 Unique 한 값을 가지는 건 아닙니다. 글자 수를 환산해서 index를 반환하는 해시 함수가 있다면, Key 값의 글자 수가 같을 때 같은 in..
-
Trello - member 테이블을 통하는 인증, 인가 ( + 수정예정 )TIL. 2024. 7. 16. 05:06
오늘은이번 프로젝트에서는 Board에 관한 접근 권한을 인증하기 위해 Member라는 테이블을 추가로 구성했고유저 인증, 인가 외에 Member 인증, 인가를 구현하기로 했습니다. 프로젝트 ERD입니다.기본적으로 보드, 리스트, 카드와 관련된 API 호출 → 해당 유저가 멤버에 등록 되어있는지 조회 → true일 경우 API 호출을 진행합니다.이를 위한 인증과 인가를 구현하기 위해 몇 가지 방법을 생각했습니다.Guard를 통한 구현Interceptor + Guard를 통한 구현Middleware + Guard를 통한 구현Method를 통한 구현다른 방법들1. Guard를 통한 구현첫 번째로 Guard를 통한 구현을 계획했습니다.URL을 통해 매 호출마다 boardId를 전달받는다.JWT 인증에서 넘어온 ..
-