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
900
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
190
TauriとRustとSolidJSで作るEthereum Address生成機 / Ethereum Address Generator made by Tauri, Rust, SolidJS
serinuntius
0
270
世界最速でArbitrumで NFTを作って震えたい!!!!/ I want to make NFT with Arbitrum in the fastest way in the world and tremble !!!!
serinuntius
0
640
なぜフラッシュローンという概念が俺達の魂を震えさせるのか / Why does the concept of flash loans make our souls tremble?
serinuntius
0
980
Why does the concept of DeFi make our souls tremble? / なぜDeFiという概念が俺達の魂を震えさせるのか ~DEX(AMM)まで~
serinuntius
0
1.3k
NotionがCMS代わりに!? / Notion replaces CMS!?
serinuntius
0
960
ont hackathon
serinuntius
0
88
新卒Rubyistが1ヶ月で Perl Mongerになった話
serinuntius
0
540
Other Decks in Technology
See All in Technology
ドキュメントはAIの味方!スタートアップのアジャイルを加速するADR
kawauso
3
370
Devinを使ったモバイルアプリ開発 / Mobile app development with Devin
yanzm
0
190
Figma + Storybook + PlaywrightのMCPを使ったフロントエンド開発
yug1224
8
2.3k
AIエージェント就活入門 - MCPが履歴書になる未来
eltociear
0
510
Evolution on AI Agent and Beyond - AGI への道のりと、シンギュラリティの3つのシナリオ
masayamoriofficial
0
170
AIとTDDによるNext.js「隙間ツール」開発の実践
makotot
5
690
AIエージェントの開発に必須な「コンテキスト・エンジニアリング」とは何か──プロンプト・エンジニアリングとの違いを手がかりに考える
masayamoriofficial
0
390
Gaze-LLE: Gaze Target Estimation via Large-Scale Learned Encoders
kzykmyzw
0
320
自社製CMSからmicroCMSへのリプレースがプロダクトグロースを加速させた話
nextbeatdev
0
130
JOAI発表資料 @ 関東kaggler会
joai_committee
1
290
攻撃と防御で実践するプロダクトセキュリティ演習~導入パート~
recruitengineers
PRO
1
190
Understanding Go GC #coefl_go_jp
bengo4com
0
1.1k
Featured
See All Featured
A designer walks into a library…
pauljervisheath
207
24k
Writing Fast Ruby
sferik
628
62k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
231
53k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
50k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
34
6k
GitHub's CSS Performance
jonrohan
1031
460k
Into the Great Unknown - MozCon
thekraken
40
2k
Agile that works and the tools we love
rasmusluckow
329
21k
What’s in a name? Adding method to the madness
productmarketing
PRO
23
3.6k
Documentation Writing (for coders)
carmenintech
73
5k
Become a Pro
speakerdeck
PRO
29
5.5k
Unsuck your backbone
ammeep
671
58k
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༏উͯ͠মᇋͬͯ͘Ε