Download free for 30 days
Sign in
Upload
Language (EN)
Support
Business
Mobile
Social Media
Marketing
Technology
Art & Photos
Career
Design
Education
Presentations & Public Speaking
Government & Nonprofit
Healthcare
Internet
Law
Leadership & Management
Automotive
Engineering
Software
Recruiting & HR
Retail
Sales
Services
Science
Small Business & Entrepreneurship
Food
Environment
Economy & Finance
Data & Analytics
Investor Relations
Sports
Spiritual
News & Politics
Travel
Self Improvement
Real Estate
Entertainment & Humor
Health & Medicine
Devices & Hardware
Lifestyle
Change Language
Language
English
Español
Português
Français
Deutsche
Cancel
Save
Submit search
EN
Uploaded by
Toshiaki Maki
PDF, PPTX
10,837 views
そんなリザルトキャッシュで大丈夫か? #jjug
JJUGナイトセミナー2014年9月のセッション 「そんなリザルトキャッシュで大丈夫か?」 のスライドです。
Technology
◦
Read more
36
Save
Share
Embed
Embed presentation
Download
Download as PDF, PPTX
1
/ 48
2
/ 48
3
/ 48
4
/ 48
5
/ 48
6
/ 48
7
/ 48
8
/ 48
9
/ 48
10
/ 48
11
/ 48
12
/ 48
13
/ 48
14
/ 48
15
/ 48
16
/ 48
17
/ 48
18
/ 48
19
/ 48
20
/ 48
21
/ 48
22
/ 48
23
/ 48
24
/ 48
25
/ 48
26
/ 48
27
/ 48
28
/ 48
29
/ 48
30
/ 48
31
/ 48
32
/ 48
33
/ 48
34
/ 48
35
/ 48
36
/ 48
37
/ 48
38
/ 48
39
/ 48
40
/ 48
41
/ 48
42
/ 48
43
/ 48
44
/ 48
45
/ 48
46
/ 48
47
/ 48
48
/ 48
More Related Content
PDF
逆戻りデバッグ補助のための嵌入的スパイの試作
by
Kamiya Toshihiro
PDF
20181211 - PGconf.ASIA - NVMESSD&GPU for BigData
by
Kohei KaiGai
PDF
BigQueryの課金、節約しませんか
by
Ryuji Tamagawa
PPTX
JavaでインメモリSQLエンジンを作ってみた
by
JustSystems Corporation
PDF
BMXUG ブロックチェーンハンズオン 20190622
by
Kohei Nishikawa
PDF
20170127 JAWS HPC-UG#8
by
Kohei KaiGai
PDF
Terraformを使ったCloudStack環境構築
by
Atsushi Sasaki
PDF
ジャパネットQB GPars
by
Takahiro Sugiura
逆戻りデバッグ補助のための嵌入的スパイの試作
by
Kamiya Toshihiro
20181211 - PGconf.ASIA - NVMESSD&GPU for BigData
by
Kohei KaiGai
BigQueryの課金、節約しませんか
by
Ryuji Tamagawa
JavaでインメモリSQLエンジンを作ってみた
by
JustSystems Corporation
BMXUG ブロックチェーンハンズオン 20190622
by
Kohei Nishikawa
20170127 JAWS HPC-UG#8
by
Kohei KaiGai
Terraformを使ったCloudStack環境構築
by
Atsushi Sasaki
ジャパネットQB GPars
by
Takahiro Sugiura
What's hot
PDF
Precise garbage collection for c
by
miura1729
PDF
130727 nagoyar presentation
by
Takayuki Nuimura
PDF
PL/CUDA - GPU Accelerated In-Database Analytics
by
Kohei KaiGai
PDF
PostgreSQL v9.5の新機能~CustomScan/Join Interface
by
Kohei KaiGai
PDF
RGtk2入門
by
Masahiro Hayashi
PDF
第8回KPF発表資料
by
cryks
PDF
Custom Scan API - PostgreSQL Unconference #3 (18-Jan-2014)
by
Kohei KaiGai
PPTX
Node.js - JavaScript Thread Programming
by
takesako
PDF
テーマ「最適化」
by
technocat
PDF
GPUをJavaで使う話(Java Casual Talks #1)
by
なおき きしだ
PDF
20180920_DBTS_PGStrom_JP
by
Kohei KaiGai
PDF
JVM! JVM! JVM!
by
Masaaki HIROSE
PDF
「Grails-1.1を斬る!〜Grails-1.1からのチーム開発〜」
by
Tsuyoshi Yamamoto
PDF
20150530 pgunconf-pgbench-semi-structured-benchmark
by
Toshi Harada
Precise garbage collection for c
by
miura1729
130727 nagoyar presentation
by
Takayuki Nuimura
PL/CUDA - GPU Accelerated In-Database Analytics
by
Kohei KaiGai
PostgreSQL v9.5の新機能~CustomScan/Join Interface
by
Kohei KaiGai
RGtk2入門
by
Masahiro Hayashi
第8回KPF発表資料
by
cryks
Custom Scan API - PostgreSQL Unconference #3 (18-Jan-2014)
by
Kohei KaiGai
Node.js - JavaScript Thread Programming
by
takesako
テーマ「最適化」
by
technocat
GPUをJavaで使う話(Java Casual Talks #1)
by
なおき きしだ
20180920_DBTS_PGStrom_JP
by
Kohei KaiGai
JVM! JVM! JVM!
by
Masaaki HIROSE
「Grails-1.1を斬る!〜Grails-1.1からのチーム開発〜」
by
Tsuyoshi Yamamoto
20150530 pgunconf-pgbench-semi-structured-benchmark
by
Toshi Harada
More from Toshiaki Maki
PDF
From Spring Boot 2.2 to Spring Boot 2.3 #jsug
by
Toshiaki Maki
PDF
Concourse x Spinnaker #concourse_tokyo
by
Toshiaki Maki
PDF
Serverless with Spring Cloud Function, Knative and riff #SpringOneTour #s1t
by
Toshiaki Maki
PDF
決済システムの内製化への旅 - SpringとPCFで作るクラウドネイティブなシステム開発 #jsug #sf_h1
by
Toshiaki Maki
PDF
Spring Boot Actuator 2.0 & Micrometer #jjug_ccc #ccc_a1
by
Toshiaki Maki
PDF
Spring Boot Actuator 2.0 & Micrometer
by
Toshiaki Maki
PDF
Open Service Broker APIとKubernetes Service Catalog #k8sjp
by
Toshiaki Maki
PDF
Spring Cloud Function & Project riff #jsug
by
Toshiaki Maki
PDF
Introduction to Spring WebFlux #jsug #sf_a1
by
Toshiaki Maki
PDF
BOSH / CF Deployment in modern ways #cf_tokyo
by
Toshiaki Maki
PDF
Why PCF is the best platform for Spring Boot
by
Toshiaki Maki
PDF
Zipkin Components #zipkin_jp
by
Toshiaki Maki
PPTX
マイクロサービスに必要な技術要素はすべてSpring Cloudにある #DO07
by
Toshiaki Maki
PDF
Spring Framework 5.0による Reactive Web Application #JavaDayTokyo
by
Toshiaki Maki
PDF
実例で学ぶ、明日から使えるSpring Boot Tips #jsug
by
Toshiaki Maki
PDF
Spring ❤️ Kotlin #jjug
by
Toshiaki Maki
PDF
Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3
by
Toshiaki Maki
PDF
Managing your Docker image continuously with Concourse CI
by
Toshiaki Maki
PDF
Data Microservices with Spring Cloud Stream, Task, and Data Flow #jsug #spri...
by
Toshiaki Maki
PDF
Short Lived Tasks in Cloud Foundry #cfdtokyo
by
Toshiaki Maki
From Spring Boot 2.2 to Spring Boot 2.3 #jsug
by
Toshiaki Maki
Concourse x Spinnaker #concourse_tokyo
by
Toshiaki Maki
Serverless with Spring Cloud Function, Knative and riff #SpringOneTour #s1t
by
Toshiaki Maki
決済システムの内製化への旅 - SpringとPCFで作るクラウドネイティブなシステム開発 #jsug #sf_h1
by
Toshiaki Maki
Spring Boot Actuator 2.0 & Micrometer #jjug_ccc #ccc_a1
by
Toshiaki Maki
Spring Boot Actuator 2.0 & Micrometer
by
Toshiaki Maki
Open Service Broker APIとKubernetes Service Catalog #k8sjp
by
Toshiaki Maki
Spring Cloud Function & Project riff #jsug
by
Toshiaki Maki
Introduction to Spring WebFlux #jsug #sf_a1
by
Toshiaki Maki
BOSH / CF Deployment in modern ways #cf_tokyo
by
Toshiaki Maki
Why PCF is the best platform for Spring Boot
by
Toshiaki Maki
Zipkin Components #zipkin_jp
by
Toshiaki Maki
マイクロサービスに必要な技術要素はすべてSpring Cloudにある #DO07
by
Toshiaki Maki
Spring Framework 5.0による Reactive Web Application #JavaDayTokyo
by
Toshiaki Maki
実例で学ぶ、明日から使えるSpring Boot Tips #jsug
by
Toshiaki Maki
Spring ❤️ Kotlin #jjug
by
Toshiaki Maki
Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3
by
Toshiaki Maki
Managing your Docker image continuously with Concourse CI
by
Toshiaki Maki
Data Microservices with Spring Cloud Stream, Task, and Data Flow #jsug #spri...
by
Toshiaki Maki
Short Lived Tasks in Cloud Foundry #cfdtokyo
by
Toshiaki Maki
そんなリザルトキャッシュで大丈夫か? #jjug
1.
そんなリザルトキャッシュ で大丈夫か? @making
槙 俊明 2014-09-17
2.
ここでいうリザルトキャッシュ とは •重い処理の結果を格納するメモ
リ(キャッシュ) •リザルトキャッシュを再利用す ることで性能向上が期待できる
3.
あなたのリザルトキャッシュ •スレッドセーフですか? •スケーラブルですか?
5.
5-6 「効率的でスケーラブ ルなリザルトキャッシュを
構築する」 の内容をご紹介します
6.
たまにみる実装
7.
たまにみる実装 static Map<BigInteger,
List<BigInteger>> cache = new HashMap<>; void doGet(…) { BigInteger n = …; List<BigInteger> result = cache.get(n); if (result == null) { result = PrimeFactor.divide(n); // 素因数分解 cache.put(n, result); } // … }
8.
たまにみる実装 static Map<BigInteger,
List<BigInteger>> cache = new HashMap<>; void doGet(…) { BigInteger n = …; List<BigInteger> result = cache.get(n); if (result == null) { result = PrimeFactor.divide(n); // 素因数分解 cache.put(n, result); } // … }
9.
たまにみる実装 static Map<BigInteger,
List<BigInteger>> cache = new HashMap<>; void doGet(…) { BigInteger n = …; List<BigInteger> result = cache.get(n); if (result == null) { result = PrimeFactor.divide(n); // 素因数分解 cache.put(n, result); } // … } キャッシュになかったら 計算してキャッシュに追加
10.
11.
static Map<BigInteger, List<BigInteger>>
cache = new HashMap<>; void doGet(…) { BigInteger n = …; List<BigInteger> result = cache.get(n); if (result == null) { result = PrimeFactor.divide(n); // 素因数分解 cache.put(n, result); } // … } スレッドアンセーフ
12.
よく見る実装 static Map<BigInteger,
List<BigInteger>> cache = new ConcurrentHashMap<>; void doGet(…) { BigInteger n = …; List<BigInteger> result = cache.get(n); if (result == null) { result = PrimeFactor.divide(n); // 素因数分解(重い処理) cache.put(n, result); } // … }
13.
よく見る実装 static Map<BigInteger,
List<BigInteger>> cache = new ConcurrentHashMap<>; void doGet(…) { BigInteger n = …; List<BigInteger> result = cache.get(n); if (result == null) { スレッドセーフなMapに変更 result = PrimeFactor.divide(n); // 素因数分解(重い処理) cache.put(n, result); } // … }
14.
Demo
15.
16.
check get calc
put check get calc put
17.
check get calc
put check get calc put
18.
check get calc
put check get calc put まだputされていない
19.
static Map<BigInteger, List<BigInteger>>
cache = new ConcurrentHashMap<>; void doGet(…) { BigInteger n = …; List<BigInteger> result = cache.get(n); if (result == null) { result = PrimeFactor.divide(n); // 素因数分解(重い処理) cache.put(n, result); } // … } Atomicじゃない
20.
FutureTaskを使って遅延評価
21.
FutureTaskを使って遅延評価 static Map<BigInteger,
FutureTask<List<BigInteger>>> cache = new ConcurrentHashMap<>; void doGet(…) { BigInteger n = …; FutureTask<List<BigInteger>> result = cache.get(n); if (result == null) { result = new FutureTask<>(() -> PrimeFactor.divide(n))); cache.put(n, result); result.run(); } // (略) result.get()で結果取得できるまでブロックする }
22.
FutureTaskを使って遅延評価 static Map<BigInteger,
FutureTask<List<BigInteger>>> cache = new ConcurrentHashMap<>; void doGet(…) { BigInteger n = …; FutureTask<List<BigInteger>> result = cache.get(n); if (result == null) { result = new FutureTask<>(() -> PrimeFactor.divide(n))); cache.put(n, result); result.run(); Callableで処理を記述 } // (略) result.get()で結果取得できるまでブロックする }
23.
FutureTaskを使って遅延評価 static Map<BigInteger,
FutureTask<List<BigInteger>>> cache = new ConcurrentHashMap<>; void doGet(…) { BigInteger n = …; FutureTask<List<BigInteger>> result = cache.get(n); if (result == null) { result = new FutureTask<>(() -> PrimeFactor.divide(n))); cache.put(n, result); result.run(); Callableで処理を記述 } // (略) result.get()で結果取得できるまでブロックする } キャッシュに入れてから処理実行
24.
check get put
calc check get put
25.
Demo
26.
27.
check get put
calc check get put calc
28.
check get put
calc check get put calc
29.
check get put
calc check get put calc 新しいFutureTaskで上書きされた
30.
check get put
calc check get put calc 結局2回計算 新しいFutureTaskで上書きされた
31.
FutureTaskを使って遅延評価 static Map<BigInteger,
FutureTask<List<BigInteger>>> cache = new ConcurrentHashMap<>; void doGet(…) { BigInteger n = …; FutureTask<List<BigInteger>> result = cache.get(n); if (result == null) { result = new FutureTask<>(() -> PrimeFactor.divide(n))); cache.put(n, result); result.run(); } // (略) result.get()で結果取得できるまでブロックする } Atomicじゃない
32.
ConcurrentMap#putIfAbsent
33.
ConcurrentMap#putIfAbsent static ConcurrentMap<BigInteger,
FutureTask<List<BigInteger>>> cache = new ConcurrentHashMap<>; void doGet(…) { BigInteger n = …; FutureTask<List<BigInteger>> result = cache.get(n); if (result == null) { FutureTask<List<BigInteger>> ft = new FutureTask<>(() -> PrimeFactor.divide(n))); result = cache.putIfAbsent(n, result); if (result == null) {ft.run(); result = ft;} } // (略) result.get()で結果取得できるまでブロックする
34.
ConcurrentMap#putIfAbsent static ConcurrentMap<BigInteger,
FutureTask<List<BigInteger>>> cache = new ConcurrentHashMap<>; void doGet(…) { BigInteger n = …; FutureTask<List<BigInteger>> result = cache.get(n); if (result == null) { FutureTask<List<BigInteger>> ft = new FutureTask<>(() -> PrimeFactor.divide(n))); result = cache.putIfAbsent(n, result); if (result == null) {ft.run(); result = ft;} } // (略) result.get()で結果取得できるまでブロックする キーが存在しない場合はnullを、 存在する場合はそれを返す
35.
check get pIA
calc check get pIA pIA … putIfAbsent
36.
check get pIA
calc check get pIA pIA … putIfAbsent put済みなので上書きしない
37.
Demo
38.
39.
でも面倒くさいね!
40.
Java SE 8から
41.
Java SE 8から
static ConcurrentHashMap<BigInteger, List<BigInteger>> cache = new ConcurrentHashMap<>; void doGet(…) { BigInteger n = …; List<BigInteger> result = cache.computeIfAbsent(n, (x) -> PrimeFactor.divide(x)); // … }
42.
Java SE 8から
static ConcurrentHashMap<BigInteger, List<BigInteger>> cache = new ConcurrentHashMap<>; void doGet(…) { BigInteger n = …; List<BigInteger> result = cache.computeIfAbsent(n, (x) -> PrimeFactor.divide(x)); // … } キーが存在しない場合はラムダ式 の計算結果を返す
43.
Java SE 8から
static ConcurrentHashMap<BigInteger, List<BigInteger>> cache = new ConcurrentHashMap<>; void doGet(…) { BigInteger n = …; List<BigInteger> result = cache.computeIfAbsent(n, PrimeFactor::divide); // … } メソッド参照でOK
44.
Demo
45.
Cool!
46.
まとめ •ConcurrentHashMap#putIfAbsent +
FutureTaskで効率的なリザルトキャッシュ を実装できる •JDK8からは ConcurrentHashMap#computeIfAbsent でおk
47.
Java SE 8を使おう
48.
ご清聴 ありがとうございました
Download