Skip to content

Allow to use BigInteger and BigDecimal for timestamps#657

Merged
majst01 merged 4 commits intoinfluxdata:masterfrom
J0s3f:master
Feb 20, 2020
Merged

Allow to use BigInteger and BigDecimal for timestamps#657
majst01 merged 4 commits intoinfluxdata:masterfrom
J0s3f:master

Conversation

@J0s3f
Copy link
Copy Markdown
Contributor

@J0s3f J0s3f commented Feb 14, 2020

Allow to use BigInteger and BigDecimal for timestamps in the Point class to allow arbitrary timestamps with nanosecond precision.

Fixes #267

Won't break any existing code because it is still possible to use Long as timestamp.

…ass to allow arbitrary timestamps with nanosecond precision.

Fixes #267
@codecov-io
Copy link
Copy Markdown

codecov-io commented Feb 14, 2020

Codecov Report

Merging #657 into master will decrease coverage by 6.24%.
The diff coverage is 96.96%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master     #657      +/-   ##
============================================
- Coverage     88.09%   81.85%   -6.25%     
+ Complexity      718      672      -46     
============================================
  Files            69       69              
  Lines          2487     2513      +26     
  Branches        263      268       +5     
============================================
- Hits           2191     2057     -134     
- Misses          208      370     +162     
+ Partials         88       86       -2
Impacted Files Coverage Δ Complexity Δ
src/main/java/org/influxdb/dto/Point.java 93.36% <96.96%> (+0.33%) 53 <0> (+4) ⬆️
...ava/org/influxdb/msgpack/QueryResultModelPath.java 0% <0%> (-90%) 0% <0%> (-7%)
...ava/org/influxdb/msgpack/MessagePackTraverser.java 0% <0%> (-87.24%) 0% <0%> (-37%)
...uxdb/msgpack/MessagePackResponseBodyConverter.java 25% <0%> (-75%) 1% <0%> (-1%)
src/main/java/org/influxdb/impl/InfluxDBImpl.java 78.89% <0%> (-3.45%) 77% <0%> (-5%)

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 45f6cf4...9f01975. Read the comment docs.

this.time = TimeUnit.MILLISECONDS.convert(instant.toEpochMilli(), timeUint);
this.precision = timeUint;
TimeUnit timeUnit = tc.timeUnit();
if (timeUnit == TimeUnit.NANOSECONDS || timeUnit == TimeUnit.MICROSECONDS) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I would leave MILLISECONDS as the default path.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

But without this change it will never be possible to use more than millisecond precision?
The BigInteger is created only if nano- or microsecond precision is requested. The default for the annotation is still milliseconds.

if (converterPrecision == null) {
converterPrecision = TimeUnit.NANOSECONDS;
}
if (this.time instanceof BigInteger) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I am a bit afraid of the performance impact, this is in the hot path and instanceof is not known for beeing super performant. Can we prove somehow, how big the performance impact might be ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I created a benchmark to measure the impact. It can be found here: https://github.com/J0s3f/influx-point-benchmark
To run it on you own machine, simply download the jar and run it via java -jar benchmarks.jar

Here are the results on my machine: https://gist.github.com/J0s3f/6e6feb1cef2644bdb060576e99b1e91f

I'd say there is no meaningful impact of this change.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Its about 4% slower ! Given that users complain about performance already, i dont want to take extra without double check if this is not possible in another way

Copy link
Copy Markdown
Contributor Author

@J0s3f J0s3f Feb 17, 2020

Choose a reason for hiding this comment

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

If you take the numbers from my benchmark, benchmarkNewPoint is the changed code so it is 4% faster (but with bigger error margin) (more ops/s is better)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Cant image the extra code speeds up the processing ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Benchmarks are just not accurate to that level on any PC that's running a full blown desktop OS.
I can try to increase the Forks in JMH but I don't have access to a bare metal machine I can use to run that for a few hours currently :(

And I changed one if in the existing code, this might have impact on the JIT compiler optimizations.

Copy link
Copy Markdown
Contributor Author

@J0s3f J0s3f Feb 17, 2020

Choose a reason for hiding this comment

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

I made another benchmark run using the settings java -jar /benchmarks.jar -bm thrpt -f 5 -i 8 -si true -t max -wi 5 on a Quad-Core Intel Xeon VM that wasn't running anything else. (of course, I don't know what the host system was doing).

Here are the results: https://gist.github.com/J0s3f/379f9d2a1cfd6b77a5931b9422e80e42

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

* @param precisionToSet the TimeUnit
* @return the Builder instance.
*/
public Builder time(final Long timeToSet, final TimeUnit precisionToSet) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why is this needed, Long is a Number right.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes but in Java the Argument type is part of the method signature. For people always recompiling their code, it is not needed. But if someone would compile with a version without this pull request and than later just switch the dependency without recompiling, the program will fail with a NoSuchMethodError

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I'm getting slow in Java, since years i switch to go for many reasons.
Is this ready to be merged now ?

Copy link
Copy Markdown
Contributor Author

@J0s3f J0s3f Feb 20, 2020

Choose a reason for hiding this comment

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

Yes, I think it is complete. The code coverage is strange, but this must be some error. I just added this one method and suddenly some entirely different classes have zero coverage.
The coverage for my fork which is the exact same commit also shows correct coverage.

@majst01 majst01 merged commit 855708d into influxdata:master Feb 20, 2020
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.

Nanosecond value in Point time field is stored in Long?

3 participants