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

request: Expect monitoring metrics to add monitoring of nginx shared memory usage #5837

Closed
chanjet1213 opened this issue Dec 17, 2021 · 12 comments · Fixed by #7412
Closed

request: Expect monitoring metrics to add monitoring of nginx shared memory usage #5837

chanjet1213 opened this issue Dec 17, 2021 · 12 comments · Fixed by #7412
Labels
discuss For student This issue is reserved for the students in open source sponsor projects good first issue Good for newcomers

Comments

@chanjet1213
Copy link

Issue description

期待监控指标添加对nginx共享内存使用情况的监控

Environment

  • apisix version (cmd: apisix version):
  • OS (cmd: uname -a):
  • OpenResty / Nginx version (cmd: nginx -V or openresty -V):
  • etcd version, if have (cmd: run curl http://127.0.0.1:9090/v1/server_info to get the info from server-info API):
  • apisix-dashboard version, if have:
  • the plugin runner version, if the issue is about a plugin runner (cmd: depended on the kind of runner):
  • luarocks version, if the issue is about installation (cmd: luarocks --version):
@juzhiyuan juzhiyuan changed the title 期待监控指标添加对nginx共享内存使用情况的监控 request: Expect monitoring metrics to add monitoring of nginx shared memory usage Dec 17, 2021
@tzssangglass
Copy link
Member

It seems to be quite difficult, and if you use the ngx.shared.DICT API to monitor it, it will lose performance.

refer to: https://github.com/openresty/lua-nginx-module#ngxshareddictcapacity

@kwanhur
Copy link
Contributor

kwanhur commented Mar 26, 2022

Is it like ngx_slab_stats? Which supports shared memory allocated from lua-nginx-module.

@tzssangglass
Copy link
Member

I changed my mind and I think it's a meaningful enhancemen.

Perhaps we can first monitor the nginx.shared.DICT that is used by APISIX, and next we allow users to monitor a custom nginx.shared.DICT (or read the used nginx.shared.DICT directly from the configuration file).

cc @spacewander

@spacewander spacewander added the good first issue Good for newcomers label Mar 27, 2022
@tokers
Copy link
Contributor

tokers commented Mar 28, 2022

I changed my mind and I think it's a meaningful enhancemen.

Perhaps we can first monitor the nginx.shared.DICT that is used by APISIX, and next we allow users to monitor a custom nginx.shared.DICT (or read the used nginx.shared.DICT directly from the configuration file).

cc @spacewander

@tzssangglass Could you share your proposal?

@tzssangglass
Copy link
Member

tzssangglass commented Mar 28, 2022

@tzssangglass Could you share your proposal?

we can use ngx.shared.DICT.capacity and ngx.shared.DICT.free_space to monitor a ngx.shared.DICT?

@tokers
Copy link
Contributor

tokers commented Mar 28, 2022

@tzssangglass Could you share your proposal?

we can use ngx.shared.DICT.capacity and ngx.shared.DICT.free_space to monitor a ngx.shared.DICT?

OK so we may get a curve about the shared dict, in the diagram we can see the shared dict memory usage.

@spacewander spacewander added the For student This issue is reserved for the students in open source sponsor projects label May 9, 2022
@ccxhwmy
Copy link
Contributor

ccxhwmy commented Jul 3, 2022

@tzssangglass Could you share your proposal?

we can use ngx.shared.DICT.capacity and ngx.shared.DICT.free_space to monitor a ngx.shared.DICT?

I found that nginx adopts a way of pre-allocating memory for shared DICT, the smallest granularity is page, ranther than allocat per use. The value of ngx.shared.DICT.capacity is accurate, but ngx.shared.DICT.free_space is the value left after the acquired pre-allocated memory, so there is a certain inconsistency in fine-grained ngx.shared.DICT.free_space accurate.

@tzssangglass
Copy link
Member

I found that nginx adopts a way of pre-allocating memory for shared DICT, the smallest granularity is page, ranther than allocat per use. The value of ngx.shared.DICT.capacity is accurate, but ngx.shared.DICT.free_space is the value left after the acquired pre-allocated memory, so there is a certain inconsistency in fine-grained ngx.shared.DICT.free_space accurate.

Is there some docs or code that explain this? This is useful info.

@ccxhwmy
Copy link
Contributor

ccxhwmy commented Jul 4, 2022

I found that nginx adopts a way of pre-allocating memory for shared DICT, the smallest granularity is page, ranther than allocat per use. The value of ngx.shared.DICT.capacity is accurate, but ngx.shared.DICT.free_space is the value left after the acquired pre-allocated memory, so there is a certain inconsistency in fine-grained ngx.shared.DICT.free_space accurate.

Is there some docs or code that explain this? This is useful info.

I checked the C code of ngx.shared.DICT, the ffi call function of free_space is ngx_http_lua_ffi_shdict_free_space, and the caluculation method is bytes = ctx->shpool->pfree * ngx_pagesize;. The ffi calling process of set is ngx_http_lua_ffi_shdict_store->ngx_slab_alloc_locked->ngx_slab_alloc_pages, it will judge whether the memory previously malloc is enough, if it is enough, it will not malloc memory. pfree will only be modified when entering ngx_slab_alloc_pages to malloc memory.

@tzssangglass
Copy link
Member

Hi @ccxhwmy , would you like to work on this?

@ccxhwmy
Copy link
Contributor

ccxhwmy commented Jul 4, 2022

Hi @ccxhwmy , would you like to work on this?

Can you tell me which plugin I can modify to get information of ngx.shared.DICT regularly and report it? prometheus?

@tzssangglass
Copy link
Member

Can you tell me which plugin I can modify to get information of ngx.shared.DICT regularly and report it? prometheus?

yes, prometheus.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discuss For student This issue is reserved for the students in open source sponsor projects good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants