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
150
TauriとRustとSolidJSで作るEthereum Address生成機 / Ethereum Address Generator made by Tauri, Rust, SolidJS
serinuntius
0
230
世界最速で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
930
Why does the concept of DeFi make our souls tremble? / なぜDeFiという概念が俺達の魂を震えさせるのか ~DEX(AMM)まで~
serinuntius
0
1.3k
NotionがCMS代わりに!? / Notion replaces CMS!?
serinuntius
0
890
ont hackathon
serinuntius
0
70
新卒Rubyistが1ヶ月で Perl Mongerになった話
serinuntius
0
470
Other Decks in Technology
See All in Technology
1等無人航空機操縦士一発試験 合格までの道のり ドローンミートアップ@大阪 2024/12/18
excdinc
0
150
OpenShift Virtualizationのネットワーク構成を真剣に考えてみた/OpenShift Virtualization's Network Configuration
tnk4on
0
130
Turing × atmaCup #18 - 1st Place Solution
hakubishin3
0
470
podman_update_2024-12
orimanabu
1
260
.NET 9 のパフォーマンス改善
nenonaninu
0
500
Snykで始めるセキュリティ担当者とSREと開発者が楽になる脆弱性対応 / Getting started with Snyk Vulnerability Response
yamaguchitk333
2
180
開発生産性向上! 育成を「改善」と捉えるエンジニア育成戦略
shoota
1
230
AI時代のデータセンターネットワーク
lycorptech_jp
PRO
1
280
How to be an AWS Community Builder | 君もAWS Community Builderになろう!〜2024 冬 CB募集直前対策編?!〜
coosuke
PRO
2
2.8k
kargoの魅力について伝える
magisystem0408
0
200
大幅アップデートされたRagas v0.2をキャッチアップ
os1ma
2
520
社外コミュニティで学び社内に活かす共に学ぶプロジェクトの実践/backlogworld2024
nishiuma
0
250
Featured
See All Featured
Side Projects
sachag
452
42k
BBQ
matthewcrist
85
9.4k
Adopting Sorbet at Scale
ufuk
73
9.1k
Rails Girls Zürich Keynote
gr2m
94
13k
KATA
mclloyd
29
14k
Fontdeck: Realign not Redesign
paulrobertlloyd
82
5.3k
Reflections from 52 weeks, 52 projects
jeffersonlam
347
20k
Measuring & Analyzing Core Web Vitals
bluesmoon
4
170
Stop Working from a Prison Cell
hatefulcrawdad
267
20k
Fireside Chat
paigeccino
34
3.1k
Producing Creativity
orderedlist
PRO
341
39k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
280
13k
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༏উͯ͠মᇋͬͯ͘Ε