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
450
[#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.2k
確率的データ構造を Java で扱いたい! #JJUG
komiya_atsushi
6
2.2k
Other Decks in Programming
See All in Programming
Creating a Free Video Ad Network on the Edge
mizoguchicoji
0
120
OnlineTestConf: Test Automation Friend or Foe
maaretp
0
110
CSC509 Lecture 12
javiergs
PRO
0
160
Amazon Qを使ってIaCを触ろう!
maruto
0
400
「今のプロジェクトいろいろ大変なんですよ、app/services とかもあって……」/After Kaigi on Rails 2024 LT Night
junk0612
5
2.1k
PHP でアセンブリ言語のように書く技術
memory1994
PRO
1
170
Enabling DevOps and Team Topologies Through Architecture: Architecting for Fast Flow
cer
PRO
0
320
役立つログに取り組もう
irof
28
9.6k
Quine, Polyglot, 良いコード
qnighy
4
640
Streams APIとTCPフロー制御 / Web Streams API and TCP flow control
tasshi
2
350
色々なIaCツールを実際に触って比較してみる
iriikeita
0
330
What’s New in Compose Multiplatform - A Live Tour (droidcon London 2024)
zsmb
1
470
Featured
See All Featured
How To Stay Up To Date on Web Technology
chriscoyier
788
250k
Fontdeck: Realign not Redesign
paulrobertlloyd
82
5.2k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
We Have a Design System, Now What?
morganepeng
50
7.2k
Why You Should Never Use an ORM
jnunemaker
PRO
54
9.1k
Building Your Own Lightsaber
phodgson
103
6.1k
Practical Orchestrator
shlominoach
186
10k
Adopting Sorbet at Scale
ufuk
73
9.1k
Become a Pro
speakerdeck
PRO
25
5k
Designing for humans not robots
tammielis
250
25k
What’s in a name? Adding method to the madness
productmarketing
PRO
22
3.1k
Raft: Consensus for Rubyists
vanstee
136
6.6k
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 !