Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1748.
Summary
Adds an opt-in limit on how many potentially broad standard searches run at the
same time in one server process on the MongoDB backend. It is off unless
HFS_MONGODB_BROAD_SEARCH_CONCURRENCYis set, so existing deployments behaveexactly as before.
When it is set to
N, a potentially broad search waits for one ofNpermitsbefore its first database operation and holds it until its response is built.
Reads, writes, history, narrow searches and
_containedsearches never wait. Thelimit does not reserve connections; it reduces how much of the driver pool broad
searches can hold at once, so other requests wait less behind them.
search_admission.rs(new): the classification and the limit check._id, reference or uripredicate; a date whose values all use
eqorap;identifierwith bothsystem and code; or a
_listor compartment search.potentially broad when it computes a total, sorts on a search parameter, or
skips rows (
_offset> 0)._total=noneand_offset=0count as omitted.search_countalways counts, so it is classified as computing atotal whatever its
_totaloption._hassearches and everything else are potentially broad.MongoBackendConfig::broad_search_concurrency: Option<usize>, read byapply_search_envfromHFS_MONGODB_BROAD_SEARCH_CONCURRENCY.None(thedefault) creates no semaphore. Zero or a non-integer fails startup; a value at
or above
max_connectionsis accepted with a warning.searchandsearch_counttake a permit after validating the query.searchcomputes its own total throughcount_standard, so it never asks fora second permit (which would deadlock with a limit of 1).
hfscallsapply_search_envnext toapply_reindex_env. The README liststhe variable.
Behavior
HFS_MONGODB_BROAD_SEARCH_CONCURRENCYN(positive integer)Npotentially broad searches at once per processN>=HFS_MONGODB_MAX_CONNECTIONS0,-1,twoHFS_MONGODB_BROAD_SEARCH_CONCURRENCY must be a positive integerA search that cannot get a permit before
HFS_REQUEST_TIMEOUTends with theexisting 408. The limit is per process; with several processes the cluster-wide
limit is that many times the setting.
Before / after
Server built with
--no-default-features --features R4,mongodb, started with--storage-backend mongodbagainst a single-node replica set, withHFS_MONGODB_MAX_CONNECTIONS=2. 150 Observations with one code. AfailCommandfailpoint blocks
getMorefor 5 s (twice) on the server's connections; twoObservation?code=http://loinc.org|8867-4&_count=10searches start, and aPatient/{id}read is timed while they run. A read by id never sendsgetMore,so the failpoint never blocks it directly.
getMoremain(acab4363)HFS_MONGODB_BROAD_SEARCH_CONCURRENCY=1Unset behaves as
main. With a limit of 1 the second search waits for thepermit instead of taking the second connection, and the read gets it.
Tests
backends/mongodb/search_admission.rs): narrowing predicates; otherpredicates broad whatever their count; weakened narrowing predicates (ranges,
mixed prefixes,
|code,system|,:not,:missing, chains, no values);parameterless searches with
_total,_sort,_offsetand their no-opvalues;
_has,_listand compartment searches; direct counts independent of_total; limit validation.backends/mongodb/backend.rs): env parsing (trim, blank, unset,invalid values); semaphore sizing (none when unset); a broad search waits while
the permit is held and a narrow one does not; without a limit 64 broad searches
proceed at once; a search that fails on an invalid cursor returns its permit; a
queued
search_countdoes not open the database client and returns its permitwhen cancelled.
hfs/src/main.rs):build_mongodb_configreads the variable and failson
0,-1andtwo.tests/mongodb/broad_search_admission.rs), pool of 2,failpoint blocking only
getMore:mongodb_broad_search_limit_leaves_a_connection_for_reads: limit 1; waitswith
waitForFailPointuntil the first search is blocked, checks the seconddoes not reach
getMore, and a read by id completes within 1 s.mongodb_broad_searches_at_the_pool_size_block_reads: limit 2; both searchesblocked, the read does not complete within 1 s (control).
mongodb_broad_search_with_total_uses_one_permit: limit 1; a broad searchwith
_total=accuratecompletes and returns its total, then a count runs.at "the second broad search waits for the permit".
Full
helios-persistence(withmongodb),helios-restandhelios-hfssuitesagainst a MongoDB replica set: 4,585 passed, 0 failed, 0 skipped.
Notes for review
prefer a default (for example half of
HFS_MONGODB_MAX_CONNECTIONS). Happy tochange it.
reference to a large organization or a busy day is treated as narrow.
_containedsearches are not limited. Under_contained=boththe top-levelpart goes through
searchand is limited like any standard search.Run locally against a MongoDB replica set started with
--setParameter enableTestCommands=1(HFS_TEST_MONGODB_URL):