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
850
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
160
TauriとRustとSolidJSで作るEthereum Address生成機 / Ethereum Address Generator made by Tauri, Rust, SolidJS
serinuntius
0
240
世界最速でArbitrumで NFTを作って震えたい!!!!/ I want to make NFT with Arbitrum in the fastest way in the world and tremble !!!!
serinuntius
0
620
なぜフラッシュローンという概念が俺達の魂を震えさせるのか / Why does the concept of flash loans make our souls tremble?
serinuntius
0
950
Why does the concept of DeFi make our souls tremble? / なぜDeFiという概念が俺達の魂を震えさせるのか ~DEX(AMM)まで~
serinuntius
0
1.3k
NotionがCMS代わりに!? / Notion replaces CMS!?
serinuntius
0
910
ont hackathon
serinuntius
0
74
新卒Rubyistが1ヶ月で Perl Mongerになった話
serinuntius
0
490
Other Decks in Technology
See All in Technology
消し忘れリソースゼロへ!私のResource Explorer活用法
cuorain
0
110
GraphRAG: What I Thought I Knew (But Didn’t)
sashimimochi
0
110
Asset Centric な データ変換パイプラインの攻略法
recruitengineers
PRO
1
100
なぜfreeeはハブ・アンド・スポーク型の データメッシュアーキテクチャにチャレンジするのか?
shinichiro_joya
3
900
サーバレスの未来〜The Key to Simplifying Everything〜
kawaji_scratch
2
330
2025-01-24-SRETT11-OpenTofuについてそろそろ調べてみるか
masasuzu
0
130
SREとしてスタッフエンジニアを目指す / SRE Kaigi 2025
tjun
14
4.7k
Agentic AI時代のプロダクトマネジメントことはじめ〜仮説検証編〜
masakazu178
0
220
dbtを中心にして組織のアジリティとガバナンスのトレードオンを考えてみた
gappy50
2
400
MicrosoftのOSSだけでAIによるブラウザテストを構成する
ymd65536
1
220
LLM活用の現在とこれから:LayerXにおける事例とともに 2025/1 ver. / layerx-llm-202501
yuya4
3
240
論文紹介 ”Long-Context LLMs Meet RAG: Overcoming Challenges for Long Inputs in RAG” @GDG Tokyo
shukob
0
230
Featured
See All Featured
Building Your Own Lightsaber
phodgson
104
6.2k
We Have a Design System, Now What?
morganepeng
51
7.4k
How to Ace a Technical Interview
jacobian
276
23k
Measuring & Analyzing Core Web Vitals
bluesmoon
5
210
Understanding Cognitive Biases in Performance Measurement
bluesmoon
27
1.5k
A Tale of Four Properties
chriscoyier
157
23k
Side Projects
sachag
452
42k
How to train your dragon (web standard)
notwaldorf
89
5.8k
Testing 201, or: Great Expectations
jmmastey
41
7.2k
How to Think Like a Performance Engineer
csswizardry
22
1.3k
Unsuck your backbone
ammeep
669
57k
The Cult of Friendly URLs
andyhume
78
6.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༏উͯ͠মᇋͬͯ͘Ε