Submit Search
Upload
appengine/datastore パッケージを読む
•
1 like
•
1,202 views
靖
靖 陣内
Follow
6/14(木) に開かれた「やっぱり AppEngine ja night #3」の LT 登壇資料です。
Read less
Read more
Technology
Report
Share
Report
Share
1 of 18
Download now
Download to read offline
Recommended
Code injectiontool
Code injectiontool
Shunsuke Araki
実践Go ツールの作成から配布まで
実践Go ツールの作成から配布まで
Yusuke Miyake
Spring Data RESTを利用したAPIの設計と、作り直しまでの道のり
Spring Data RESTを利用したAPIの設計と、作り直しまでの道のり
Rakuten Group, Inc.
東海GTUG 20110910発表資料
東海GTUG 20110910発表資料
Kenji NAKAGAKI
scala-kaigi1-sbt
scala-kaigi1-sbt
Kenji Yoshida
Astahプラグイン開発勉強会
Astahプラグイン開発勉強会
Kinji Akemine
Collecting corpus
Collecting corpus
Atsushi Hayakawa
Go静的解析ハンズオン
Go静的解析ハンズオン
Takuya Ueda
Recommended
Code injectiontool
Code injectiontool
Shunsuke Araki
実践Go ツールの作成から配布まで
実践Go ツールの作成から配布まで
Yusuke Miyake
Spring Data RESTを利用したAPIの設計と、作り直しまでの道のり
Spring Data RESTを利用したAPIの設計と、作り直しまでの道のり
Rakuten Group, Inc.
東海GTUG 20110910発表資料
東海GTUG 20110910発表資料
Kenji NAKAGAKI
scala-kaigi1-sbt
scala-kaigi1-sbt
Kenji Yoshida
Astahプラグイン開発勉強会
Astahプラグイン開発勉強会
Kinji Akemine
Collecting corpus
Collecting corpus
Atsushi Hayakawa
Go静的解析ハンズオン
Go静的解析ハンズオン
Takuya Ueda
2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
Marius Sescu
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
Expeed Software
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
Pixeldarts
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
marketingartwork
Skeleton Culture Code
Skeleton Culture Code
Skeleton Technologies
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
Neil Kimberley
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
contently
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
Albert Qian
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
Search Engine Journal
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
SpeakerHub
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
Clark Boyd
Getting into the tech field. what next
Getting into the tech field. what next
Tessa Mero
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Lily Ray
How to have difficult conversations
How to have difficult conversations
Rajiv Jayarajah, MAppComm, ACC
Introduction to Data Science
Introduction to Data Science
Christy Abraham Joy
Time Management & Productivity - Best Practices
Time Management & Productivity - Best Practices
Vit Horky
The six step guide to practical project management
The six step guide to practical project management
MindGenius
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
RachelPearson36
More Related Content
Featured
2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
Marius Sescu
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
Expeed Software
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
Pixeldarts
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
marketingartwork
Skeleton Culture Code
Skeleton Culture Code
Skeleton Technologies
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
Neil Kimberley
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
contently
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
Albert Qian
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
Search Engine Journal
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
SpeakerHub
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
Clark Boyd
Getting into the tech field. what next
Getting into the tech field. what next
Tessa Mero
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Lily Ray
How to have difficult conversations
How to have difficult conversations
Rajiv Jayarajah, MAppComm, ACC
Introduction to Data Science
Introduction to Data Science
Christy Abraham Joy
Time Management & Productivity - Best Practices
Time Management & Productivity - Best Practices
Vit Horky
The six step guide to practical project management
The six step guide to practical project management
MindGenius
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
RachelPearson36
Featured
(20)
2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
Skeleton Culture Code
Skeleton Culture Code
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
Getting into the tech field. what next
Getting into the tech field. what next
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
How to have difficult conversations
How to have difficult conversations
Introduction to Data Science
Introduction to Data Science
Time Management & Productivity - Best Practices
Time Management & Productivity - Best Practices
The six step guide to practical project management
The six step guide to practical project management
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
appengine/datastore パッケージを読む
1.
appengine/datastore パッケージを読む 〜または OSS への
contribute について〜 1
2.
自己紹介 名前 陣内 靖(じんのうち
やすし) アカウント @delphinus (GitHub) @delphinus35 (Twitter) 所属 株式会社ディー・エヌ・エー(DeNA) AppEngine 歴 2年くらい ハマってるもの Splatoon2。Switch 最近買った。 オクト・エキスパンジョン今日出ましたね! 2
3.
今日のお題 対象者 ● GAE/Go SE
で Datastore 使ったことのある人。 ● あんまり OSS に contribute とかしたことない人。 内容 ● appengine/datastore パッケージのコードリーディング。 ● BatchSize というニッチなメソッドを実装する際にやったこと。 ○ https://github.com/golang/appengine/pull/90 3
4.
一度に全 Entity を取得したい! 構造体のプロパティ追加・削除したいときとか…… Entity
の数が多いとお金かかるからあんまりやりたくないのだけども。 (KeysOnly なら無料) 全部じゃなくても数千 Entity〜 の結果が変えるクエリなら同じ影響あり。 4
5.
普通に GetAll してみると……(その1) 5
6.
普通に GetAll してみると……(その2) なんだか効率が悪い? 「問題」も指摘されている…… 6
7.
指摘を詳しく見てみると…… このリクエストを処理中に datastore.next() へのリモート
プロシージャ コールが 249 回実行されました。クエリのバッチサイズとして 20 を指定していたことが原因と 考えられます。 いや、そんな指定した覚えはないしバッチサイズって何……? クエリのバッチサイズの値を増やし、datastore.next() のコール回数を減らしてくださ い。 どうやって? というか datastore.next() って何者? 7
8.
appengine/datastore でクエリを処理するには 通常、クエリを発行した後に Entity
を取り出すには2つの方法があります。 ● q.GetAll(ctx, &entities) で一気に全部取り出す。 ○ 変数 entities に全部突っ込まれる。 ● t := q.Run() した後 t.Next() で一個ずつ取り出す。 ○ メモリを余り消費しないので扱う Entity が多い場合はこちらが安心。 ○ とはいえ、まさか一個取り出す度に Datastore にアクセスする訳ではないよね……? ■ ⇒読んでみるとなかなかスマートなロジックになっていた。 8
9.
q.GetAll = q.Run
+ t.Next 実際のソースを読んでみると、両者は同じことを行っていることが分かります。 func GetAll(...) ([]*Key, error) { ... for t := q.Run(c); ; { k, e, err := t.next() ... } ... } 9
10.
t.next() は何をやっている? Datastore へのアクセスを極力少なくするようになっています。ソースはここ。 func
(t *Iterator) next() (...) { ... for (必要なときだけ真) { callNext() ... // ←実際に Datastore へ RPC してるヤツ } // 予め上で取得しておいた Pool から 目当ての Entity を取り出す return ... } 10
11.
callNext() が Datastore
にアクセスする ということが分かります。ソースはここ(修正前)。 ここで呼んでいる RPC が最初に出てきた datastore.next()。 一度に Get する数がバッチサイズだったのです。 でもバッチサイズを指定するための適当なメソッドがない…… 11
12.
ハックしてバッチサイズを指定可能にする なんとレスポンスが 2分の1に! 12
13.
初 contribute これは他にも便利に思う人が多そう。 ひとまず issue
立ててみる。誰かこれで実装してくれるかな…… ……と思ったけど、これくらいなら実装してみよう。 そもそもこんなマイナーなの誰も実装してくれないし。 ⇒おそるおそる PR してみた。 13
14.
BatchSize の指定の仕方 こんな風に指定できたら便利そう。 // BatchSize
に適当な値を指定 q := datastore.NewQuery(“Hoge”).BatchSize(500) // もちろん他の条件を追加しても OK q := datastore.NewQuery(“Hoge”).BatchSize(500). Filter(“Age >=”, 20).Order(“Age”) コード例はここに置いています。 ● https://github.com/delphinus/datastore-batchsize-test 14
15.
ここからが長かった…… https://github.com/golang/appengine/pull/90 PR したのは 2017年9月。その後1ヶ月間、完全に放置される。 催促してみるが、またもや放置。 4ヵ月経ってレビューコメントが付くが、今度は僕が放置(気付かなかった)。 なんやかんやあってマージされたのは今年の5月。 15
16.
結論:OSS への contribute
は気長にね! 16
17.
まとめ 動作が分からないときはソースを読もう! なんかおかしいと思ったら気軽に contribute しよう! 無視されてもめげるな!
それが通常運行だ! 17
18.
18
Download now