Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Issue #389 : Support for MessagePack #462

Closed
wants to merge 6 commits into from

Conversation

lxhoan
Copy link
Contributor

@lxhoan lxhoan commented Jun 15, 2018

In comparison to PR #460 , this PR:

  • keep using Moshi for keep using Moshi for converting chunked response in JSON
  • keep QueryResult neutral - do not put Jackson binding annotations on it

(please refer to this comment in PR #460 for more details: #460 (comment))

@codecov-io
Copy link

codecov-io commented Jun 15, 2018

Codecov Report

Merging #462 into master will increase coverage by 0.36%.
The diff coverage is 95.34%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master     #462      +/-   ##
============================================
+ Coverage     86.63%   86.99%   +0.36%     
- Complexity      302      305       +3     
============================================
  Files            20       20              
  Lines          1294     1346      +52     
  Branches        135      139       +4     
============================================
+ Hits           1121     1171      +50     
- Misses          113      114       +1     
- Partials         60       61       +1
Impacted Files Coverage Δ Complexity Δ
src/main/java/org/influxdb/InfluxDB.java 100% <100%> (ø) 0 <0> (ø) ⬇️
src/main/java/org/influxdb/InfluxDBFactory.java 93.33% <50%> (-6.67%) 5 <0> (ø)
src/main/java/org/influxdb/impl/InfluxDBImpl.java 88.97% <96.29%> (+1.28%) 71 <3> (+3) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f9ca92f...f06dcb3. Read the comment docs.

});
messagePackFactory.setExtTypeCustomDesers(extTypeCustomDeserializers);

mapper = new ObjectMapper(messagePackFactory);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ObjectMapper are thread-safe and should be reused. I know we are not expecting to have users with 2^100 instances of this InfluxDB client but we are wasting resources here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed as comment

final ObjectReader objectReader = mapper.readerFor(javaType);
chunkProccesor = new MessagePackChunkProccesor(objectReader);
} else {
mapper = new ObjectMapper(new MappingJsonFactory());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should an ObjectMapper instance exist even if msgpack is not being used?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed as comment

ResponseBody chunkedBody = response.body();
chunkProccesor.process(chunkedBody, consumer);
} else {
//REVIEW: must be handled consistently with IOException.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I'm not wrong, IOException will be thrown by Moshi when the stream consumer arrived at the end of the stream and it's not a real error (like errorBody != null).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's actually EOFException on reaching end of stream (handled in JSONChunkProccesor.process())

* Accept MessagePack format (TRUE) or JSon (FALSE) for response from InfluxDB server
* @return a InfluxDB adapter suitable to access a InfluxDB.
*/
public static InfluxDB connect(final String url, final String username, final String password,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we think about a different approach on enabling MsgPack usage? I'm afraid we may end up by having many boolean parameters to activate/deactivate features (for example, we may add support to Protobuf).

   + reuse ObjectMapper, ObjectReader
   + Remove unused code
   + Respone format enum
Copy link
Contributor

@fmachado fmachado left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine by me (even after the last considerations from @majst01 sent by email).
Waiting for @majst01 approval...

@lxhoan
Copy link
Contributor Author

lxhoan commented Jun 22, 2018

I observed the query time reduced by ~20% for querying of 200K points and 2M points

@fmachado
Copy link
Contributor

@lxhoan Good job!

@lxhoan
Copy link
Contributor Author

lxhoan commented Jun 23, 2018

I even suppose that at server side, MessagePack serialization must be lighter than JSON serialization. So using MessagePack in query data can also reduce server side overheads

@lxhoan
Copy link
Contributor Author

lxhoan commented Jun 28, 2018

I have done a heap analysis to see if there is any memory footprint difference between JSON and MessagePack queries. The experiment over the query of 2M points
The immediate finding is that the difference in retained size of QueryResult

JSON: 1,015,736,928 bytes
MessagePack: 874,940,128 bytes

it's 13.8% better heap usage

The reason is MessagePack encode time value of the Data Point as a Long value, and it's in general use pretty less memory than the time which formatted in String value (as in JSON)

@fmachado
Copy link
Contributor

@lxhoan that's great! Could you please share with us how did you get those numbers?

@lxhoan
Copy link
Contributor Author

lxhoan commented Jun 28, 2018

I use Eclipse Memory Analyzer (https://www.eclipse.org/mat) to analyze heap dump. I am going to write a document on it. Will copy you

@lxhoan
Copy link
Contributor Author

lxhoan commented Jul 27, 2018

closed because PR #471 is the final PR

@lxhoan lxhoan closed this Jul 27, 2018
@lxhoan lxhoan deleted the features/message-pack-6 branch July 27, 2018 07:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants