Performance test application for db to json conversion.
- Directly convert data array to json using object mapper
13ms. - Use jackson stream. Add trades using
objectMapper.writeValue. Use in-memory buffer before writing into the file
13ms. - Use jackson stream. Add trades using
objectMapper.writeValue. Write directly into file stream
12ms.
So there is no significant advantage over tested methods.
Test results for loading 10000 trades from db and converting into json
- Load trades into a list from repository.
Converting to json directly from the list.
59ms. - Load trades into a list from repository.
Use jackson stream.
Add trades using
objectMapper.writeValue.
55ms. - Load trades using a jdbc connection.
Use jackson stream.
Add trades using
objectMapper.writeValue, while iterating result set.
31ms. - Load trades using hibernate stream.
Use jackson stream.
Add trades using
objectMapper.writeValue, while iterating result set.
60ms. - Load trades using a jdbc connection.
Use jackson stream.
Add trades using jackson stream api, while iterating result set.
28ms.
- Using jackson stream api has minor advantage for serialization
- Using jdbc connection provides 2x gain over using hibernate. When iterating over jdbc result set, java object(trades) creation is minimum, causing less pressure on garbage collector.
If jackson stream is directly writing to file stream make sure to disable FLUSH_AFTER_WRITE_VALUE, otherwise flush will be called for every write value causing significant performance degradation.
- Spring boot - 2.3.1
- fasterxml.jackson - 2.11.0
- PostgreSQL 12.2, compiled by Visual C++ build 1914, 64-bit
- Windows 10
- Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
- RAM 16.0 GB