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
go-athenaの大量データ取得を速くした方法
Search
muroon
April 19, 2021
Programming
1
370
go-athenaの大量データ取得を速くした方法
muroon
April 19, 2021
Tweet
Share
More Decks by muroon
See All by muroon
UZOUにおけるAerospike
muroon
0
260
GCにおけるパフォーマンス改善
muroon
0
840
Goの静的解析を使用してAPI Doc Linterをつくる
muroon
0
71
Cloude Spannerの主キーの設計
muroon
0
49
Other Decks in Programming
See All in Programming
Flutter On-device AI로 완성하는 오프라인 앱, 박제창 @DevFest INCHEON 2025
itsmedreamwalker
1
180
Spinner 軸ズレ現象を調べたらレンダリング深淵に飲まれた #レバテックMeetup
bengo4com
1
210
Cap'n Webについて
yusukebe
0
160
20251212 AI 時代的 Legacy Code 營救術 2025 WebConf
mouson
0
240
ローカルLLMを⽤いてコード補完を⾏う VSCode拡張機能を作ってみた
nearme_tech
PRO
0
240
AIの誤りが許されない業務システムにおいて“信頼されるAI” を目指す / building-trusted-ai-systems
yuya4
7
4.3k
2年のAppleウォレットパス開発の振り返り
muno92
PRO
0
180
gunshi
kazupon
1
140
Canon EOS R50 V と R5 Mark II 購入でみえてきた最近のデジイチ VR180 事情、そして VR180 静止画に活路を見出すまで
karad
0
140
Pythonではじめるオープンデータ分析〜書籍の紹介と書籍で紹介しきれなかった事例の紹介〜
welliving
3
760
Developing static sites with Ruby
okuramasafumi
1
340
CSC307 Lecture 02
javiergs
PRO
1
740
Featured
See All Featured
The Hidden Cost of Media on the Web [PixelPalooza 2025]
tammyeverts
2
130
The Curse of the Amulet
leimatthew05
0
6.8k
Amusing Abliteration
ianozsvald
0
84
Visual Storytelling: How to be a Superhuman Communicator
reverentgeek
2
410
Raft: Consensus for Rubyists
vanstee
141
7.3k
Kristin Tynski - Automating Marketing Tasks With AI
techseoconnect
PRO
0
120
We Analyzed 250 Million AI Search Results: Here's What I Found
joshbly
0
400
The Invisible Side of Design
smashingmag
302
51k
Build The Right Thing And Hit Your Dates
maggiecrowley
38
3k
Skip the Path - Find Your Career Trail
mkilby
0
38
YesSQL, Process and Tooling at Scale
rocio
174
15k
How People are Using Generative and Agentic AI to Supercharge Their Products, Projects, Services and Value Streams Today
helenjbeal
1
94
Transcript
go-athenaの⼤量データ取得 を速くした⽅法
⾃⼰紹介 muroon https://twitter.com/muroon01 https://github.com/muroon Speeeという会社で広告配信システムを開発 Go歴は3年くらい
go-athenaとは database/sqlパッケージのAthenaのdriver import ( "database/sql" _ "github.com/speee/go-athena" ) func main()
{ db, _ := sql.Open("athena", "db=default&output_location=s3://results") rows, _ := db.Query("SELECT url, code from cloudfront") for rows.Next() { var url string var code int rows.Scan(&url, &code) } }
AWS Athenaとは AWS Athenaはサーバレスな分析サービスで、S3に保存・蓄積し たデータに対してSQLクエリにてデータ取得を⾏えるサービスで す。 • S3にデータを保存 • SQL検索
特徴 • APIを介してSQL実⾏ • SQLの結果をCSVダウンロードすることも可能 • CTASテーブルを使って圧縮形式でデータを取得する⽅法もあ る • GZIP • SNAPPY(Parquet)
go-athenaの⻑所 database/sqlパッケージを使⽤することにより、Goの開発者に とって開発しやすい データ取得がより簡単にできる • AWS Go SDK(https://docs.aws.amazon.com/sdk-for- go/api/service/athena/)を使⽤した場合 •
aws-sdk-goのAPI仕様を別途理解 • 接続確⽴、SQL実⾏、結果取得それぞれAPIアクセスが必要
go-athenaの問題点 APIアクセスしかできないこと • 取得件数が約1000件を超えるとrows.Next()の内部で複数ネッ トワークIOが⾛る rows, _ := db.Query("SELECT url,
code from cloudfront") for rows.Next() { var url string var code int rows.Scan(&url, &code) } ① ② ① ② 約1000件を超えると複数回取得する。O(n)
CSV, GZIP DLモードを作成 Resultモードというものを設けてCSVダウンロード、GZIPダウン ロードを可能にする • APIモード(default) • DLモード •
GZIPモード O(1)のネットワークアクセス ② ② 圧縮データダウンロード DLモード GZIPモード ①
各モードのパフォーマンス • 少量の件数ではDLモード、APIモードが有効 • ⼤量の件数ではGZIP DLモードが⾮常に有効
Resultモードの使⽤⽅法 Open時に設定 # API Mode db, err := sql.Open(“Athena”,”db=xxx&…”) #
DL Mode db, err := sql.Open(“Athena”,”db=xxx&…&result_mode=dl") # GZIP DL Mode db, err := sql.Open("athena","db=xxx&…&result_mode=gzip") SQL毎に設定 # API Mode ctx = SetAPIMode(ctx) # DL Mode ctx = SetDLMode(ctx) # GZIP DL Mode ctx = SetGzipDLMode(ctx)
URL https://github.com/speee/go-athena • fork元(segmentio/go-athena)のOrganizationは 2年近くメンテ ナンスされてないよう… • メンテする予定がないならリポジトリのTransferを検討しても らえないかを交渉中
ご清聴ありがとうございました