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

5주차 과제 #6

Open
dididy opened this issue Oct 8, 2020 · 1 comment
Open

5주차 과제 #6

dididy opened this issue Oct 8, 2020 · 1 comment

Comments

@dididy
Copy link
Contributor

dididy commented Oct 8, 2020

다중 클라이언트 연결 웹 서버와 성능 테스트(Select Multiplexing): 201704147 이용재

다중 클라이언트 웹 서버 구현과 성능 테스트 (10점)

Select를 이용한 Multiplexing (4점)

import socket
import select
import os
import sys

def main(port):
    serversocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    serversocket.bind(('', port))
    print("listening...")
    serversocket.listen()
    input_list = [serversocket] # select를 통해 관찰할 리스트

    while input_list:
      input_ready, write_ready, except_ready = select.select(input_list, [], [])

      for each in input_ready: # 관찰중인 input 리스트에 대한 부분
        if each == serversocket:
            (clientsocket, address) = serversocket.accept()
            input_list.append(clientsocket)
        else:
            data = each.recv(1024).decode('utf-8') # 기존에 send_recv로 처리되어 있는 부분을 이렇게 변경해야 함
            if data: # data가 존재하는 경우 실행
                header = "HTTP/1.1 200 0K\r\n"
                body = """
                    <!DOCTYPE html>
                    <html>
                    </html>
                    """ # body가 없으면 locust 측에서 error 발생
                each.send((header + body).encode('utf-8'))
                input_list.remove(each)
                each.close()

            else: # data가 없는 경우 실행
                input_list.remove(each)
                each.close()

if __name__ == "__main__":
    port = 8881
    main(port)

Locust를 이용한 서버 성능 테스트 결과 비교 작성 (6점)

Single Process

single--chat

Single Process의 경우 RPS가 121.1이며, 10,000번의 요청을 했을 시 20%의 failure가 발생한다. 그리고 평균 응답시간은 28,878ms 이다.

Multi Process

Screen Shot 2020-10-08 at 10 39 06 PM

Multi Process의 경우 RPS가 46.2이며, 10,000의 요청을 했을 시 6%의 failure가 발생한다. 그리고 평균 응답시간은 237,402ms 이다.

Multi Thread

thread-chart

Multi Thread의 경우 RPS가 99.3이며, 10,000번의 요청을 했을 시 13%의 failure가 발생한다. 그리고 평균 응답시간은 28,507ms 이다.

Select

Screen Shot 2020-10-08 at 11 01 08 PM

Select의 경우 RPS가 213.4이며, 10,000번의 요청을 했을 시 11%의 failure가 발생한다. 그리고 평균 응답시간은 26,193ms 이다.

single process vs multi process vs multi thread vs select

Hatch Rate 100, 10000 Requests single process multi process multi thread select
Request 63,471 86,156 64,828 57,391
Request Per Second 121.2 46.2 99.3 213.4
Average Response time 28,878 237,402 28,507 26,193
failure 20% 4% 13% 1%

결과를 바탕으로 성능별로 나열해보자면 셀렉트, 싱글프로세스, 멀티스레드, 멀티프로세스 순이다. 가장 성능이 좋은 방식은 셀렉트이다.

@dididy
Copy link
Contributor Author

dididy commented Oct 8, 2020

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

No branches or pull requests

1 participant