Skip to content

Auto checkpoint upon exceeding memory percentage - #4378

Closed
vasslitvinov wants to merge 1 commit into
Bears-R-Us:masterfrom
vasslitvinov:auto-checkpoint-1
Closed

vasslitvinov wants to merge 1 commit into
Bears-R-Us:masterfrom
vasslitvinov:auto-checkpoint-1

Conversation

@vasslitvinov

Copy link
Copy Markdown
Contributor

Initial implementation of automatic checkpointing, performed in the server before waiting for the next zmq message from the client based on a memory percentage threshold. The threshold is controlled by a config argument of the server and is off by default. Automatic checkpointing is not done if the CheckpointMsg module was included in the build.

Minimal intelligence is included that suppresses automatic checkpointing if it has already been performed or a checkpoint has been loaded, unless memory has been below the threshold after these took place.

Essential next steps: report it to the user that the checkpointing is taking place and wait for 5 seconds (for example) idle time so that checkpointing does not occur during intermediate computations. For example, ak.ones(nnn) takes two messages and the checkpoint will currently occur between them if threshold is exceeded.

I would also like to move activityMutex to a "common header" file like MultiTypeSymbolTable so that CheckpointMsg can do locking at a finer granularity than (currently) for the entire autoCheckpointMsg().

@ajpotts ajpotts left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks OK to me. I'm interested in how you will test this out.

@e-kayrakli e-kayrakli left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nice! Thanks for the quick turnaround.

Just so that I am understanding it right, this is not about server being idle, but it is strictly about memory percentage. Is that right? I am mostly confused by the variable names. Your PR title and message are clear on that.

wait for 5 seconds (for example) idle time so that checkpointing does not occur during intermediate computations. For example, ak.ones(nnn) takes two messages and the checkpoint will currently occur between them if threshold is exceeded.

Good point. Also considering that we want to add the feature of checkpointing after N minutes of an idle server, the logic will eventually be like:

  • if memory is above threshold, set the checkpoint timeout (e.g. ZMQ recv timeout) to 5 seconds
  • otherwise, set it to 5 minutes

does that sound right?

I would also like to move activityMutex to a "common header" file like MultiTypeSymbolTable

There must be a better place to put that. Otherwise, we can create a new module.

Comment thread src/CheckpointMsg.chpl

/* Perform checkpointing automatically when used memory exceeds this many percent
of available memory. No auto-checkpointing if 0 or below. */
config const ckptMemPct = 0;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Since this is user facing, can you spell it out as at least checkpointMemPct?

Comment thread src/CheckpointMsg.chpl

