Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Golangでリクエストごとのクエリログが見たい!! kamakura.go #4 /...
Search
serinuntius
May 25, 2018
Technology
1
840
Golangでリクエストごとのクエリログが見たい!! kamakura.go #4 / go-query-and-request-logger
kamakura.go #4 LT枠
https://serinuntius.hatenablog.jp/entry/2018/05/01/083000
serinuntius
May 25, 2018
Tweet
Share
More Decks by serinuntius
See All by serinuntius
NFTのインデクシングとGraphQLのすゝめ / NFT indexing and GraphQL
serinuntius
0
140
TauriとRustとSolidJSで作るEthereum Address生成機 / Ethereum Address Generator made by Tauri, Rust, SolidJS
serinuntius
0
220
世界最速でArbitrumで NFTを作って震えたい!!!!/ I want to make NFT with Arbitrum in the fastest way in the world and tremble !!!!
serinuntius
0
610
なぜフラッシュローンという概念が俺達の魂を震えさせるのか / Why does the concept of flash loans make our souls tremble?
serinuntius
0
920
Why does the concept of DeFi make our souls tremble? / なぜDeFiという概念が俺達の魂を震えさせるのか ~DEX(AMM)まで~
serinuntius
0
1.3k
NotionがCMS代わりに!? / Notion replaces CMS!?
serinuntius
0
880
ont hackathon
serinuntius
0
66
新卒Rubyistが1ヶ月で Perl Mongerになった話
serinuntius
0
470
Other Decks in Technology
See All in Technology
10XにおけるData Contractの導入について: Data Contract事例共有会
10xinc
5
590
Lexical Analysis
shigashiyama
1
150
Amazon CloudWatch Network Monitor のススメ
yuki_ink
1
200
Why App Signing Matters for Your Android Apps - Android Bangkok Conference 2024
akexorcist
0
120
20241120_JAWS_東京_ランチタイムLT#17_AWS認定全冠の先へ
tsumita
2
240
rootlessコンテナのすゝめ - 研究室サーバーでもできる安全なコンテナ管理
kitsuya0828
3
380
ハイパーパラメータチューニングって何をしているの
toridori_dev
0
140
Python(PYNQ)がテーマのAMD主催のFPGAコンテストに参加してきた
iotengineer22
0
470
第1回 国土交通省 データコンペ参加者向け勉強会③- Snowflake x estie編 -
estie
0
120
信頼性に挑む中で拡張できる・得られる1人のスキルセットとは?
ken5scal
2
530
RubyのWebアプリケーションを50倍速くする方法 / How to Make a Ruby Web Application 50 Times Faster
hogelog
3
940
オープンソースAIとは何か? --「オープンソースAIの定義 v1.0」詳細解説
shujisado
5
630
Featured
See All Featured
Visualization
eitanlees
145
15k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
26
2.1k
Faster Mobile Websites
deanohume
305
30k
Embracing the Ebb and Flow
colly
84
4.5k
Making Projects Easy
brettharned
115
5.9k
StorybookのUI Testing Handbookを読んだ
zakiyama
27
5.3k
The World Runs on Bad Software
bkeepers
PRO
65
11k
The Pragmatic Product Professional
lauravandoore
31
6.3k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
47
2.1k
Code Reviewing Like a Champion
maltzj
520
39k
Fontdeck: Realign not Redesign
paulrobertlloyd
82
5.2k
Bash Introduction
62gerente
608
210k
Transcript
GolangͰϦΫΤετ͝ͱͷ ΫΤϦϩά͕Έ͍ͨʂʂ 2018-05-25 kamakura.go #4 LT ໘ന๏ਓΧϠοΫ ۔Ѯ @_serinuntius
ҙ ⚠ܕগͳΊͰ͢⚠
Ξϯέʔτ
ISUCON ͬͯΒͬ͠ΌΔํʙ
ISUCON ग़ͨ͜ͱ͋ΔΑͬͯํʙ
ISUCONͱʁ
͓ͱͳΔWebαʔϏεΛ ܾΊΒΕͨϨΪϡϨʔγϣϯͷதͰ ݶք·ͰߴԽΛਤΔ νϡʔχϯάότϧɺ ͦΕ͕ISUCONͰ͢ɻ ISUCONެࣜBlogͷdescriptionΑΓ
ͪͳΈʹ ࣾISUCON͔͠ ग़ͨ͜ͱ͋Γ·ͤΜ
ࣾISUCONͰݟ͑ͨ՝ • ΫΤϦͷൃߦճΛߟྀ͠ͳ͚Ε͍͚ͳ͍ (ൃߦճ͕গͳ͍ɺ͍͚ͩͷΫΤϦ͋Δ) w w • Ͳ͜ͰΫΤϦ͕ൃߦ͞Ε͍ͯΔ͔Γ͍ͨ • ͬͱݴ͑ͲͷϦΫΤετͰ
ͲΕ͚ͩݺΕͯΔ͔Γ͍ͨ • GoͰग़͍ͨ(ܕ͕͋ͬͨํ͕ΞϓϦͷϦϑΝΫλ͕͠қ͍)
ࣾISUCONͰͷ লΛ׆͔ͨ͢Ίʹ
ΞΫηεϩΨʔ ͱ ΫΤϦϩΨʔΛ࡞ͬͨ
github.com/serinuntius/graqt ര
͍ํ εςοϓ1~import~ • 2ͭͷύοέʔδΛimport͢Δ
͍ํ εςοϓ2 ~driverΛڥมͰΓସ͑Δ~ • driverΓସ͑ͱtraceΛΦϯΦϑ͢Δ
͍ํ εςοϓ3 ~middlewareՃ~ • aliceΛ͏
͍ํ εςοϓ4 ~SQLݺͼग़͠ݩͷcontextରԠ~ • http.Request͔ΒcontextऔΓग़ͯ͠ɺ ݺͼग़͢ͱ͖ʹ͢
ٕज़తͳ͜ͱ
ϦΫΤετʹUUIDΛຒΊࠐΉ • middleware.go UUID=>ϦΫΤετͱΫΤϦΛඥ͚ΔͨΊ
ϦΫΤετʹUUIDΛຒΊࠐΉ • middleware.go UUID=>ϦΫΤετͱΫΤϦΛඥ͚ΔͨΊ ίϯςΩετʹೖΕΔཧ༝ =>ޙͰΫΤϦͱUUIDΛඥ͚ΔͨΊ
ϋΠύϑΥʔϚϯεͳ ߏԽϩΨʔ • uber-go/zap • RLogger͕request༻ͷzapͷLogger ࠓճͷਃ͠༁ఔͷܕཁૉ
ϋΠύϑΥʔϚϯεͳ ߏԽϩΨʔ {"level":"info", "ts":1525082389.1337767, "caller":"graqt/middleware.go:25", "msg":"", "time":0.011566198, "request_id":"5914e629-6746-42c5- z342-702f224f48e1", "path":"/user",
"method":"POST" } • ܕΛࢦఆͯ͠Δ͔Β͍
ΫΤϦΛτϨʔε͢Δ • shogo82148/go-sql-proxy • database/sqlͲΜͳDBʹରԠͰ͖ΔΑ͏ʹͳͬͯ ͍Δ • database/sql/driverʹ͋ΔinterfaceΛຬͨͯ͠ΕOK • ϓϩΩγ࡞ͬͯͦͷ··ͤϩάΛు͚ΔͷͰʁ
• ͱ͍͏ൃͰ࡞ΒΕͨΒ͍͠Ͱ͢*1 *1GoݴޠͰSQLͷτϨʔεΛ͢Δ https://shogo82148.github.io/blog/2015/05/13/golang-sql-proxy/
φΠεͳinterfaceͩʂʂ (͑) ࠓճͷืूཁ߲ˠ
ΫΤϦΛτϨʔε͢Δ • go-sql-proxyʹඪ४ͰΫΤϦϩΨʔ͕͋Δ • ࠓճUUIDΛϩάʹు͖͍ͨؔͰ ࣗલͰఆٛ
ΫΤϦτϨʔαʔͷ࣮ • tracer.go
ΫΤϦτϨʔαʔͷ࣮ • preܥͰݱࡏ࣌ࠁΛฦ͢ • cͷcontextʹrequestͷuuid͕ೖ͍ͬͯΔ • ctxʹpreܥͷݱࡏ࣌ࠁ͕ೖ͍ͬͯΔ
࣮ࡍʹు͔ΕΔϩά • request.log {"level":"info","ts":1525082389.1337767,"caller":"graqt/middleware.go: 25","msg":"","time":0.011566198,"request_id":"5914e629-6746-42c5- b342-702f224f48e1","path":"/user","method":"POST"} • query.log {"level":"info","ts":1525082389.1336403,"caller":"graqt/tracer.go: 20","msg":"Exec","query":"INSERT
INTO `user` (email,age) VALUES (?, ?)","args":[{"Name":"","Ordinal": 1,"Value":"
[email protected]
"}, {"Name":"","Ordinal":2,"Value":57}],"time": 0.001157627,"request_id":"5914e629-6746-42c5-b342-702f224f48e1"}
͑ɺϩάు͚ͩ͘ʁ • ͪΐͬͱͬͯͯ • alpΈ͍ͨͳϩάΛूܭ͢ΔCLIΛ࡞த • ϦΫΤετ͝ͱʹΫΤϦݟΕΔΑ͏ʹ͠·͢ • tigΛΊͬͪΌγϯϓϧʹͨ͠ૢ࡞ײͷΠϝʔδ
ϩʔυϚοϓ ϩά͕ग़ΔΑ͏ʹͳͬͨ Kamakura.goͰLT (ΠϚίί)
ϩʔυϚοϓ ϩά͕ग़ΔΑ͏ʹͳͬͨ Kamakura.goͰLT (ΠϚίί) viewerͷ࡞
ϩʔυϚοϓ ϩά͕ग़ΔΑ͏ʹͳͬͨ Kamakura.goͰLT (ΠϚίί) viewerͷ࡞ ISUCON༧બ௨աͯ͠ ϒϩάͰհ͢Δ
ϩʔυϚοϓ ϩά͕ग़ΔΑ͏ʹͳͬͨ Kamakura.goͰLT (ΠϚίί) viewerͷ࡞ ISUCON༧બ௨աͯ͠ ϒϩάͰհ͢Δ (୭͔͕graqtͬͯ) ISUCON༏উ͢Δ
ϩʔυϚοϓ ϩά͕ग़ΔΑ͏ʹͳͬͨ Kamakura.goͰLT (ΠϚίί) viewerͷ࡞ ISUCON༧બ௨աͯ͠ ϒϩάͰհ͢Δ (୭͔͕graqtͬͯ) ISUCON༏উ͢Δ
100ສͰʹ মᇋͬͯ͘ΕΔ
·ͱΊ • serinuntius/graqtΛ͑ɺ ISUCONʹศརͦ͏ͳϩά͕ు͚Δ • ISUCONҎ֎ʹͪΖΜ͑Δ • OSSͳͷͰποίϛͱ͔ؾܰʹͲ͏ͧ • ISUCON༏উͯ͠মᇋͬͯ͘Ε