8000 fix buffer index number for sticky tcp output connection by DimaGolomozy · Pull Request #981 · buger/goreplay · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix buffer index number for sticky tcp output connection #981

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

Merged
merged 1 commit into from
Aug 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions output_tcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,15 @@ func (o *TCPOutput) worker(bufferIndex int) {
}
}

func (o *TCPOutput) getBufferIndex(data []byte) int {
func (o *TCPOutput) getBufferIndex(msg *Message) int {
if !o.config.Sticky {
o.workerIndex++
return int(o.workerIndex) % o.config.Workers
}

hasher := fnv.New32a()
hasher.Write(payloadMeta(data)[1])
hasher.Write(payloadID(msg.Meta))
return int(hasher.Sum32()) % o.config.Workers

}

// PluginWrite writes message to this plugin
Expand All @@ -113,7 +112,7 @@ func (o *TCPOutput) PluginWrite(msg *Message) (n int, err error) {
return len(msg.Data), nil
}

bufferIndex := o.getBufferIndex(msg.Data)
bufferIndex := o.getBufferIndex(msg)
o.buf[bufferIndex] <- msg

if Settings.OutputTCPStats {
Expand Down
9 changes: 5 additions & 4 deletions output_tcp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,9 @@ func TestBufferDistribution(t *testing.T) {
}
}

func getTestBytes() []byte {
reqh := payloadHeader(RequestPayload, uuid(), time.Now().UnixNano(), -1)
reqb := append(reqh, []byte("GET / HTTP/1.1\r\nHost: www.w3.org\r\nUser-Agent: Go 1.1 package http\r\nAccept-Encoding: gzip\r\n\r\n")...)
return reqb
func getTestBytes() *Message {
return &Message{
Meta: payloadHeader(RequestPayload, uuid(), time.Now().UnixNano(), -1),
Data: []byte("GET / HTTP/1.1\r\nHost: www.w3.org\r\nUser-Agent: Go 1.1 package http\r\nAccept-Encoding: gzip\r\n\r\n"),
}
}
0