SlideShare a Scribd company logo
1 of 33
DSPでgolangの屍
を超えた話
1
片田 雄樹
先日リリースしたAmebaDSPの開発責任者としてエンジニア兼任で
分析とかやってます。
主な使用言語: Scala、Go言語
最近はまっていること: Tableauで個性的なダッシュボードを作る
2
Agenda
» Ameba DSPで起きた問題
» 対応策と結果
» チューニング方法
» まとめ
3
※ 今回の話は、golangをある程度触
ったことがある人が主な対象となり
ます。
4
1.
Ameba DSPで起きた問題たち
Problems happened in Ameba DSP
5
golangを使った理由
ちょっと触った感じ簡単だし、流行ってるか
らいい感じなんじゃね!?(*´∀`*)
6
最強の壁: 速度問題
DSPなので、リクエストからレスポンスまで
100ms以内に返さなきゃいけない。
なかなか思ったような速度出ない…(涙)
7
イライラ: structが勝手にデフォ
ルト値にしやがる問題
ログで「0」値を吐きたいのにnullにする
また、structに詰めるときに勝手に「0」が入る
。
そもそも値が返ってきてるのかわからん!
8
イライラ2: コード荒れる問題
他の言語で書くよりgolangで書くとやたらコー
ド荒れる。
キレイになったかと思えばコード量半端ない…
9
2.
解決策
Solutions the problem
10
最強の壁: 速度問題
今回はこの問題にフォーカスします。
(100ms以内にレスポンスしなきゃいけない問題)
11
そもそもの原因として、I/Oのレイテンシーをなめてた。
最初は、1000QPSで130msぐらいかかってました…
12
解決策その1
13
最強の壁: 速度問題(解決策その1)
14
goroutineを内部で使用していたライブラリ例
» net/http (https://github.com/golang/go/tree/master/src/net/http)
» ruslog (社内ライブラリ)
最強の壁: 速度問題(解決策その1)
15
それぞれgoroutineの実装部分でかなりのオーバ
ーヘッドが発生していました…
最強の壁: 速度問題(解決策その1)
16
ライブラリ変更後
» net/http
→ fasthttp (https://github.com/valyala/fasthttp)
» ruslog (社内Loggerライブラリ)
→ zap logger (https://github.com/uber-go/zap)
ライブラリ変更することで、30msぐらいは速く
なった!
最強の壁: 速度問題(解決策その1)
17
最強の壁: 速度問題(解決策その1)
教訓その1
ライブラリの実装を見れば割と簡単に問題に気
づくので、使用するライブラリはちゃんと内部
実装を確認しましょう。
18
解決策その2
19
最強の壁: 速度問題(解決策その2)
ココ
20
二つのサーバに並列(goroutine)でリク
エストしてました。
最強の壁: 速度問題(解決策その2)
21
最強の壁: 速度問題(解決策その2)
こんな感じで、Wait Group 使ってアクセスし
てました。(サンプルコード)
22
プロファイルとってみると、goroutineを生成し
すぎてたせいかレイテンシーの原因になってる
ことが判明。
シーケンシャルな処理(goroutine/wgをなくした
)にしたら20msくらい改善!
最強の壁: 速度問題(解決策その2)
23
最強の壁: 速度問題(解決策その2)
教訓その2
goroutineを使うにもいくらかコストがかかるの
で、意識して実装しましょう。
24
3.
チューニング方法
Performance tuning
25
パフォーマンスチューニングの要はプ
ロファイルを取ることだった。
Golangの「pprof」は超優秀です。
https://golang.org/pkg/net/http/pprof/
26
今回使ったのはこちら、
echo-contrib/echopprof
(github.com)
https://github.com/echo-contrib/echopprof
27
> go tool pprof ./main
http://localhost:xxx/debug/pprof/block
(pprof)
このようにビルド後のバイナリ(./main)とエンドポイント(http://localhost:xxx/debug/pprof/block)を
指定することで (pprof) が立ち上がります。
28
例えば、「list 関数名」コマンドで関数呼び出しにかかった時間を調べることができます。
29
DEMO
30
4.
まとめ
Conclusion
31
屍を超えて学んだこと
» ライブラリの内部実装はしっかり確認しましょう
(golangは比較的読みやすいので)
» 決してgoroutineが悪いわけではなく、軽量で簡単に実装で
きるからといって使い方を誤るとボトルネックになります
» めんどくさがらず、プロファイリングしてボトルネックを見
つけていきましょう
32
ご清聴ありがとうございました。
33

More Related Content

Featured

PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at WorkGetSmarter
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...DevGAMM Conference
 

Featured (20)

Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
 

DSPでgolangの屍を超えた話