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

MEMORY DOCTOR/MALLOC-STATS in loading phase #1299

Open
knggk opened this issue Nov 13, 2024 · 12 comments
Open

MEMORY DOCTOR/MALLOC-STATS in loading phase #1299

knggk opened this issue Nov 13, 2024 · 12 comments

Comments

@knggk
Copy link
Contributor

knggk commented Nov 13, 2024

The problem/use-case that the feature addresses

Sometimes I wish to investigate memory issues during the loading phase. However I get:

socket_redis> memory malloc-stats
LOADING Redis is loading the dataset in memory

Description of the feature

I would like to see the memory details provided by these commands during loading

Additional information

The check seems to be here https://github.com/valkey-io/valkey/blob/unstable/src/server.c#L4176-L4181:

    /* Loading DB? Return an error if the command has not the
     * CMD_LOADING flag. */
    if (server.loading && !server.async_loading && is_denyloading_command) {
        rejectCommand(c, shared.loadingerr);
        return C_OK;
    }

The question: Is there specific reasons those commands are disallowed during loading?

If not, is it as simple as adding CMD_LOADING flag to all the MEMORY commands, or there are considerations to take into account for making this work?

@hwware
Copy link
Member

hwware commented Nov 13, 2024

The command with flag "LOADING" indicates that this command has no any interaction with the data set.
During loading process, data is written into memory, thus memory malloc-stats and related commands are not allowed to run.

@knggk
Copy link
Contributor Author

knggk commented Nov 13, 2024

@hwware Understood about LOADING being defined as a flag for commands not interacting with the dataset.
Apart from that definition, is it not a potential valid use case to dump malloc-stats for investigation during loading?

@madolson
Copy link
Member

I think we can allow this, it shouldn't be a breaking change, @knggk do you want to open a PR? We might also want to take a look at similar commands to see which ones we should enable so we stop flipping them one at a time :)

@knggk
Copy link
Contributor Author

knggk commented Nov 15, 2024

@madolson

We might also want to take a look at similar commands to see which ones we should enable so we stop flipping them one at a time :)

Agree...I was thinking doing all memory commands.

One additional question: any pointers on how to unit test this assuming we want to?

@hpatro
Copy link
Contributor

hpatro commented Nov 15, 2024

One additional question: any pointers on how to unit test this assuming we want to?

@knggk I think it's fine to write a tcl test and slowdown the rdb loading via key-load-delay config and then perform the MEMORY * command operation.

@knggk
Copy link
Contributor Author

knggk commented Nov 15, 2024

I will look into TCL + key-load-delay. Thanks @hpatro!

@knggk
Copy link
Contributor Author

knggk commented Nov 18, 2024

I've moved all memory commands to be allowed during loading EXCEPT for memory usage key, because that one works on key and was always returning empty on any key during loading. It's also directly interacting with the dataset, which we want to disallow during loading as per @hwware.

Let me know your thoughts on the PR.

@hwware
Copy link
Member

hwware commented Nov 19, 2024

Honestly said, I have a little bit concern to allow run command "memory stats" during loading, because it costs a lot of resources and involves key issues. (key count, key used memory). Can we just allow the other 3 commands to be called during loading process?

@knggk
Copy link
Contributor Author

knggk commented Nov 19, 2024

Honestly said, I have a little bit concern to allow run command "memory stats" during loading, because it costs a lot of resources and involves key issues. (key count, key used memory). Can we just allow the other 3 commands to be called during loading process?

Ok, I do see

keys.count: The total number of keys stored across all databases in the server
keys.bytes-per-key: The ratio between dataset.bytes and keys.count

as part of the memory stats doc. (I don't know that it costs a lot of resources though.)

I can remove memory stats from the commands allowed during loading.

That would leave us with memory doctor, memory malloc-stats, memory purge now being allowed during loading.

Thoughts @hpatro @madolson?

@madolson
Copy link
Member

I would also remove memory doctor. I think it might give weird results when run during loading. The other two seem fine to me.

@knggk
Copy link
Contributor Author

knggk commented Nov 23, 2024

Ok that makes sense. I will update the PR keeping only memory malloc-stats and memory purge, and updating the TCL. Thank you @hwware @hpatro and @madolson for the feedback.

@knggk
Copy link
Contributor Author

knggk commented Nov 27, 2024

I've made the requested changes to the PR as per the feedback.

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

No branches or pull requests

4 participants