SlideShare a Scribd company logo
1 of 31
Real World Erlang
    VOYAGE GROUP
       @ajiyoshi
Advertisement System




          HERE!
RTB


• Real Time Bidding
• real time auction for each ad impression to
  decide price
Ad Request


              Ad Server
Browser     for Publisher
               (SSP)
Bid Request


              Ad Server
Browser     for Publisher
               (SSP)        Ad Server
                               for
                            Advertiser
                             (DSP)
Bid

                          10


            Ad Server     20
Browser   for Publisher
             (SSP)                  Ad Server
                           30          for
                                    Advertiser
                                     (DSP)
                               15
Auction

                                  10


                    Ad Server     20
     Browser      for Publisher
                     (SSP)                  Ad Server
                                   30          for
                                            Advertiser
                                             (DSP)
                                       15



       ※usually “second price auction”
2nd highest bid price will be the contract price
Display winner Ad

                          10


            Ad Server     20
Browser   for Publisher
             (SSP)                  Ad Server
                           30          for
                                    Advertiser
                                     (DSP)
                               15
Problem


• How will you design the system?
Requirements

• stable
• fast! fast! fast!
 • < 50ms (if possible)
 • don’t block in network IO
 • timeout (IMPORTANT!)
Non blocking IO
• multi process, multi thread
• IO multiplexing
 • select epoll libeio etc.
• IO multiplexing + event driven
 • libev etc.
TIMEOUT
Network timeout (curl)

• CURLOPT_CONNECTTIMEOUT
• CURLOPT_CONNECTTIMEOUT_MS
• CURLOPT_TIMEOUT
• CURLOPT_TIMEOUT_MS
Network timeout (curl)
•   CURLOPT_TIMEOUT_MS
    •   “cURL 関数の実行にかけられる最大のミ
        リ秒数。 システムの標準の名前解決を
        使うように libcurl をビルドしている場合
        は、 接続のタイムアウトは秒単位の精
        度となり、最小のタイムアウトは 1 秒と
        なります。
Timeout
•   timeout for each connection
    • C socket API has “connect()” and “recv()”
        •
        need to manage each timeout
    • what we need is “round trip” timeout
•   timeout for total auction process
    • hard to implement in some languages like C
        •
        watch dog thread for each processes?
        •
        multi processes + signal?
My options

• write in C with libev, libeio and so on
• use node.js (it uses libev libeio)
• light weight process(like Erlang)
Write in C


• pros
 • Fast!
Write in C
• cons
 • self memory management in
   the HELL
 • multi thread in C in the HELL
 • timeout in the HELL
use node.js

• pros
 • abstracted event loop and IO
    multiplexing
 • auto memory management
use node.js
• cons
 • callback HELL
 • single threaded
 • timeout for whole process in the HELL
 • NOT stable
   • many upgrades
Erlang

• pros
 • with lightweight process
 • stable
 • easy to write networking system
 • fitting perfectly for the requirements
Erlang


• cons
 • few Erlang programmers
Erlang
Erlang performance
http://dsas.blog.klab.org/archives/51993306.html




            proc#/sec of TCP echo
Observations
“しかし、CPU負荷をモニタリングしていると、thread版はほんの少し速いだ
けなのにCPUを200% 使いきっており、CPU負荷のうちでも sys が多い状況
になっていました。これは、ネイティブスレッドの コンテキストスイッチ
の負荷だと思います。

なので、最速TCPサーバーの条件とは、基本的にネイティブスレッドではな
く軽量なユーザーランド スレッドかイベント駆動方式で接続の多重化を行
いつつ、なおかつ複数コアを利用するために コア数程度のネイティブス
レッドかプロセスを利用するという物になると思います。”
Let’s go!

• implement RTB daemon in Erlang
 • other system is not Erlang
 • receive request from other system,
    return auction result
• 120msec timeout in each process
Performance

• about 3 Billion bids/month
• about 110 Million bids/day
• about 5000 bids/sec (peak time)
Timeout




total ad deliver time msec→ # (logarithmic)
stable

• no memory leak
• no bottle neck
• no crash (including VM)
Requirements(again)
• stable→OK
• fast! fast! fast!→OK
 • no network blocking →OK
    • by lightweight process
 • timeout(IMPORTANT!)→OK
    • by lightweight process
Real world Erlang

• Erlang is awsome
• very fit to handling many many little
  network IOs
• stable
• easy to write

More Related Content

Similar to Real world erlang

関東GPGPU勉強会 LLVM meets GPU
関東GPGPU勉強会 LLVM meets GPU関東GPGPU勉強会 LLVM meets GPU
関東GPGPU勉強会 LLVM meets GPU
Takuro Iizuka
 
VRライブ・コミュニケーションサービス「バーチャルキャスト」でのモノビットエンジンの採用事例と最新情報
VRライブ・コミュニケーションサービス「バーチャルキャスト」でのモノビットエンジンの採用事例と最新情報VRライブ・コミュニケーションサービス「バーチャルキャスト」でのモノビットエンジンの採用事例と最新情報
VRライブ・コミュニケーションサービス「バーチャルキャスト」でのモノビットエンジンの採用事例と最新情報
モノビット エンジン
 
