TCP 서버 동시요청 처리(스레드 풀) #7
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
TCP 서버 동시요청 처리
서버는 다수의 클라이언트와 통신한다
동시에 요청을 받아서 개별 클라이언트에 결과를 보내잖아
근데 만약 한 클라이언트의 요청을 처리 후 다음 클라이언트의 요청을 처리하는 방식이면,
처리 시간이 길어지면 다음 요청의 대기시간이 너무 늘어난다는 게 문제인거지.
그래서 동시에 처리하는 방법
⇒ 각 요청 처리 코드를 별도의 스레드에서 작업하는 방법
데이터 받기와 데이터 보내기 이 부분을 별도의 스레드에서 작업하는 게 좋음
❗주의사항: 과도한 스레드 생성을 방지해야함.
스레드 풀 사용
스레드 수를 제한해서 사용하니까, 클라이언트 폭증이 일어나도 문제가 크게 없음. 대신 응답이 좀 느릴 수는 있지
❗왜 응답이 느려? 작업 큐의 대기 작업이 증가되니까.