Skip to content

Quota Update

Chlins Zhang edited this page Jul 10, 2023 · 8 revisions

Background

Harbor provides the function of quota management, you can configure different quotas for each project to limit the occupation of space for each project, but in the scenario of high concurrent push to the same project, because the update is the same quota_usage record in the db, so it will cause a lot of optimistic locking, which will cause the db connection number spike and a lot of occupation.

Solution

In the v2.9, harbor introduces the quota update by redis to resolve the issue. The basic idea is to shift the implementation of optimistic locking mechanism from the database (Postgres) to utilizing the Watch mechanism in Redis. This change makes the updating of quota usage asynchronous, resulting in improved throughput and reduced database connections. However, the downside is that the displayed project quota usage in the UI may experience some delay and won't be updated in real-time. Nevertheless, the delay will be kept within a few minutes.

USAGE

Apply the environment variable QUOTA_UPDATE_PROVIDER to the following options, or not set for default behavior(update quota by DB).

  • QUOTA_UPDATE_PROVIDER="redis"
  • QUOTA_UPDATE_PROVIDER="db" (by default)

NOTICE

If you have multiple core instances, please make sure the configuration is consistent, both use DB to update quota or both use Redis to update, otherwise, it may result in inconsistent data, leading to incorrect quota usage.

Comparison

Benchmark scenario is pushing a total of 5000 artifacts to the same project at 500 concurrence. (Harbor deployed by docker-compose in 16 CPU cores and 16G MEM VM)

script reference: https://github.com/goharbor/perf/blob/main/scripts/test/push-artifacts-to-same-project.js

DB connections

update quota by DB iShot_2023-06-29_17 34 52

update quota by Redis iShot_2023-06-30_10 43 11

The average db connections was less than 25 after updating quota via Redis. This is a very important enhancement, as long periods of high db connection usage may cause other requests from harbor to become unavailable.

Core resource usage

update quota by DB iShot_2023-06-29_17 33 34

update quota by Redis iShot_2023-06-29_17 25 14

Switching to Redis and seeing a several-fold increase in CPU usage for core is reasonable. This is because the throughput has increased, resulting in handling more requests per second, which in turn consumes more resources for token parsing. It does not incur any additional costs.

DB resource usage

update quota by DB iShot_2023-06-29_17 33 51

update quota by Redis iShot_2023-06-30_10 42 37

The resources occupied by DB do not show significant differences, but the overall time consumption is reduced after using Redis.

Redis resource usage

update quota by DB iShot_2023-06-29_17 34 03

update quota by Redis iShot_2023-06-29_17 25 39

Obviously, after updating the quota with Redis, it will require more resources, which is also expected.

Response time

iShot_2023-06-29_17 55 11

After using Redis, the response time of requests from different dimensions has shown significant improvement, ranging from several times to tens of times faster.

TPS

iShot_2023-06-29_17 58 00

The throughput that can be processed per second has increased by more than 4 times after switching to Redis.