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
聞き手から登壇者へ: RubyKaigi2024 LTでの初挑戦が 教えてくれた、可能性の星
mikik0
1
130
役立つログに取り組もう
irof
28
9.6k
Amazon Bedrock Agentsを用いてアプリ開発してみた!
har1101
0
340
.NET のための通信フレームワーク MagicOnion 入門 / Introduction to MagicOnion
mayuki
1
1.7k
リアーキテクチャxDDD 1年間の取り組みと進化
hsawaji
1
220
Outline View in SwiftUI
1024jp
1
330
Hotwire or React? ~アフタートーク・本編に含めなかった話~ / Hotwire or React? after talk
harunatsujita
1
120
WebフロントエンドにおけるGraphQL(あるいはバックエンドのAPI)との向き合い方 / #241106_plk_frontend
izumin5210
4
1.4k
アジャイルを支えるテストアーキテクチャ設計/Test Architecting for Agile
goyoki
9
3.3k
Realtime API 入門
riofujimon
0
150
as(型アサーション)を書く前にできること
marokanatani
10
2.7k
ActiveSupport::Notifications supporting instrumentation of Rails apps with OpenTelemetry
ymtdzzz
1
240
Featured
See All Featured
Automating Front-end Workflow
addyosmani
1366
200k
The Power of CSS Pseudo Elements
geoffreycrofte
73
5.3k
Building an army of robots
kneath
302
43k
jQuery: Nuts, Bolts and Bling
dougneiner
61
7.5k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
356
29k
Building Flexible Design Systems
yeseniaperezcruz
327
38k
GitHub's CSS Performance
jonrohan
1030
460k
A designer walks into a library…
pauljervisheath
204
24k
Thoughts on Productivity
jonyablonski
67
4.3k
Imperfection Machines: The Place of Print at Facebook
scottboms
265
13k
Statistics for Hackers
jakevdp
796
220k
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 !