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
Sidekiqで実現する 長時間非同期処理の中断と再開 / Pausing and Resuming Long-Running Asynchronous Jobs with Sidekiq
hypermkt
6
2.7k
リリース8年目のサービスの1800個のERBファイルをViewComponentに移行した方法とその結果
katty0324
5
3.6k
Modern Angular: Renovation for Your Applications
manfredsteyer
PRO
0
200
Vue SFCのtemplateでTypeScriptの型を活用しよう
tsukkee
3
1.5k
hotwire_or_react
harunatsujita
8
4k
WEBエンジニア向けAI活用入門
sutetotanuki
0
300
RailsのPull requestsのレビューの時に私が考えていること
yahonda
5
1.7k
Vaporモードを大規模サービスに最速導入して学びを共有する
kazukishimamoto
4
4.3k
CSC509 Lecture 08
javiergs
PRO
0
110
アジャイルを支えるテストアーキテクチャ設計/Test Architecting for Agile
goyoki
7
2.8k
外部システム連携先が10を超えるシステムでのアーキテクチャ設計・実装事例
kiwasaki
1
220
From Subtype Polymorphism To Typeclass-based Ad hoc Polymorphism- An Example
philipschwarz
PRO
0
170
Featured
See All Featured
Automating Front-end Workflow
addyosmani
1365
200k
Typedesign – Prime Four
hannesfritz
39
2.4k
Adopting Sorbet at Scale
ufuk
73
9k
RailsConf 2023
tenderlove
29
880
Learning to Love Humans: Emotional Interface Design
aarron
272
40k
A Modern Web Designer's Workflow
chriscoyier
692
190k
Building an army of robots
kneath
302
42k
Side Projects
sachag
452
42k
The MySQL Ecosystem @ GitHub 2015
samlambert
250
12k
The Invisible Side of Design
smashingmag
297
50k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
46
2.1k
The Pragmatic Product Professional
lauravandoore
31
6.3k
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 !