Skip to content

Conversation

giorio94
Copy link
Member

@giorio94 giorio94 commented Jun 7, 2023

Reporting the description of the first commit for convenience:


Currently, each etcd client is associated with a single session, and the
corresponding lease is attached to all upserted keys (if the lease
parameter is set). This approach, though, suffers from performance
issues, because put requests in etcd take linear apply time depending
on the number of keys already attached to the lease (etcd-io/etcd#15993).
This performance penalty is planned to be fixed in etcd (at least for the
common case in which the user which performs the request has root role).

In the meanwhile, let's make sure that we attach a limited number of
keys to a single lease. In particular, this commit introduces the etcd
lease manager, which is responsible for managing the lease acquisitions,
tracking the keys that are attached to each of them. Once the number of
keys per lease exceeds the configured threshold, a new lease gets
automatically acquired. The lease usage counter is decremented when a
given key gets deleted. Finally, in case one of the leases fails to be
renewed, the manager allows to emit a notification event for all the keys
that were attached to it.


Additionally, the sync store implementation is modified to register for the lease expiration events, appropriately triggering the re-creation of the given keys. This allows to mitigate the possibility that keys get deleted because the associated lease failed to be renewed.

@giorio94 giorio94 added kind/performance There is a performance impact of this. area/clustermesh Relates to multi-cluster routing functionality in Cilium. release-note/misc This PR makes changes that have no direct user impact. area/kvstore Impacts the KVStore package interactions. labels Jun 7, 2023
@giorio94 giorio94 requested a review from marseel June 7, 2023 07:21
@giorio94 giorio94 requested a review from a team as a code owner June 7, 2023 07:21
@giorio94 giorio94 requested a review from tklauser June 7, 2023 07:21
@giorio94
Copy link
Member Author

giorio94 commented Jun 7, 2023

/test

@giorio94 giorio94 force-pushed the mio/etcd-lease-manager branch from 86a5223 to 0bbdede Compare June 7, 2023 11:37
@giorio94 giorio94 requested a review from marseel June 7, 2023 11:41
Copy link
Contributor

@marseel marseel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, except for one minor thing with metrics.

@giorio94 giorio94 force-pushed the mio/etcd-lease-manager branch from 0bbdede to 92e835f Compare June 7, 2023 12:59
giorio94 added 4 commits June 7, 2023 15:19
Currently, each etcd client is associated with a single session, and the
corresponding lease is attached to all upserted keys (if the lease
parameter is set). This approach, though, suffers from performance
issues, because put requests in etcd take linear apply time depending
on the number of keys already attached to the lease (etcd-io/etcd#15993).
This performance penalty is planned to be fixed in etcd (at least for the
common case in which the user which performs the request has root role).

In the meanwhile, let's make sure that we attach a limited number of
keys to a single lease. In particular, this commit introduces the etcd
lease manager, which is responsible for managing the lease acquisitions,
tracking the keys that are attached to each of them. Once the number of
keys per lease exceeds the configured threshold, a new lease gets
automatically acquired. The lease usage counter is decremented when a
given key gets deleted. Finally, in case one of the leases fails to be
renewed, the manager allows to emit a notification event for all the keys
that were attached to it.

Signed-off-by: Marco Iorio <marco.iorio@isovalent.com>
This commit modifies the etcd client to use the newly introduced lease
manager in place of the static session, adapting the different call
sites. One side effect is that we now create only one lease (instead of
two) in case the client is used in read-only mode (e.g., in the
clustermesh case).

Signed-off-by: Marco Iorio <marco.iorio@isovalent.com>
Now that we track the keys attached to each leases, let's allow to
register callbacks to be executed for each key attached to a lease that
has expired or failed to be renewed. This allows possible subscribers to
be notified and take care of inserting again the given keys.

Signed-off-by: Marco Iorio <marco.iorio@isovalent.com>
The SyncStore now registers an observer to get notified in case the
lease attached to any managed key expires, so that the given key can
be enqueued to be synchronized again in the kvstore.

Signed-off-by: Marco Iorio <marco.iorio@isovalent.com>
@giorio94 giorio94 force-pushed the mio/etcd-lease-manager branch from 92e835f to da50c81 Compare June 7, 2023 13:19
@giorio94
Copy link
Member Author

giorio94 commented Jun 7, 2023

Rebased onto main to pick the CI fixes.

@giorio94
Copy link
Member Author

giorio94 commented Jun 7, 2023

/test

@maintainer-s-little-helper maintainer-s-little-helper bot added the ready-to-merge This PR has passed all tests and received consensus from code owners to merge. label Jun 8, 2023
@tklauser tklauser merged commit 2178f93 into cilium:main Jun 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/clustermesh Relates to multi-cluster routing functionality in Cilium. area/kvstore Impacts the KVStore package interactions. kind/performance There is a performance impact of this. ready-to-merge This PR has passed all tests and received consensus from code owners to merge. release-note/misc This PR makes changes that have no direct user impact.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants