skycoin / skywire

Skywire Node implementation
73 stars 45 forks source link

Address rate limiting of queries to SD, UT, etc. via response caching #1713

Closed 0pcom closed 4 months ago

0pcom commented 6 months ago

Rate Limiting of Queries to SD, UT, etc.

if one does several queries via skywire-cli to service discovery or uptime tracker (or any http endpoint of any service) in short succession, it's likely that a rate-limit will be hit.

One thing we could do is to remove the rate limit for queries that come from visors

i.e. if skywire-cli proxy list or skywire-cli ut makes an rpc call to the running visor, and the visor queries SD or UT then don't rate limit the request.

However; the rate limit may not be directly configured in the SD, UT, etc. currently. it may be part of the load balancing setup or otherwise not directly configured.

Cached Responses

Another alternative would be to cache responses to such queries for a period of time, in such a way that subsequent queries will fall back on the cached response until the rate-limit is no longer expected to be encountered.

The visor may need to handle this, as it's running as a daemon.

But if the cli is used apart from a running visor, there would be no way to clean up any cached file which was created except for it to be manually removed.

The dataset in question is so small that i doubt it should cause any concern to leave files in the userspace.

Perhaps a better alternative, a temporary file may be written by the cli to /tmp and it will be removed on the next boot automatically.

Perhaps it's best to implement this as a flag which specifies to --cache the response, and the duration or age of the cache to be used, in minutes. Default to the query interval of the visor to the uptime tracker (5 minutes)

Note: this behavior should not be the default behavior.

Overview of Proposed Behavior

$ skywire-cli proxy list -c US --cache 5

Then, on any subsequent query:

$ skywire-cli proxy list -c US --cache 5

Custom SD / UT address or file

Then the user can manage keeping those files synced on their own, if desired.

Related issues

https://github.com/skycoin/skywire/issues/1681

0pcom commented 4 months ago

this was implemented and works well.