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

nsqd: ability to request stats without mem stats #1230

Closed
creker opened this issue Jan 6, 2020 · 3 comments
Closed

nsqd: ability to request stats without mem stats #1230

creker opened this issue Jan 6, 2020 · 3 comments

Comments

@creker
Copy link
Contributor

creker commented Jan 6, 2020

Right now /stats HTTP call always returns memory stats even if you don't need them. To do that it calls runtime.ReadMemStats which incurs STW on every call. Go team did make it very short but I would like to avoid it completely if I can.

The use case for us is the following. We use stats call to measure how full topics and channels are and throttle producers so that they don't keep spamming messages if consumers for some reason are slow. It could be due to consumers simply not working properly or just being overwhelmed with traffic. Our services can be quite slow as each NSQ message is a task that requires heavy computations. We request stats every 30 seconds. This seems not too much but this is done in every service (we built our own custom NSQ client library that does this) of which there're 10s and 100s of instances. Naturally, even with 30 seconds interval NSQ nodes would be constantly blasted with these requests.

I looked at the code and see that there's already some GET parameters like include_clients that you can use to filter out unneeded information. I propose to add another one include_mem that would allow one to avoid calling getMemStats (which, in turn, calls runtime.ReadMemStats) completely. I'm willing to send pull request if this gets accepted.

@jehiah jehiah added the perf label Jan 6, 2020
@jehiah
Copy link
Member

jehiah commented Jan 6, 2020

@creker this sounds reasonable as long as include_mem defaults to a backwards compatible value.

@creker
Copy link
Contributor Author

creker commented Jan 6, 2020

@jehiah of course. By default it would return everything. Only when include_mem=0 would it exclude the information.

One question remains, how should the response look like if include_mem=0? Should memory field in JSON and Memory: in text formats be completely removed or just return zeroes for all mem stats? Personally have no real preference. The latter could be done in just a few lines.

@ploxiln
Copy link
Member

ploxiln commented Jan 12, 2020

closing in favor of #1232

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants