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 slows down for large responses #40

Closed
duprasa opened this issue Nov 30, 2020 · 4 comments
Closed

cache slows down for large responses #40

duprasa opened this issue Nov 30, 2020 · 4 comments

Comments

@duprasa
Copy link

duprasa commented Nov 30, 2020

Hi, Amazing gem, really useful and I love the api :D

I'm working on an api that sometimes returns massive amounts of data up to 27mB and the cached responses are a bit slow.

I'm guessing this has to do with parsing the cached data text to a hash/json. Do you think it's possible to speed this up at all?

the response time seems linearly correlated with response size
image

Thanks for the help!

@DmitryTsepelev
Copy link
Owner

Hi @duprasa, 27mb is a serious amount of data!

I guess you use Redis as a cache store (am I right?), so it might take some extra time for a network roundtrip. I wonder if it's possible to find out how much time is spent in parser and how long it takes to fetch a cached data (I guess we could compare how much time it takes to execute Rails.cache.fetch against redis.get).

@duprasa
Copy link
Author

duprasa commented Dec 1, 2020

Hi @DmitryTsepelev thanks for the quick reply!

Ya it's a ton of data, we are planning on breaking it up into smaller requests, but I found that it illustrated this issue well.

I'm just using the default caching mechanism and running it locally, looking at the rails logs I can see that most of the processing is done in view_runtime, so the network isn't adding much overhead.

Smaller requests are blazing fast tho and range in the 10-100ms range 👍

I'm not great at rails so I have trouble diagnosing where the issue is exactly, do you think it might be because after cache.fetch, the data needs to be parsed to json (for graphql)? Maybe we can use a faster json parsing libary, I've heard that the deafult one is pretty slow?

Thanks again!

@DmitryTsepelev
Copy link
Owner

Yeah, you could try writing a custom cache storage using a faster serialiser (example is is here, you need to implement only #read, #exists? and #write). I think oj should be faster then the default one. Before reimplementing storage, you can just compare how much time Rails.cache.read takes against oj.

@DmitryTsepelev
Copy link
Owner

I'm closing the issue for now, feel free to reopen it or open a new one if you have questions 🙂

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

No branches or pull requests

2 participants