Upgrade to Pro — share decks privately, control downloads, hide ads and more …

40만명이 쓰는 Django channels 채팅서버, 우리는 어떻게 만들었나?

40만명이 쓰는 Django channels 채팅서버, 우리는 어떻게 만들었나?

2018 Pycon. @EJSohn

Dd72fe7cec4dcbe92677edd15e7bc337?s=128

Eunju Amy Sohn

August 17, 2018
Tweet

Transcript

  1. 40만명이 쓰는 Django channels 채팅서버, 우리는 어떻게 만들었나? Pycon Korea

    2018 Eunju Sohn (Amy)
  2. Name: 손은주 Nickname: Amy Who: Devops Engineer @Mathpresso Comment: I

    love The magical moment! github: http://github.com/EJSohn email: 5on.3un.7oo@gmail.com
  3. Contents 1. Why? 1. background explanation 2. introduce Django channels

    2. How? 1. server-client communication protocol 2. coding 3. testing 4. deployment & maintenance
  4. Why? Slack – Java Facebook Messenger – Erlang Line –

    Java, C++, Erlang Kakaotalk – C++ Snapchat – Java * 구글링 첫 페이지에 나온 정보들입니다. 신뢰도가 그리 높지 않습니다 ㅠ
  5. Why? – background explanation Mathpresso Dev Team

  6. Why? – background explanation Main language: Python + deeply use

    Django ORM + fast action and output required + but all thing has to be maintainable and scalable Had to make Reliable app Faster, with existing technical stack
  7. Why? – background explanation

  8. Why? – Django channels

  9. Why? – Django channels • ASGI • Asynchronous webserver •

    Consumer • Daphne • Channel layer
  10. Why? – Django channels ASGI? = Asynchronous Server Gateway Interface

    Spiritual successor of wsgi. Extend not only support HTTP-style request/response but also websocket and others.
  11. Why? – Django channels myapp/myapp/asgi.py

  12. Why? – Django channels

  13. Why? – Django channels Daphne HTTP request websocket request mysite.urls

    mysite.routing
  14. How? – server-client communication protocol

  15. How? – server-client communication protocol Requirement User – Bot 1:1

    chatting with multiple templates User – User 1:1 chatting User group chatting
  16. How? – server-client communication protocol Had to build communication protocol

    & • Communicating text, byte-data based pre-defined json. • Serializing& deserializing into object.
  17. How? – coding

  18. How? – coding Store chat data in NoSQL

  19. How? – coding async/await Remove all I/O bottleneck • Network

    I/O • Database I/O
  20. How? – coding aiohttp

  21. How? – coding database_sync_to_async

  22. Why? – testing pytest-asyncio HTTPCommunicator WebsocketCommuniator

  23. Why? – testing Chat-client https://github.com/websocket-client/websocket-client

  24. How? – deployment & maintenance machine daphne nginx Load balancer

    80 endpoint1:80 endpoint2:80
  25. Why? – conclusion 소수의 인원으로 빠르게 관리하기 편한 채팅 서버를

    만들 수 있었습니다. + 채팅 서버의 성능에 대해 관심 있으신 분들과 이야기를 나누고 싶습니다!