mongo-java-driver icon indicating copy to clipboard operation
mongo-java-driver copied to clipboard

Direct retries to another mongos if one is available

Open stIncMale opened this issue 1 year ago • 0 comments

Given that the current specification wording is internally inconsistent, I confirmed the actual intent with the spec author and created DRIVERS-2901 Clarify the intent behind the list of deprioritized mongos'es and fix the pseudocode.

Performance considerations

Our ServerSelector and ClusterDescription API do not allow us to implement an efficient pipeline (CompositeServerSelector) of ServerSelectors: we can neither mutate the List<ServerDescription> in place, nor mutate ClusterDescription, nor even reuse the same ClusterDescription if a selector did not filter anything out. This PR added one more selector required by the specification logic, and introduced two more selectors by refactoring server selection code that wasn't expressed in terms of ServerSelectors. As a result, it is conceivable that the PR has negative performance impact.

Additionally, due to this refactoring https://github.com/mongodb/mongo-java-driver/pull/1367/commits/d25010d928704dcb7f29921f10f70505b4d45d9f, each server selection iteration now involves copying the map of Servers maintained by a Cluster. While that copying does not entail locking (all hail the CHM!), it may still have additional negative performance impact.

If we indeed notice performance degradation, we may try mitigating the issue by introducing InternalServerSelector extends ServerSelector (or a subclass of ClusterDescription that allows mutating getServerDescriptions, or both), which allows for a more optimal chaining, and use it for everything but the application-specific selector. This is assuming, of course, that the would be degradation is caused to a large extent by the inefficient selector chaining, and not by the CHM copying.

JAVA-4254, JAVA-5320

stIncMale avatar Apr 17 '24 01:04 stIncMale