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
High-performance Jackson #渋谷Java
Search
KOMIYA Atsushi
October 01, 2016
Programming
2
16k
High-performance Jackson #渋谷Java
第17回 #渋谷Java の発表資料です
http://shibuya-java.connpass.com/event/38674/
KOMIYA Atsushi
October 01, 2016
Tweet
Share
More Decks by KOMIYA Atsushi
See All by KOMIYA Atsushi
#JJUG Java における乱数生成器とのつき合い方
komiya_atsushi
5
5.1k
#JJUG Fork/Join フレームワークを効率的に正しく使いたい
komiya_atsushi
0
440
[#JSUG] SmartNews における container friendly な Spring Boot アプリケーション開発
komiya_atsushi
1
11k
Java のデータ圧縮ライブラリを極める #jjug_ccc #ccc_c7
komiya_atsushi
4
4.6k
#devsumi 自然言語処理・機械学習によるファクトチェック業務の支援
komiya_atsushi
1
4.3k
SmartNews Ads における機械学習の活用とその運用 #mlops
komiya_atsushi
3
19k
GBDT によるクリック率予測を高速化したい #オレシカナイト vol.4
komiya_atsushi
5
1.3k
Maven central repository の artifact をランキングする #渋谷java
komiya_atsushi
0
1.2k
確率的データ構造を Java で扱いたい! #JJUG
komiya_atsushi
6
2.2k
Other Decks in Programming
See All in Programming
Vue.js学習の振り返り
hiro_xre
2
130
Piniaの現状と今後
waka292
5
1.4k
PagerDuty を軸にした On-Call 構築と運用課題の解決 / PagerDuty Japan Community Meetup 4
horimislime
1
110
Synchronizationを支える技術
s_shimotori
1
150
From Subtype Polymorphism To Typeclass-based Ad hoc Polymorphism- An Example
philipschwarz
PRO
0
160
AWS IaCの注目アップデート 2024年10月版
konokenj
3
3.1k
CSC509 Lecture 08
javiergs
PRO
0
100
Vue SFCのtemplateでTypeScriptの型を活用しよう
tsukkee
3
1.5k
PLoP 2024: The evolution of the microservice architecture pattern language
cer
PRO
0
1.6k
Dev ContainersとGitHub Codespacesの素敵な関係
ymd65536
1
120
Snowflake x dbtで作るセキュアでアジャイルなデータ基盤
tsoshiro
2
420
offers_20241022_imakiire.pdf
imakurusu
2
360
Featured
See All Featured
KATA
mclloyd
29
13k
Mobile First: as difficult as doing things right
swwweet
222
8.9k
Build The Right Thing And Hit Your Dates
maggiecrowley
32
2.4k
Statistics for Hackers
jakevdp
796
220k
Designing for humans not robots
tammielis
249
25k
Being A Developer After 40
akosma
86
590k
Designing on Purpose - Digital PM Summit 2013
jponch
115
6.9k
Side Projects
sachag
452
42k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
27
1.9k
Into the Great Unknown - MozCon
thekraken
31
1.5k
The Straight Up "How To Draw Better" Workshop
denniskardys
232
140k
Teambox: Starting and Learning
jrom
132
8.7k
Transcript
High-performance Jackson ौ୩Java #17 2016-10-01 KOMIYA Atsushi (@komiya_atsushi)
KOMIYA Atsushi @komiya_atsushi
Today’s topic
Jackson
= JSON parser / generator Ͱͳ͍ (ݫີʹ)
“Jackson is a suite of data- processing tools for Java”
https://github.com/FasterXML/jackson/blob/master/README.md
JSON parer / generator ʰʱඪ४αϙʔτ͍ͯ͠Δ σʔλॲཧϥΠϒϥϦ
Jackson • JSON processor • Streaming API • Data binding
(POJO to and from JSON) • Other formats • XML, YAML • Avro, CBOR, CSV, Smile, Protobuf
Popular JSON Libraries • 4,180 usages: Jackson Databind • 2,820
usages: Gson • 1,238 usages: Json (org.json) • 516 usages: JSON.simple • 494 usages: Jersey Json ※mvnrepository.com ௐɺ2016-10-01 ࣌
Jackson as JSON processor • Pros • γϦΞϥΠζɾσγϦΞϥΠζͱʹ͍ • ࠷Ͱͳͦ͞͏͚ͩͲ…
• ػೳ͕๛Ͱɺᙱ͍ͱ͜Ζʹख͕ಧ͖͍͢ • ৼΔ͍ͷΧελϚΠζ·͋·͍͋͢͠ • ͍͍ҙຯͰރΕ͍ͯΔ ※ݸਓͷײͰ͋Γɺੑೳɾੑ࣭Λอূ͢ΔͷͰ͋Γ·ͤΜ
Jackson as JSON processor • Cons • ମܥతʹهड़͞Εͨྑ࣭ͳຊޠυΩϡϝϯτͳ͍ • ػೳ͕๛ա͗Δ͕Ώ͑ʹɺ͍͜ͳ͢ͷ͍͠
• ʮ͜͏͍͏͜ͱͰ͖Δͷ͔ͳʁʯ ʮͲ͏ͬͯઃఆ͢Ε͍͍Μͩʁʯ • ࣮៉ྷ͚ͩͲɺΫϥε͕ଟͯ͘ॳݟࡴ͠ײ͕͋ Δ ※ݸਓͷײͰ͋Γɺੑೳɾੑ࣭Λอূ͢ΔͷͰ͋Γ·ͤΜ
High-performance Jackson
(JSON prosessor ͱͯ͠ ࠷Ͱͳ͍͔͠Εͳ͍͕) Jackson Λ࠷ʹར༻͍ͨ͠❗
Shortest path to high-performance • Presentation: Jackson Performance • https://github.com/FasterXML/jackson-docs/
wiki/Presentation:-Jackson-Performance • Jackson Best Practices: Performance • http://wiki.fasterxml.com/ JacksonBestPracticesPerformance
ৄͪ͘͜͠ΒΛ͝ࢀরԼ͍͞ http://qiita.com/komiya_atsushi/items/803f69b51426ed476a75
ϕετϓϥΫςΟεʹै͏͜ͱͰ ͲΕ͘Β͍͘ͳΔͷ͔ʁ
ࠓճରͱ͍ͯ͠ΔλεΫ • 1 ߦ͝ͱʹ JSON ͕ه͞ΕͨϑΝΠϧ (= Line delimited JSON)
͕༩͑ΒΕ͍ͯΔ • JSON 1 ݅͝ͱʹಛఆͷॲཧΛ͍ͨ͠ • 㱺 JSON ͷσγϦΞϥΠζΛ࠷ʹ❗
۩ମతͳαϯϓϧλεΫ • Twitter Streaming API Ͱ 1,000 ݅ͷ tweet Λऩूͯ͠ɺ̍ͭ
ͷϑΝΠϧʹ·ͱΊ͓ͯ͘ ǖ DVSMHFUIUUQTTUSFBNUXJUUFSDPNTUBUVTFTTBNQMFKTPOǘ • શ෦Ͱ 4MB = JSON 1 ͭ͋ͨΓ 4KB ͙Β͍ • ্هϑΝΠϧΛಡΈࠐΈɺຊޠ tweet ͷ݅Λ্͑͛Δ • ຊޠ͔൱͔ “lang” ଐੑͷͰఆ͢Δ • ͜ͷλεΫͷεϧʔϓοτ (ops/s) Λ JMH Ͱଌఆ͢Δ
Baseline implementation • Best practice ʹࢥ͍͖ͬΓ͢Δɺ͋͑ͯ ඇޮͳ࣮͔Β࢝ΊΔ • ϑΝΠϧ͔Β 1
ߦͣͭจࣈྻͱͯ͠ಡΈࠐΉ • Data-binding Ͱ JSON → POJO ʹσγϦΞϥ Πζ͢Δ • ͜ͷॲཧͷɺObjectMapper Λੜ͢Δ
Baseline implementation 2.596 ops/s ͜Ε͕࠷ඇޮ
1. ObjectMapper Λ࠶ར༻͢Δ • POJO from JSON ͷ data-binding Λ͢Δͷʹ
ຖճੜ͍ͯͨ͠ ObjectMapper Λ͍·Θ͢ • ObjectMapper ͷΦϒδΣΫτੜಛʹॏ ͍ॲཧ • ObjectMapper εϨουηʔϑ ☺
1. ObjectMapper Λ࠶ར༻͢Δ 32.533 ops/s (12.53x)
2. ObjectReader Λར༻͢Δ • ObjectMapper ͷΘΓʹ ObjectReader Λ ͏ •
ObjectMapper Λ͏ΑΓͪΐͬͱ͚ͩ ޮ͕͍͍
2. ObjectReader Λར༻͢Δ 33.306 ops/s (1.024x)
3. ObjectReader #readValues(InputStream) • 1 ߦͣͭจࣈྻͱͯ͠ಡΈࠐΉͷΛΊɺ InputStream ͷ··Ͱ Jackson ʹ༩͑Δ
• Jackson byte[] InputSteam ͳͲͷ ೖྗιʔεʹରͯ͠࠷దԽ͍ͯ͠Δ • String ͷೖྗιʔεʹͦΜͳʹ࠷దԽ͍ͯ͠ ΔΘ͚Ͱͳ͍
ࢀߟهࣄ (InfoQ) https://www.infoq.com/jp/news/2014/05/jackson-founder-responds
ࢀߟهࣄ (InfoQ) https://www.infoq.com/jp/news/2014/05/jackson-founder-responds “Jackson͕RESTͷج൫Ͱ͋Δ όΠτετϦʔϜɼ͋Δ͍ ϑΝΠϧετϨʔδΛపఈత ʹ࠷దԽ͍ͯ͠Δ”
3. ObjectReader #readValues(InputStream) 43.641 ops/s (1.310x)
(ิ) ObjectMaper → JsonFactory → JsonParser ͱ͍͏ํ๏͋Δ
4. Afterburner ϞδϡʔϧΛ͏ • POJO to and from JSON ͷ
data-binding ΛߴԽ͢ ΔϞδϡʔϧ • POJO ͷੜ getter / setter ͷݺͼग़͠Λɺ ϦϑϨΫγϣϯͳ͠ʹόΠτίʔυੜͨ͠ͷͰ ࣮ݱ͢Δ • primitive ͳͷ boxing ආ͚Δ͜ͱ͕Ͱ͖Δ • طଘͷίʔυ΄ͱΜͲมߋෆཁͰಋೖָ͕
4. Afterburner ϞδϡʔϧΛ͏ 49.764 ops/s (1.140x) ͜ΕΛه
5. Streaming API Λར༻͢Δ • POJO to and from JSON
ɺͲ͏ૡ͍ͯॏ͍ ॲཧͰ͋Δ͜ͱʹมΘΒͳ͍ • POJO ͷΦϒδΣΫτੜ͠ͳ͘ͱɺ Streaming API Λ͑ JSON ύʔεͰ͖Δ • Streaming API ͰతͷॲཧΛ࣮͢Δͷେม ͕ͩɺ໘ʹ͓͍ͯҰ൪ޮՌత❗
5. Streaming API Λར༻͢Δ 77.969 ops/s (1.567x) ͜ͷ࣮ΛؤுΔ
Benchmark & result
Benchmark app https://github.com/komiya-atsushi/ java-playground/tree/master/jackson-performance
Result: table 4DPSF<PQTT> #BTFMJOF 3FVTF0CKFDU.BQQFS 6TF0CKFDU3FBEFS 0CKFDU3FBEFSSFBE7BMVFT
"GUFSCVSOFS 4USFBNJOH"1*
Result: chart 2x~ faster !
Conclusion
Conclusion • Jackson Ͱ POJO to and from JSON ͷγϦΞϥΠζɾσγϦΞ
ϥΠζΛߴʹॲཧ͍ͨ͠ͷͰ͋Ε: • Jackson ͷΦϒδΣΫτ (ObjectMapper, ObjectReader ͳͲ) ੵۃతʹ࠶ར༻͠Α͏ • ͳΔ͘ InputStream ΦϒδΣΫτΛ Jackson ʹ༩͑ΔΑ͏ ʹ͠Α͏ • Afterburner ͏͜ͱΛݕ౼͠Α͏ • ͬͱΛՔ͍͗ͨͷͰ͋ΕɺStreaming API Λར༻͠Α͏
Thank you !