Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
move clientCron onto a separate timer #1387
base: unstable
Are you sure you want to change the base?
move clientCron onto a separate timer #1387
Changes from 8 commits
51db017
cb816fb
ea6499b
eaea2b9
82b1d18
0264c99
172d46c
755e7ec
dfe8f17
1296a20
d25dc5e
0fd1b30
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's better to align the name with
MAX_CLIENTS_PER_CLOCK_TICK
and put it toserver.h
together, we have the chance nowThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
server.h
is a big dumping ground - and included almost everywhere. I don't see a good reason to move an existing define which is already localized and move it into a global namespace.Note: I wanted to leave as much code untouched as possible (including this define). If that isn't a goal, I'd prefer making this a local
const
inside the function rather than moving the existing define to a more global namespace.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we wanna minimize the scope, we can put
MAX_CLIENTS_PER_CLOCK_TICK
here and changeCLIENTS_CRON_MIN_ITERATIONS
toMIN_CLIENTS_PER_CLOCK_TICK
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should also count the time into
server.el_cron_duration
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently
server.el_cron_duration
is set to the duration of the most recentserverCron
. It's not cumulative or additive. Then, inbeforeSleep()
, we add (locals)duration_before_aof
&duration_after_write
and record the sum withdurationAddSample
which both accumulates a total duration AND increments a counter of samples taken.I think you are suggesting that inside
serverCron
we should alter the existing code to doserver.el_cron_duration += ...
and also incrementserver.el_cron_duration
in this function also.If we do this, it will affect the samples taken counter as we will get samples for both
serverCron
and theclientTimeProc
. Usually, these won't happen in the same event loop cycle, but at times they might align.Thoughts?
As a side note, I notice that
server.el_cron_duration
is defined asmonotime
. That is not the intended usage for the type.monotime
is intended as a timestamp (a point in time). Durations should not bemonotime
as they are not timestamps. This is shown inmonotonic.h
in that all of the duration functions returnuint64_t
, notmonotime
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
serverCron
we getserver.el_cron_duration += serverCron
clientsCron
we getserver.el_cron_duration += clientsCron
beforeSleep
we getserver.el_cron_duration += duration_before_aof + duration_after_write
and usedurationAddSample
to accumulate the total duration, and resetserver.el_cron_duration
to0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i'd love to reuse the
clientsCron
, just likeserverCron
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I intentionally didn't use "cron" because the name is ambiguous. This function IS a time proc as defined by AE.
Naming is consistent with the defrag time proc (
activeDefragTimeProc
)We have other functions called "cron" that are simply functions called by a timer proc. Like
replicationCron()
,databasesCron()
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not a native English speaker : ), what is the specific difference between cron and timeproc? I'm more accustomed to cron, and the statistics related to its timing are also el_cron_duration.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you look at
ae.h
, the callback is defined asaeTimeProc
here: https://github.com/valkey-io/valkey/blob/unstable/src/ae.h#L70"cron" seems to be used for anything that's invoked at some interval. This function is specifically an
aeTimeProc
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know
ae.h
, but the underlying logic doesn't necessarily need to be passed through to the upper layers. Logically speaking, cron is also suitable and easy to understand.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think it's better to show
clients_hz
here, since it is out of the hz controlThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure what you're asking/suggesting here. I don't think we can just change the definition of the existing metric.
I think maybe you're suggesting a new metric? Currently the required hz for the
clientsTimeProc
is computed locally to the function, in each iteration. Are you suggesting adding a new field toserver...
and adding a metric abovehz
withclients_hz
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, a new metric, since the
clients_hz
can be changed and affect the poll_wait's sleep time, this will further affect the CPU usage