-
Notifications
You must be signed in to change notification settings - Fork 1
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
Handle HTTP calls asynchronously, add response caching #163
Conversation
return null | ||
} | ||
|
||
let backend = response.data.wiki_queryservice_namespace.backend |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could also cache this computation. I steered away from it as it would mean even more noise in this changeset. Any opinions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is probably the right call. IMHO if we start trying to optimise this computation we might also want to use native URL parsing etc. https://nodejs.org/api/url.html before adding the complexity of more caching.
// Try and log on failures (so this process keeps running...) | ||
try { | ||
var responseCache = new LRUCache({ | ||
ttl: parseInt(process.env.RESPONSE_CACHE_TTL || 60 * 60, 10) * 1000 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs a chart update. Any opinions on how long to cache such an item? I'd think 60 minutes is a good value to have.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR here wbstack/charts#118
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
60mins seems fine to me. These mappings are currently very stable. We have never changed them so from historical data these could be cache indefinitely but 60mins means that we shan't have to worry too much if for some reason we do change them (e.g. if in future we allow reusing domains)
Seems returning a Promise from a resolver is expected and would work just like the synchronous version before https://github.com/OptimalBits/redbird/blob/cb7781e9c471bcb497ea4af1ddabf4fdf4432caa/lib/proxy.js#L578 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good!
Ticket https://phabricator.wikimedia.org/T339906
Having asynchronous resolvers in redbird is not documented, but is done in the tests: https://github.com/OptimalBits/redbird/blob/cb7781e9c471bcb497ea4af1ddabf4fdf4432caa/test/test_custom_resolver.js#L225-L233 so I would assume this works as expected.
I tried to follow the existing behavior as closely as possible, which is why the code is still a bit quirky in places. For review, it might help to look at the commits which isolate the two changes munged together into this PR.
I was able to test these changes successfully in my local env.