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

Short-term memory #103

Closed
wants to merge 0 commits into from
Closed

Short-term memory #103

wants to merge 0 commits into from

Conversation

wfrank2509
Copy link

@wfrank2509 wfrank2509 commented Aug 15, 2017

We experienced a high load on the redis cache overloading the sockets for redis. As we have very highly frequented data a short-term cache that prevents every cache hit to go to redis helped a lot to get the load from the network.

The caching time for short term should of course be very moderate and shorter than the 'general' set caching time.

@kwhitley
Copy link
Owner

Interesting point @wfrank2509 - I'm going to wait until after the pending minor release to merge this. I'm also adding user-defined cache stages to to the feature list for the upcoming v1.0.0, inspired by this. Definitely makes sense to leverage the power of ST memory in front of the persistence of a LT redis store.

Also, thanks for the clean PR, docs update, etc! 👍

@kwhitley
Copy link
Owner

EDIT: Actually I'll try to roll this into the v0.9.0 release rather than have it cause a double bump to 0.10.0. We're simply waiting on restify to publish @svozza's merged PR. Shouldn't be more than a few days.

@kwhitley
Copy link
Owner

Fair warning, there are some merge conflicts you'll need to fix once the merge takes place... you can jump start the process by merging in #97 and fixing locally...

@wfrank2509
Copy link
Author

Ok, thanks.
I'll prepare everything for a smooth merge with #97 then.

@kwhitley
Copy link
Owner

Just check against master now @wfrank2509 - v0.9.0 is out of the gate!

@coveralls
Copy link

coveralls commented Aug 17, 2017

Coverage Status

Coverage decreased (-2.5%) to 93.902% when pulling 2907567 on wfrank2509:master into 4ae232b on kwhitley:master.

@coveralls
Copy link

coveralls commented Aug 17, 2017

Coverage Status

Coverage decreased (-2.1%) to 94.309% when pulling de75b41 on wfrank2509:master into 4ae232b on kwhitley:master.

@wfrank2509
Copy link
Author

wfrank2509 commented Aug 17, 2017

The redis related tests don't seem to run in travis CI. The getting redis cache hits code is not executed.
On my local test with redis I checked that all code was executed.

Can you help here?

@kwhitley
Copy link
Owner

@wfrank2509 - mind getting the merge conflicts resolved and test coverage implemented?

This is a feature I'm considering for v1.x

@coveralls
Copy link

coveralls commented Aug 23, 2017

Coverage Status

Coverage decreased (-2.1%) to 94.309% when pulling 473c7b6 on wfrank2509:master into 4652b5f on kwhitley:master.

@wfrank2509
Copy link
Author

wfrank2509 commented Aug 23, 2017

@kwhitley Not sure how I can activate the redis tests for travis-ci and coveralls? It looks like the missing coverage is caused by the redis tests not running? How do you test the redis scenarios? With a mock for RedisClient? The coverage report shows the whole code path with the reds config is not executed.

Somehow the

'var redis = require('fakeredis')'
and
var app = mockAPI.create('10 seconds', { redisClient: db, shortTermMemory: '20 ms', debug: true })

setting for mockAPI in the test does not set redis ?

@coveralls
Copy link

coveralls commented Aug 24, 2017

Coverage Status

Coverage decreased (-2.1%) to 94.4% when pulling 6202eba on wfrank2509:master into a74f3ce on kwhitley:master.

@kwhitley
Copy link
Owner

@wfrank2509 There's a fake redis server for use in the tests as you've found. According to the TravisCI report, your code hasn't broken any of the existing tests, so now it's a case of covering the new code. I'll download your PR today and take a look, time willing! (I need to clean up some of the options tests in the main branch anyway)

@kwhitley
Copy link
Owner

Ahhh... you must have forked from a point before we fixed the restify branch - I notice 2 of the 4 environment emulations are commented out, showing a max of 84 tests (we are currently at around 136) run.

@kwhitley
Copy link
Owner

Also, instead of implementing your own shortTerm cache Set, why not use the built-in memCache object (see memory-cache.js for API) for your short term cache? It handles things like timeouts, self-clearing, etc. If using redis, it would otherwise be ignored, but it's sitting there in the apicache instance... so may as well use that rather than add more code.

Either way, I'm planning on doing exactly that in v1.x based on your suggestion - use the internal memory cache as a short term buffer when using redis to alleviate the pressure (and speed up the responses). I love your concept, and seeing the slow speed of redis requests compared to the <1ms responses from the memory cache, it should definitely improve production environments.

👍

@wfrank2509
Copy link
Author

Makes total sense!

I would have done it that way but didn’t know the code good enough ;)

@wfrank2509 wfrank2509 closed this Oct 14, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants