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

[all] Refactor time.Time to xtime.UnixNano #3515

Merged
merged 59 commits into from
Jun 8, 2021
Merged

Conversation

arnikola
Copy link
Collaborator

What this PR does / why we need it:

This PR refactors the usages of time.Time to xtime.UnixNano along the
critical read path primarily, to reduce overhead from constant conversions
to/from time.Times.

Benchmarks show this is around a 13% improvement.

On real-data benchmarks running read_data_files:

With optimization:

Running time: 283.808698ms
35238 series read
(124161.10 series/second)
2535668 datapoints decoded
(8934426.67 datapoints/second)

Without optimization:

35238 series read
(109477.95 series/second)

2535668 datapoints decoded
(7877851.54 datapoints/second)

Special notes for your reviewer:
The most dangerous part of this conversion is in RPC conversions to ensure we maintain back/forward compat; be extra-critical around these areas

Still TODO: update test files, get them running

Does this PR introduce a user-facing and/or backwards incompatible change?:
If all the RPC conversions have been updated correctly, this should not be an issue. Any third party libraries may need updates, however.

arnikola and others added 30 commits May 24, 2021 12:19
This PR refactors the usages of `time.Time` to `xtime.UnixNano` along the
critical read path primarily, to reduce overhead from constant conversions
to/from time.Times.

Benchmarks show this is around a 13% improvement.

On real-data benchmarks running `read_data_files`:

With optimization:
```
Running time: 283.808698ms
35238 series read
(124161.10 series/second)
2535668 datapoints decoded
(8934426.67 datapoints/second)
```

Without optimization:
```
35238 series read
(109477.95 series/second)

2535668 datapoints decoded
(7877851.54 datapoints/second)
```

Still TODO: update test files, get them running
@codecov
Copy link

codecov bot commented May 31, 2021

Codecov Report

Merging #3515 (ac7b90d) into master (ac7b90d) will not change coverage.
The diff coverage is n/a.

❗ Current head ac7b90d differs from pull request most recent head 37abbcf. Consider uploading reports for the commit 37abbcf to get more accurate results

Impacted file tree graph

@@          Coverage Diff           @@
##           master   #3515   +/-   ##
======================================
  Coverage    57.6%   57.6%           
======================================
  Files         549     549           
  Lines       67420   67420           
======================================
  Hits        38897   38897           
  Misses      25133   25133           
  Partials     3390    3390           
Flag Coverage Δ
aggregator 57.1% <0.0%> (ø)
cluster ∅ <0.0%> (∅)
collector 54.3% <0.0%> (ø)
dbnode 62.2% <0.0%> (ø)
m3em 46.4% <0.0%> (ø)
metrics 19.8% <0.0%> (ø)
msg 74.4% <0.0%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.


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 ac7b90d...37abbcf. Read the comment docs.

@@ -962,7 +967,7 @@ func (req *retrieveRequest) Clone(
}

func (req *retrieveRequest) Start() time.Time {
return req.start
return req.start.ToTime()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe change to return UnixNano

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Looks like this func is unused, removing it

@@ -475,13 +486,13 @@ func (dbb *databaseSeriesBlocks) Len() int {

func (dbb *databaseSeriesBlocks) AddBlock(block DatabaseBlock) {
start := block.StartTime()
if dbb.min.Equal(timeZero) || start.Before(dbb.min) {
if dbb.min == timeZero || start < dbb.min {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe revert to the convenience methods

@@ -1007,7 +1010,7 @@ func (s *fileSystemSource) bootstrapFromIndexPersistedBlocks(
s.log.Error("unable to read segments from index fileset",
zap.Stringer("namespace", ns.ID()),
zap.Error(err),
zap.Time("blockStart", indexBlockStart),
zap.Time("blockStart", indexBlockStart.ToTime()),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's make sure we only do these conversions in error cases

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Did a sweep; these conversions happen largely in errors/invariant violation logging, but are also called as part of the trace path for some large granularity functions like top level Query calls, where the overhead will be negligible (makes some sense since we wouldn't have been logging the hotpath anyway)

@@ -107,7 +107,7 @@ func (m *coldFlushManager) Run(t time.Time) bool {
m.Unlock()
}()

m.log.Debug("starting cold flush", zap.Time("time", t))
m.log.Debug("starting cold flush", zap.Time("time", t.ToTime()))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe confirm how often this gets called

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Seems like this may call decently often, going to put this behind a flag to only log/generate these fields if we're logging at debug level

@arnikola arnikola merged commit 3995bf6 into master Jun 8, 2021
@arnikola arnikola deleted the arnikola/time-conversion branch June 8, 2021 15:54
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.

2 participants