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

privileged agent and malloc trim #2233

Closed
bungle opened this issue Oct 6, 2023 · 8 comments
Closed

privileged agent and malloc trim #2233

bungle opened this issue Oct 6, 2023 · 8 comments

Comments

@bungle
Copy link
Member

bungle commented Oct 6, 2023

@agentzh or anyone else, do you know if the privileged agent does malloc trims? I am asking this because we would like to utilise privileged agent more, but it seems to cause more memory usage (that is never or very rarely returned - not leaking, just that memory usage spikes seem to persist for a long time). And one reason could be that it does not do malloc trims?

This (https://github.com/openresty/lua-nginx-module#lua_malloc_trim) makes a lot of sense on normal request processing workers, but privileged agent doesn't process any requests (that is what lead me to ask malloc trim in specific, but it might be unrelated to it).

@zhuizhuhaomeng
Copy link
Contributor

As long as ngx_http_lua_log_handler is called, the malloc_trim will take effect.

1 similar comment
@zhuizhuhaomeng
Copy link
Contributor

As long as ngx_http_lua_log_handler is called, the malloc_trim will take effect.

@zhuizhuhaomeng
Copy link
Contributor

You can use gdb and add breakpoint on malloc_trim to see if it happends.

@bungle
Copy link
Member Author

bungle commented Oct 7, 2023

@zhuizhuhaomeng thanks, I believe that nothing except init_worker handler is called on privileged agent, so it still feels about right that some malloc trim needs to be added for privileged agent too.

I’ll investigate it a bit more.

@chobits
Copy link

chobits commented Oct 8, 2023

@zhuizhuhaomeng thanks, I believe that nothing except init_worker handler is called on privileged agent, so it still feels about right that some malloc trim needs to be added for privileged agent too.

I’ll investigate it a bit more.

Perhaps we can set up a timer to actively call malloc_trim(1) using ffi in the privileged agent. This can help us see if the memory issue is due to free memory not being released.

@oowl
Copy link
Contributor

oowl commented Oct 8, 2023

I think privileged workers can not trigger lua_malloc_trim function, even if we have the openresty timer task (fake request), it still can not be trigger. So as @chobits said, we can call malloc_trim in luajit ffi function to do this.

@bungle
Copy link
Member Author

bungle commented Oct 9, 2023

Reporting back here. We added FFI calls and tested it on Linux, but didn't find malloc_trim helping the situation. We need to do further investigation on memory usage before we can conclude anything. Thus I am closing this. Thank you!

@bungle bungle closed this as completed Oct 9, 2023
@zhuizhuhaomeng
Copy link
Contributor

@bungle OpenResty XRay can help you to identify the memory issue.
You can apply for a free trial https://xray.openresty.com.

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