High-performance Networking with Python

  • 성능 측정과 개선
  • 2016-08-13 (토요일) 16:40 - 17:20
  • 영어
  • 103
  • 촬영, 녹화가 가능합니다.

슬라이드

https://speakerdeck.com/achimnol/pycon-apac-2016-high-performance-networking-with-python

발표 동영상

https://youtu.be/RUj_N7yMS_s

PDF

https://github.com/pythonkr/pyconapac-2016-files/raw/master/20160813-103-23-KimJoongi.pdf

설명

네트워크 속도가 빨라지고 대규모 사용자를 가진 웹서비스들이 등장하면서 많은 수의 소켓 연결을 효율적으로 처리해야 할 필요가 점점 늘고 있습니다.

하나의 소켓 연결이 들어올 때마다 프로세스나 쓰레드를 새로 만드는 방식은 동시접속자 수가 수천~수만 단위가 넘어가면 문맥전환 오버헤드로 인해 고성능을 내기 어렵습니다.

이에 따라 Linux의 epoll, Windows의 IOCP, BSD의 kqueue와 같이 다수의 소켓 또는 I/O 오브젝트에 대해 수신 이벤트를 기다리는 운영체제 메커니즘들이 등장하였지만, 이벤트 기반 프로그래밍은 각 소켓별 문맥을 프로그래머가 일일이 추적해야 하기 때문에 프로그래머 입장에서는 코딩하기 어렵고 불편합니다.

이러한 문제를 해결하기 위해, Python을 비롯한 최신 프로그래밍 언어들은 코루틴 개념을 도입하여 소켓에 대한 blocking I/O가 발생하는 시점에 이벤트 루프 스케줄러가 자동으로 다른 대기 중인 코루틴을 진행시킴으로써 다수의 소켓 연결을 단일 쓰레드에서 적은 문맥전환 오버헤드로 다룰 수 있게 하고 있습니다.


이 발표에서는 Python 3.4에서 표준라이브러리에 추가된 asyncio 모듈과 Python 3.5에서 도입된 async 함수 선언자 문법 및 await 코루틴 호출 문법을 함께 살펴보고, Python이 비동기 이벤트 기반 프로그래밍을 어떻게 쉽게 할 수 있도록 도와주는지 살펴봅니다.

또한 asyncio 모듈을 이용해 실제 웹서버를 어떻게 구현할 수 있는지, 어느 정도 성능이 구현 가능한지 살펴봅니다.

asyncio와 독립적으로 개발된 Windows Python용 비동기 I/O 프레임워크인 PyParallel도 함께 소개해드립니다.


As the network speed and the number of users for global-scale web services increase, it is crucial to handle a large number of socket connection efficiently to achieve high performance.

Conventional methods such as spawning new processes or threads for new socket connections are no longer scalable for thousands of client connections due to high context switching overheads since the number of CPU cores is far less than the number of connections.

There are several OS-level solutions such as epoll of Linux, IOCP of Windows, and kqueue of BSD to multiplex many I/O objects such as sockets, but still it is difficult to exploit them because programmers need to keep track of contexts for individual connections.

To remedy this problem, modern programming languages such as Python has introduced coroutine-based event loop schedulers that automatically switches to other pending coroutines when a coroutine has a blocking I/O operation to wait for.

This eliminates the context management overheads for programmers since coroutines are just "stoppable" functions and the function scope becomes the context.


In this talk, I introduce the asyncio module added in Python 3.4 and async/await syntaxes added in Python 3.5, and show how Python eases asynchronous event-driven programming for network I/O.

We will see how to build a small web server using them and how much performance we can get.

Additionally, I also describe an alternative approach for Windows Python, PyParallel, which is independently developed against asyncio.


댓글

blog comments powered by Disqus

후원사 목록

키스톤

다이아몬드

플래티넘

골드

스타트업

실버

미디어