Skip to content

upstream: avoid quadratic time complexity in server initialization#15347

Merged
snowp merged 2 commits intoenvoyproxy:mainfrom
rojkov:cds-std-list-v3
Mar 8, 2021
Merged

upstream: avoid quadratic time complexity in server initialization#15347
snowp merged 2 commits intoenvoyproxy:mainfrom
rojkov:cds-std-list-v3

Conversation

@rojkov
Copy link
Member

@rojkov rojkov commented Mar 6, 2021

Commit Message: upstream: avoid quadratic time complexity in server initialization

Additional Description:
Currently ClusterManagerInitHelper.secondary_init_clusters_ is a list.
Upon every insert the list gets searched for an already added cluster
with the same name. Since in normal circumstances all new clusters
have unique names the worst case scenario is triggered and all elements
of the list are checked sequentially upon every cluster added.

Replace the list with a hash map.

This is a second attempt to submit the reverted #15237

Risk Level: Low
Testing: added a test case for removing unknown cluster
Docs Changes: N/A
Release Notes: N/A

…nvoyproxy#15237)

Currently ClusterManagerInitHelper.secondary_init_clusters_ is a list.
Upon every insert the list gets searched for an already added cluster
with the same name. Since in normal circumstances all new clusters
have unique names the worst case scenario is triggered and all elements
of the list are checked sequentially upon every cluster added.

Replace the list with a hash map.

Signed-off-by: Dmitry Rozhkov <dmitry.rozhkov@intel.com>
@rojkov
Copy link
Member Author

rojkov commented Mar 6, 2021

/cc @tbarrella Could you please review the fix? I've added a very simple test case, but perhaps it needs to reflect better what actually happened in Istio's test suite.

lambdai
lambdai previously approved these changes Mar 7, 2021
Copy link
Contributor

@lambdai lambdai left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks!

cluster_list->remove(&cluster);
// present in the initializer map. If so, this is fine.
auto iter = cluster_map->find(cluster.cluster().info()->name());
if (iter != cluster_map->end() && iter->second == &cluster) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Now that you are here, can you log the when (iter != cluster_map->end() && iter->second != &cluster) ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Above is not the condition of the crash. But it's good to know if this branch is possible.

Copy link
Contributor

Choose a reason for hiding this comment

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

Based on this code I think we are expecting it's possible that this can happen in our data model, e.g. getting a CDS update with the same cluster name as before.

If that's the case just put that in a comment. It would be good to know if that's covered in our tests. E.g. put an ASSERT failure here and just see if that passes tests.

If we don't hit that assert, may be leave it in? If we do hit that assert then replace it with a comment saying the above happens on a CDS update.

I'm not sure it's necessary to log it, if it's just going to happen on every CDS update that retains some names.

Copy link
Member Author

Choose a reason for hiding this comment

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

e.g. getting a CDS update with the same cluster name as before.

Yes, this is exactly the case covered with bazel test //test/common/upstream:cluster_manager_impl_test --gtest_filter=*UpdateAlreadyInitialized*. I've added a comment referencing it.

@jmarantz
Copy link
Contributor

jmarantz commented Mar 7, 2021

/retest

@repokitteh-read-only
Copy link

Retrying Azure Pipelines:
Retried failed jobs in: envoy-presubmit

🐱

Caused by: a #15347 (comment) was created by @jmarantz.

see: more, trace.

Signed-off-by: Dmitry Rozhkov <dmitry.rozhkov@intel.com>
@rojkov rojkov force-pushed the cds-std-list-v3 branch from cb4a513 to 4b30e58 Compare March 8, 2021 09:42
Copy link
Contributor

@jmarantz jmarantz left a comment

Choose a reason for hiding this comment

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

Thank you!

@envoyproxy/senior-maintainers

Copy link
Contributor

@snowp snowp left a comment

Choose a reason for hiding this comment

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

Thanks!

@snowp snowp merged commit 18453fa into envoyproxy:main Mar 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants