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

[cache] Switch from memcache to redis to get rid of memjs. #928

Merged
merged 2 commits into from
Feb 15, 2018

Conversation

alloy
Copy link
Contributor

@alloy alloy commented Feb 15, 2018

Closes #869.

This switches us back to Redis to fix the issue of the memos client getting into a state where it can’t reconnect to the service anymore. Hopefully this also reduces some back pressure during high load times, but at the very least remove noise that makes it harder to diagnose performance issues.

Of the various available Heroku addons I for now chose openredis, as they are the cheapest and I think we already use that in other apps (?).

We currently pay $300/5GB for memcache, the available options with openredis are $200/3.4GB or $400/5.6GB. I guess we’ll have to shell out the extra $100 to get at a minimum the same amount we have now?

Unfortunately openredis does not have a free option that we could use in staging, the smallest is $8. Would you rather have we pay a little to use the same service-provider in staging or use one of the other redis addons that provide a free option?

@orta
Copy link
Contributor

orta commented Feb 15, 2018

Personally, I'd rather pay the 8 dollars for consistency


return client.set(
key,
JSON.stringify(data),
{ expires: CACHE_LIFETIME_IN_SECONDS },
"EX",
CACHE_LIFETIME_IN_SECONDS,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 just double-checked this interface, looks good.

const client = redis.createClient({
host: redisURL.hostname,
port: redisURL.port,
retryStrategy: options => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in the docs this is snake case, retry_strategy.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good reviewing! 🕵️ At the bottom of https://github.com/NodeRedis/node_redis#usage-example they mention that all APIs/options can be either snake or camel case, so I went with camel because that‘s what we’ve been settling on for JS syntax style.

return undefined
}
// Reconnect after:
return Math.min(options.attempt * 100, 3000)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this min seems redundant since we break at > 10 attempts, so the first arg will never reach over 1000. but it does allow us to vary the max attempt count without worrying i guess.

}
// End reconnecting after a specific timeout and flush all commands with a
// individual error.
if (options.total_retry_time > 1000 * 60 * 60) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this total retry time seems high... just to clarify the logic here - we're happy to stay in a reconnecting state for up to an hour, but every 10 attempts we flush the command buffer with errors (by returning undefined below)?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also unclear on this. In the constructor, I would opt to fail hard and bail out on the process if we can't establish a connection.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct. I’m open to suggestions for a better time, this is just the suggested default value from their README.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@izakp This is not just for the initial connection but for any situation where the connection was lost.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Defaults seem like a good place to start to me (but I was also surprised about the hour).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 yeah i'm ok with this, perhaps a little complex for a default strategy. It would be nice to not terminate the process just because the cache is missing (one should be able to run an app slowly without caches). But that is perhaps an idealised view of caching ;)

Copy link
Contributor

@cavvia cavvia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just have a couple of clarificatory questions - otherwise looks good.

@alloy
Copy link
Contributor Author

alloy commented Feb 15, 2018

@cavvia Good questions regarding the retry strategy. I should have noted that I simply copied the suggested defaults over, which appears to be the way to do things nowadays with this client. None of the values are written in stone, so if y’all have suggestions for improvements then that’s a-ok with me 👍

@alloy alloy requested a review from izakp February 15, 2018 13:19
}
// End reconnecting after a specific timeout and flush all commands with a
// individual error.
if (options.total_retry_time > 1000 * 60 * 60) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also unclear on this. In the constructor, I would opt to fail hard and bail out on the process if we can't establish a connection.

@joeyAghion
Copy link
Contributor

Add-ons are highway robbery!

But yeah, seems like a small openredis add-on makes sense for staging. Feel free to merge when this is set up in staging/prod!

@alloy alloy merged commit 96e5f95 into master Feb 15, 2018
@alloy alloy deleted the switch-to-redis branch February 15, 2018 14:26
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

Successfully merging this pull request may close these issues.

Memcache issues on production
5 participants