Adstir説明資料ver3.2(2012年9月5日)
Adstir説明資料ver3.2(2012年9月5日)Adstir説明資料ver3.2(2012年9月5日)
Adstir説明資料ver3.2(2012年9月5日)
AdStir
 
1011motionBEAT主催セミナー_1
1011motionBEAT主催セミナー_11011motionBEAT主催セミナー_1
1011motionBEAT主催セミナー_1
motionBEAT
 
1011_motionBEAT SSPセミナー1
1011_motionBEAT SSPセミナー11011_motionBEAT SSPセミナー1
1011_motionBEAT SSPセミナー1
motionBEAT
 
CommunityOpenDay2012名古屋セッション資料
CommunityOpenDay2012名古屋セッション資料CommunityOpenDay2012名古屋セッション資料
CommunityOpenDay2012名古屋セッション資料
Shinichiro Isago
 
drecomにおけるwinning the metrics battle
drecomにおけるwinning the metrics battledrecomにおけるwinning the metrics battle
drecomにおけるwinning the metrics battle
Mitsuki Kenichi
 

Similar to Real world erlang (20)

Ad tech 勉強会 20140115
Ad tech 勉強会 20140115Ad tech 勉強会 20140115
Ad tech 勉強会 20140115
 
関東GPGPU勉強会 LLVM meets GPU
関東GPGPU勉強会 LLVM meets GPU関東GPGPU勉強会 LLVM meets GPU
関東GPGPU勉強会 LLVM meets GPU
 
VRライブ・コミュニケーションサービス「バーチャルキャスト」でのモノビットエンジンの採用事例と最新情報
VRライブ・コミュニケーションサービス「バーチャルキャスト」でのモノビットエンジンの採用事例と最新情報VRライブ・コミュニケーションサービス「バーチャルキャスト」でのモノビットエンジンの採用事例と最新情報
VRライブ・コミュニケーションサービス「バーチャルキャスト」でのモノビットエンジンの採用事例と最新情報
 
Riakmeetup2forupload
Riakmeetup2foruploadRiakmeetup2forupload
Riakmeetup2forupload
 
Vrodeo agenda 200930
Vrodeo agenda 200930Vrodeo agenda 200930
Vrodeo agenda 200930
 
Armored core vのオンラインサービスにおけるクラウドサーバー活用事例
Armored core vのオンラインサービスにおけるクラウドサーバー活用事例Armored core vのオンラインサービスにおけるクラウドサーバー活用事例
Armored core vのオンラインサービスにおけるクラウドサーバー活用事例
 
Cocos2d-x 3.0を使ったゲーム “消滅都市” の開発事例
Cocos2d-x 3.0を使ったゲーム “消滅都市” の開発事例Cocos2d-x 3.0を使ったゲーム “消滅都市” の開発事例
Cocos2d-x 3.0を使ったゲーム “消滅都市” の開発事例
 
Fluentd meetup #2
Fluentd meetup #2Fluentd meetup #2
Fluentd meetup #2
 
Rtbマネタイズセミナー@(20120324、abc2012)資料
Rtbマネタイズセミナー@(20120324、abc2012)資料Rtbマネタイズセミナー@(20120324、abc2012)資料
Rtbマネタイズセミナー@(20120324、abc2012)資料
 
vRodeo rancher 200702
vRodeo rancher 200702vRodeo rancher 200702
vRodeo rancher 200702
 
Production Services with Gentoo Linux on SAKURA Cloud
Production Services with Gentoo Linux on SAKURA CloudProduction Services with Gentoo Linux on SAKURA Cloud
Production Services with Gentoo Linux on SAKURA Cloud
 
Rtb30min
Rtb30minRtb30min
Rtb30min
 
VRライブ・コミュニケーションサービス「バーチャルキャスト」でのモノビットエンジンの採用事例と最新情報 - モノビットエンジン - GTMF 2018 O...
VRライブ・コミュニケーションサービス「バーチャルキャスト」でのモノビットエンジンの採用事例と最新情報 - モノビットエンジン - GTMF 2018 O...VRライブ・コミュニケーションサービス「バーチャルキャスト」でのモノビットエンジンの採用事例と最新情報 - モノビットエンジン - GTMF 2018 O...
VRライブ・コミュニケーションサービス「バーチャルキャスト」でのモノビットエンジンの採用事例と最新情報 - モノビットエンジン - GTMF 2018 O...
 
Adstir説明資料ver3.2(2012年9月5日)
Adstir説明資料ver3.2(2012年9月5日)Adstir説明資料ver3.2(2012年9月5日)
Adstir説明資料ver3.2(2012年9月5日)
 
1011motionBEAT主催セミナー_1
1011motionBEAT主催セミナー_11011motionBEAT主催セミナー_1
1011motionBEAT主催セミナー_1
 
1011_motionBEAT SSPセミナー1
1011_motionBEAT SSPセミナー11011_motionBEAT SSPセミナー1
1011_motionBEAT SSPセミナー1
 
CommunityOpenDay2012名古屋セッション資料
CommunityOpenDay2012名古屋セッション資料CommunityOpenDay2012名古屋セッション資料
CommunityOpenDay2012名古屋セッション資料
 
Windows Azure Community Open Day 2012
Windows Azure   Community Open Day 2012Windows Azure   Community Open Day 2012
Windows Azure Community Open Day 2012
 
500+のサーバーで動く LINE Ads PlatformをささえるSpring
500+のサーバーで動く LINE Ads PlatformをささえるSpring500+のサーバーで動く LINE Ads PlatformをささえるSpring
500+のサーバーで動く LINE Ads PlatformをささえるSpring
 
drecomにおけるwinning the metrics battle
drecomにおけるwinning the metrics battledrecomにおけるwinning the metrics battle
drecomにおけるwinning the metrics battle
 

Real world erlang

  • 1. Real World Erlang VOYAGE GROUP @ajiyoshi
  • 3. RTB • Real Time Bidding • real time auction for each ad impression to decide price
  • 4. Ad Request Ad Server Browser for Publisher (SSP)
  • 5. Bid Request Ad Server Browser for Publisher (SSP) Ad Server for Advertiser (DSP)
  • 6. Bid 10 Ad Server 20 Browser for Publisher (SSP) Ad Server 30 for Advertiser (DSP) 15
  • 7. Auction 10 Ad Server 20 Browser for Publisher (SSP) Ad Server 30 for Advertiser (DSP) 15 ※usually “second price auction” 2nd highest bid price will be the contract price
  • 8. Display winner Ad 10 Ad Server 20 Browser for Publisher (SSP) Ad Server 30 for Advertiser (DSP) 15
  • 9. Problem • How will you design the system?
  • 10. Requirements • stable • fast! fast! fast! • < 50ms (if possible) • don’t block in network IO • timeout (IMPORTANT!)
  • 11. Non blocking IO • multi process, multi thread • IO multiplexing • select epoll libeio etc. • IO multiplexing + event driven • libev etc.
  • 13. Network timeout (curl) • CURLOPT_CONNECTTIMEOUT • CURLOPT_CONNECTTIMEOUT_MS • CURLOPT_TIMEOUT • CURLOPT_TIMEOUT_MS
  • 14. Network timeout (curl) • CURLOPT_TIMEOUT_MS • “cURL 関数の実行にかけられる最大のミ リ秒数。 システムの標準の名前解決を 使うように libcurl をビルドしている場合 は、 接続のタイムアウトは秒単位の精 度となり、最小のタイムアウトは 1 秒と なります。
  • 15. Timeout • timeout for each connection • C socket API has “connect()” and “recv()” • need to manage each timeout • what we need is “round trip” timeout • timeout for total auction process • hard to implement in some languages like C • watch dog thread for each processes? • multi processes + signal?
  • 16. My options • write in C with libev, libeio and so on • use node.js (it uses libev libeio) • light weight process(like Erlang)
  • 17. Write in C • pros • Fast!
  • 18. Write in C • cons • self memory management in the HELL • multi thread in C in the HELL • timeout in the HELL
  • 19. use node.js • pros • abstracted event loop and IO multiplexing • auto memory management
  • 20. use node.js • cons • callback HELL • single threaded • timeout for whole process in the HELL • NOT stable • many upgrades
  • 21. Erlang • pros • with lightweight process • stable • easy to write networking system • fitting perfectly for the requirements
  • 22. Erlang • cons • few Erlang programmers
  • 25. Observations “しかし、CPU負荷をモニタリングしていると、thread版はほんの少し速いだ けなのにCPUを200% 使いきっており、CPU負荷のうちでも sys が多い状況 になっていました。これは、ネイティブスレッドの コンテキストスイッチ の負荷だと思います。 なので、最速TCPサーバーの条件とは、基本的にネイティブスレッドではな く軽量なユーザーランド スレッドかイベント駆動方式で接続の多重化を行 いつつ、なおかつ複数コアを利用するために コア数程度のネイティブス レッドかプロセスを利用するという物になると思います。”
  • 26. Let’s go! • implement RTB daemon in Erlang • other system is not Erlang • receive request from other system, return auction result • 120msec timeout in each process
  • 27. Performance • about 3 Billion bids/month • about 110 Million bids/day • about 5000 bids/sec (peak time)
  • 28. Timeout total ad deliver time msec→ # (logarithmic)
  • 29. stable • no memory leak • no bottle neck • no crash (including VM)
  • 30. Requirements(again) • stable→OK • fast! fast! fast!→OK • no network blocking →OK • by lightweight process • timeout(IMPORTANT!)→OK • by lightweight process
  • 31. Real world Erlang • Erlang is awsome • very fit to handling many many little network IOs • stable • easy to write

Editor's Notes

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n
  29. \n
  30. \n
  31. \n