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
810
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
210
世界最速でArbitrumで NFTを作って震えたい!!!!/ I want to make NFT with Arbitrum in the fastest way in the world and tremble !!!!
serinuntius
0
600
なぜフラッシュローンという概念が俺達の魂を震えさせるのか / Why does the concept of flash loans make our souls tremble?
serinuntius
0
890
Why does the concept of DeFi make our souls tremble? / なぜDeFiという概念が俺達の魂を震えさせるのか ~DEX(AMM)まで~
serinuntius
0
1.2k
NotionがCMS代わりに!? / Notion replaces CMS!?
serinuntius
0
870
ont hackathon
serinuntius
0
64
新卒Rubyistが1ヶ月で Perl Mongerになった話
serinuntius
0
450
Other Decks in Technology
See All in Technology
LeSSはスクラムではない!?LeSSにおけるスクラムマスターの振る舞い方とは / Scrum Master Behavior in LeSS
toma_sm
0
210
Develop to Survive - YAPC::Hakodate 2024 Keynote
moznion
8
2.5k
LINEヤフー新卒採用 コーディングテスト解説 アルゴリズム問題編
lycorp_recruit_jp
0
13k
Azure App Service on Linux の Sidecar に Phi-3 を配置してインテリジェントなアプリケーションを作ってみよう/jazug-anniv14
thara0402
0
420
リスクから学ぶKubernetesコンテナセキュリティ/k8s-risk-and-security
mochizuki875
1
320
TypeScript x Raycast x AIで変える開発者体験
nagauta
1
260
ドキュメントとの付き合い方を考える
leveragestech
1
140
入社半年(合計1年)でGoogle Cloud 認定を全冠した秘訣🤫
risatube
1
210
LINEヤフー新卒採用 コーディングテスト解説 実装問題編
lycorp_recruit_jp
1
12k
Kubernetes Meetup Tokyo #67 - KEP-3619: Fine-grained SupplementalGroups Control / k8sjp67-kep-3619
everpeace
0
110
Databricks Appのご紹介
databricksjapan
0
270
テストを楽に書きたい
tomorrowkey
0
110
Featured
See All Featured
Design by the Numbers
sachag
278
19k
Optimising Largest Contentful Paint
csswizardry
31
2.8k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
355
29k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
3
230
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
7
580
Understanding Cognitive Biases in Performance Measurement
bluesmoon
26
1.3k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
327
21k
Being A Developer After 40
akosma
84
590k
From Idea to $5000 a Month in 5 Months
shpigford
381
46k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
664
120k
Debugging Ruby Performance
tmm1
73
12k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
9
1.2k
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༏উͯ͠মᇋͬͯ͘Ε