Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use direct outbound for history client #4619

Conversation

vytautas-karpavicius
Copy link
Contributor

@vytautas-karpavicius vytautas-karpavicius commented Nov 5, 2021

What changed?
Client factory used to initialize and cache history clients for each peer. For each client a separate dispatcher was created via rpc factory. This is rather complicated setup and is not idiomatic on YARPC framework.

In order to route requests to different peers, yarpc provides direct peer chooser. It uses ShardKey set on the request to route this particular call to the given host. We do not need to initialize multiple dispatchers and multiple clients with caching on top.

This PR:

  • Introduces direct outbound builder
  • Refactors out history.PeerChooser, documents it and adds unit tests.
  • Refactors history.Client to drop client cache and instead adds WithShardKey for routing to appropriate instance.
  • Updates client.Factory to wire up new setup.

Why?
To move forward towards use of single yarpc dispatcher.

The similar effort is needed for matching client as well. After that we can basically drop rpc.Factory and use single Dispatcher everywhere.

How did you test it?
New unit tests.
Integration tests.
Locally with cadence canary.

Potential risks
This also brings one observable change. History client will no longer use caller name history-service-client, but rather use the actual service name where the call is originating, for example: cadence-frontend.
Even though the we can override callerName, at the moment I do not think this is needed. I'm not aware where this could be used other than yarpc metrics.
IMO, the actual name of caller service is more useful than a constant string.

Release notes

Documentation Changes

@vytautas-karpavicius vytautas-karpavicius force-pushed the history-direct-outbound branch 2 times, most recently from 3025999 to 9346303 Compare November 5, 2021 14:01
@coveralls
Copy link

coveralls commented Nov 5, 2021

Pull Request Test Coverage Report for Build cd689d97-cec4-4557-ad2a-06984abe45f7

  • 165 of 275 (60.0%) changed or added relevant lines in 8 files are covered.
  • 66 unchanged lines in 12 files lost coverage.
  • Overall coverage increased (+0.05%) to 56.89%

Changes Missing Coverage Covered Lines Changed/Added Lines %
cmd/server/cadence/server.go 0 1 0.0%
client/clientfactory.go 13 16 81.25%
common/rpc/outbounds.go 19 23 82.61%
client/history/client.go 87 189 46.03%
Files with Coverage Reduction New Missed Lines %
common/task/weightedRoundRobinTaskScheduler.go 1 89.64%
service/history/queue/timer_queue_processor_base.go 1 78.6%
client/clientfactory.go 2 59.16%
common/membership/rpServiceResolver.go 2 73.58%
common/persistence/executionManager.go 2 76.32%
common/persistence/statsComputer.go 2 95.71%
service/history/queue/timer_gate.go 3 95.83%
common/task/fifoTaskScheduler.go 5 84.54%
common/persistence/nosql/nosqlExecutionStore.go 9 60.35%
service/history/shard/context.go 9 65.46%
Totals Coverage Status
Change from base Build e6ed1a71-c434-4036-ad25-0bf7da45916d: 0.05%
Covered Lines: 82331
Relevant Lines: 144720

💛 - Coveralls

@vytautas-karpavicius vytautas-karpavicius marked this pull request as ready for review November 5, 2021 14:42
@vytautas-karpavicius vytautas-karpavicius requested a review from a team November 5, 2021 14:42
func NewPeerResolver(numberOfShards int, membership membership.Monitor, addressMapper AddressMapperFn) PeerResolver {
return PeerResolver{
numberOfShards: numberOfShards,
membership: membership,
Copy link
Contributor

Choose a reason for hiding this comment

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

If you need only history resolver, you can replace membership with resolver and pass history resolver here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agree, updated the PR.

logger log.Logger,
) Client {
return &clientImpl{
numberOfShards: numberOfShards,
rpcMaxSizeInBytes: rpcMaxSizeInBytes,
tokenSerializer: common.NewJSONTaskTokenSerializer(),
timeout: timeout,
clients: clients,
client: client,
peer: peerResolver,
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: rename peer to peerResolver to make it more obvious

@vytautas-karpavicius vytautas-karpavicius merged commit 04cd354 into cadence-workflow:master Nov 8, 2021
@vytautas-karpavicius vytautas-karpavicius deleted the history-direct-outbound branch November 8, 2021 13:51
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.

3 participants