proc loadCheckpointMsg(cmd: string, msgArgs: borrowed MessageArgs,
st: borrowed SymTab): MsgTuple throws {
skipAutoCkpt = true;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You mentioned this in the PR message, but I am not fully following why this skip was necessary. Is it to prevent auto-checkpoint while loading a checkpoint. I can load a checkpoint, keep doing my work, but still expect auto checkpointing to fire normally afterwards. Should we have skipAutoCkpt=false at the end of this function?

Comment thread src/CheckpointMsg.chpl

// check whether memory use exceeds ckptMemPct
if (getMemUsed():real / getMemLimit()) > ckptMemPct / 100.0 {
return if skipAutoCkpt then false else true;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Or simply return !skipAutoCkpt;

Comment thread src/CheckpointMsg.chpl
if (getMemUsed():real / getMemLimit()) > ckptMemPct / 100.0 {
return if skipAutoCkpt then false else true;
} else {
skipAutoCkpt = false;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

So, we disable skipping if we are not using a lot of memory. Why?

Comment thread src/ServerDaemon.chpl
// Do nothing if the checkpointing module was not included.
if commandMap.contains("auto_checkpoint") {
const msgArgs = new owned MessageArgs();
msgArgs.addPayload(b"idle start");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is the motivation for using a message-based approach to be able to do commandMap.contains? I am on board with it in any case. However, checkpointing is a core feature of Arkouda and we can consider making it part of the server no matter what. I can't imagine it adding a ton of compilation time.

Short of that, it would be good to wire in a mechanism so that the server can check whether a module is loaded or not without having to do this. I also wanted that feature so that when the server sees a message to be not supported, it can tell you which module it belongs to. IOW, during compilation, we would still take a look at the excluded modules just to see which messages they implement, but then not compile them. That's a bit of a tangent, though.

Comment thread src/ServerDaemon.chpl
var startTime = timeSinceEpoch().totalSeconds();

while !this.shutdownDaemon {
startIdleServer();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Did you mean to put this in a begin?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If not, the mutex is not necessary I think?

Comment thread src/CheckpointMsg.chpl
}
// when b"idle start" {
// // nothing for now
// }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

remove?

Comment thread src/ServerDaemon.chpl
proc stopIdleServer() throws {
if commandMap.contains("auto_checkpoint") {
const msgArgs = new owned MessageArgs();
msgArgs.addPayload(b"idle stop");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think this is not wired in right now. In general, it is not clear to me why this is necessary. I am probably missing something about asynchrony, begin etc.

Comment thread src/ServerDaemon.chpl
/* While waiting for a message from client, do checkpointing if desired. */
proc startIdleServer() throws {
// Do nothing if the checkpointing module was not included.
if commandMap.contains("auto_checkpoint") {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I have preference towards putting this and needMemBasedCkpt in a helper and calling that helper in the very top level while loop. Because it looks like we may end up calling a lot of functions that are no-ops. Function call is OK, but I think putting checks that may result in no-op in the top-level makes the code easier to read and maintain IMO.

@vasslitvinov

Copy link
Copy Markdown
Contributor Author

Superseded by #4391. Closing.

github-merge-queue Bot pushed a commit that referenced this pull request May 21, 2025
…le time (#4391)

Address part of #2384. Replaces #4378.

The server now automatically saves a checkpoint if memory usage exceeded
a threshold or if the server has been idle for a bit. This is disabled
by default, see below. Requires `CheckpointMsg` module. Arkouda still
builds without this module.

The following server options in `CheckpointMsg` module control the
behavior:

* `checkpointMemPct` : Perform checkpointing automatically when memory
usage exceeds this many percent of available memory. By default / if
<=0, auto-checkpointing is not triggered by memory usage.

* `checkpointMemPctDelay` : When memory exceeds the `checkpointMemPct`
threhsold, wait for this many seconds of idle time before checkpointing.
By default / if <=0, uses 5 seconds.

* `checkpointIdleTime` : Perform checkpointing automatically when the
server is idle for this many seconds. By default / if <=0,
auto-checkpointing is not triggered by idle time.

* `checkpointCheckInterval` : The auto-checkpoint implementation will
wake up every this many seconds to check if a checkpoint needs to be
saved due to memory usage or idle time. By default / if <=0, uses min(
checkpointMemPctDelay, checkpointIdleTime ).

* `checkpointInterval` : Automatic checkpointing due to memory use or
idle time will wait for at least this many seconds after any completed
checkpoint save or load operations, whether automatic or
client-initiated. By default / if <=0, uses 3600 (one hour). This avoids
overly-frequent auto-checkpointing. The server does not need not be idle
during this interval. Checkpoint operations requested by the client are
not subject to this delay.

If the server receives a message from the client while
auto-checkpointing is in progress, it locks until auto-checkpointing
completes.

This PR also introduces a framework for client testing with customer
server options and invokes it as a sibling `pytest` command in
`Makefile`. Such testing is configured using `pytest.opts.ini` and
`tests/optioned-server/conftest.py` . It is used to test the
functionality added in this PR.

While there: switch the order of error() and critical() in
`src/Logging.chpl` to match the order in the enum; an analogous change
in `src/Message.chpl`; open the file in read mode, not append, in
`io_util.delimited_file_to_dict()`; added `io_util.directory_exists()`.

Next features to implement:
* The previous checkpoint is saved until the new checkpoint has
successfully completed.
* The server informs the client that it is auto-saving a checkpoint.
* Tune the default thresholds, esp. `checkpointInterval` .
* Do not checkpoint until the first client connects to the server and
has some activity.

The module-level variable `lastCkptCompletion` in CheckpointMsg.chpl
should be specific to each `DefaultServerDaemon` instance rather than be
a global. This is OK for now that we have only a single instance.

Signed-off-by: Vassily Litvinov <[email protected]>
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