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

[m3msg] Use multiple connections for M3Msg writers #2230

Merged

Conversation

robskillington
Copy link
Collaborator

@robskillington robskillington commented Mar 26, 2020

What this PR does / why we need it:

Allows for multiple connections for M3Msg to use to a single backend instance, also removes a lot of default instrumentation using Prometheus summaries for timers when using the M3Msg aggregator client.

There are bunch of other small fixes in terms of the default connection options for large throughput workloads using M3Msg from point to point connections (i.e. 50k-500k single instance to instance datapoints per second, rather than fan-in of metrics from thousands of hosts which the old rawtcp protocol was mainly designed for).

Making the default write timeout infinite and relying on fast TCP keep alives to (5-10s) to break stale connections are used instead, since IO timeout on connections was frequently hit during bursts of traffic which made it worse (i.e. hard to recover the connection once it degrades even slightly).

Special notes for your reviewer:

Does this PR introduce a user-facing and/or backwards incompatible change?:

NONE

Does this PR require updating code package or user-facing documentation?:

NONE

@robskillington robskillington force-pushed the r/add-m3msg-aggregator-client-server-multi-connections branch from daef618 to e070f43 Compare March 26, 2020 18:18
@robskillington robskillington changed the title [m3msg] Use multiple TCP connections for M3Msg connections [m3msg] Use multiple connections for M3Msg writers Mar 26, 2020
@codecov
Copy link

codecov bot commented Mar 26, 2020

Codecov Report

❗ No coverage uploaded for pull request base (r/add-m3msg-aggregator-client-server@48beec5). Click here to learn what that means.
The diff coverage is 0%.

Impacted file tree graph

@@                          Coverage Diff                           @@
##             r/add-m3msg-aggregator-client-server   #2230   +/-   ##
======================================================================
  Coverage                                        ?   40.9%           
======================================================================
  Files                                           ?     837           
  Lines                                           ?   74980           
  Branches                                        ?       0           
======================================================================
  Hits                                            ?   30695           
  Misses                                          ?   41270           
  Partials                                        ?    3015
Flag Coverage Δ
#aggregator 0% <0%> (?)
#cluster 28.3% <ø> (?)
#collector 100% <ø> (?)
#dbnode 68.5% <ø> (?)
#m3em 100% <ø> (?)
#m3ninx 48.3% <ø> (?)
#m3nsch 100% <ø> (?)
#query 1.3% <0%> (?)
#x 46.1% <ø> (?)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 48beec5...5aa1c4e. Read the comment docs.

@mmedvede
Copy link
Contributor

mmedvede commented Apr 9, 2020

With a build from 5aa1c4e (go1.12.9) used for both aggregator and cordinator, I see high idle CPU

image
CPU profiles:
pprof.m3aggregator.samples.cpu.002.pb.gz
pprof.m3coordinator.samples.cpu.011.pb.gz

@mmedvede
Copy link
Contributor

mmedvede commented Apr 9, 2020

When I reduced number of m3msg connections on coordinators from 32 to 8, the aggregator CPU use went down from 1.4 to 1.1. Coordinator CPU remained unchanged. That cluster has 6 coordinators, and 12 aggregators.

@mmedvede
Copy link
Contributor

Likewise, dropping connection count on aggregators from 32 to 8 resulted in idle CPU drop on cooridinators from 2.7 to 1.5.

func (w *consumerWriterImpl) reset(opts resetOptions) {
w.writeState.Lock()
prevConns := w.writeState.conns
defer func() {
Copy link
Collaborator

@arnikola arnikola Apr 22, 2020

Choose a reason for hiding this comment

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

Would this work better replacing the conns in place, and closing the previous one after it's replaced? Or it the size of conns not guaranteed to be the same every reset?

w.rw.Writer.Reset(conn)
w.lastResetNanos = w.nowFn().UnixNano()
w.writeState.lastResetNanos = opts.at.UnixNano()
w.writeState.validConns = opts.validConns
Copy link
Collaborator

Choose a reason for hiding this comment

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

Looks like there's no branching here; if it's impossible to replace conns in place, can close them here rather than in the defer?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Main thing is trying to avoid holding lock while doing IO work (closing connection may block for IO, so don't want to do that while we hold any locks).

@notbdu notbdu self-requested a review April 24, 2020 05:14
Copy link
Contributor

@notbdu notbdu left a comment

Choose a reason for hiding this comment

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

LGTM, followup on more comments in a consequent PR

@robskillington robskillington merged commit 5997222 into master Apr 24, 2020
@robskillington robskillington deleted the r/add-m3msg-aggregator-client-server-multi-connections branch April 24, 2020 09:58
if acked {
w.m.messageConsumeLatency.Record(time.Duration(w.nowFn().UnixNano() - initNanos))
// w.m.messageConsumeLatency.Record(time.Duration(w.nowFn().UnixNano() - initNanos))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hi @robskillington a lot of these metrics are commented out, any reason for that? Can we uncomment them?

@nathanjordan nathanjordan mentioned this pull request May 4, 2020
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.

5 participants