Work around clients hammering FindLicense requests
I've written Load repo License in the background (gitlab#378902) on how GitLab rails should be nicer at not hammering Gitaly with a large number of FindLicense
requests.
This is the better solution to the problem, but we might need to work around this in the short term.
Proposal
We could cache the results of the FindLicense
request in a file something like info/license-info.json
. When the file exists we return the values from that file instead of computing it.
Question: Do we need to take extra care make info/license-info.json
work with Gitaly Cluster?
First call
Because the LICENSE
button is shown on the project page, a slow response on the FindLicense
RPC isn't be great. We should aim for it to always be fast. Therefore I suggest we return undefined
(or something like that) if no license-info.json
exists. We can kick of the license computation, but we should not wait for it's response.
Invalidation
This file will have all the license details and the blob OID of the license_path
. Each request we'll read that file, check the current blob ID of that license path and if they are the same we'll return the stored values in the json. Otherwise we'll kick of a new computation of the license, while we return the cached value to the caller. We accept a little outdated data here.
Concurrent calls
Because different clients can call FindLicense
concurrently. To avoid each of them to go compute the license on their own, we can use the internal/safe
to make sure only one is able to do the license computation. If a call comes in while the file is locked we can read it, and return the license info, even though it might contain stale info. If there wasn't a cached info/license-info.json
file we'll return undefined
.