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

Can 'node-cache' block node event loop? #215

Open
sunhyun opened this issue Nov 2, 2020 · 7 comments · May be fixed by #216
Open

Can 'node-cache' block node event loop? #215

sunhyun opened this issue Nov 2, 2020 · 7 comments · May be fixed by #216
Labels

Comments

@sunhyun
Copy link

sunhyun commented Nov 2, 2020

In our project, we use node-cache as a cache layer.
We found an issue which looks like a API performance issue.
Our API responds status code '499' (client connection close, cause by our API response time is over client's limit), every 5minutes.
When we were looking for the reason, we found that we set node-cache TTL as 5minutes.
If node-cache block node's event loop when flush data, node server can't respond to API request during that time.
We are wondering if 'node-cache' block node event loop or not.

Thank you

image

@simllll
Copy link

simllll commented Nov 2, 2020

Looking into similiar issues on our end right now. If you find something, let me know please!

simllll added a commit to simllll/node-cache that referenced this issue Nov 2, 2020
potenitally fixes node-cache#215, needs more testing though

note: I have no idea of coffeescript, is my fix syntacitally correct?
@simllll simllll linked a pull request Nov 2, 2020 that will close this issue
@simllll
Copy link

simllll commented Nov 5, 2020

image
this looks quite crazy, I will do some more tests tomorrow to see if it is really related to the cleanup method in node-cache.

@sunhyun
Copy link
Author

sunhyun commented Nov 6, 2020

@simllll , Did you set TTL as 1min?

@simllll
Copy link

simllll commented Nov 7, 2020

TTL was different, but checkperiod was set to 60. I tried now setting it to 0 (to disable the check), but turned out it didn't make any difference. Therefore I assume this is not the real issue here.

Can you try setting checkperiod to 0 on your side to see if it changes something?

Simon

@stale
Copy link

stale bot commented Jan 6, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@patrick-mcdougle
Copy link

One possible optimization would be to dereference all the expired keys in one statement vs while looping over them. By keeping a reference to all the to-be-evicted-soon objects in one place until we're about to be done with the check and dereferencing them en masse would mean that we trigger one GC vs a dice roll on each dereference on each iteration of the loop.

REF: https://stackoverflow.com/a/52745907/968201

@patrick-mcdougle
Copy link

The API of check could change. Right now check actually does the delete. Instead it could return a boolean of if the key should be evicted. Then we could collect an array of keys to evict in checkData. After looping we could do one call to del with all the keys to be evicted. We might also want to change the the del code to keep one final reference from key -> oldVal. Which will dereference when the function returns triggering 1 GC (if the engine wants to run it)

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

Successfully merging a pull request may close this issue.

4 participants