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
460
[#JSUG] SmartNews における container friendly な Spring Boot アプリケーション開発
komiya_atsushi
1
11k
Java のデータ圧縮ライブラリを極める #jjug_ccc #ccc_c7
komiya_atsushi
4
4.7k
#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.3k
確率的データ構造を Java で扱いたい! #JJUG
komiya_atsushi
6
2.2k
Other Decks in Programming
See All in Programming
Go の GC の不得意な部分を克服したい
taiyow
2
760
モバイルアプリにおける自動テストの導入戦略
ostk0069
0
110
Semantic Kernelのネイティブプラグインで知識拡張をしてみる
tomokusaba
0
180
KMP와 kotlinx.rpc로 서버와 클라이언트 동기화
kwakeuijin
0
140
Fibonacci Function Gallery - Part 1
philipschwarz
PRO
0
200
Recoilを剥がしている話
kirik
5
6.6k
nekko cloudにおけるProxmox VE利用事例
irumaru
3
420
14 Years of iOS: Lessons and Key Points
seyfoyun
1
770
短期間での新規プロダクト開発における「コスパの良い」Goのテスト戦略」 / kamakura.go
n3xem
2
170
layerx_20241129.pdf
kyoheig3
2
290
テスト自動化失敗から再挑戦しチームにオーナーシップを委譲した話/STAC2024 macho
ma_cho29
1
1.3k
The Efficiency Paradox and How to Save Yourself and the World
hollycummins
1
440
Featured
See All Featured
Producing Creativity
orderedlist
PRO
341
39k
GraphQLとの向き合い方2022年版
quramy
44
13k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
32
2.7k
Building a Modern Day E-commerce SEO Strategy
aleyda
38
7k
YesSQL, Process and Tooling at Scale
rocio
169
14k
Typedesign – Prime Four
hannesfritz
40
2.4k
The Pragmatic Product Professional
lauravandoore
32
6.3k
How to train your dragon (web standard)
notwaldorf
88
5.7k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
38
1.9k
Fontdeck: Realign not Redesign
paulrobertlloyd
82
5.3k
Keith and Marios Guide to Fast Websites
keithpitt
410
22k
Done Done
chrislema
181
16k
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 !