delay profiling
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Jake Hillion 2021-01-23 18:33:52 +00:00
parent 50e58454c3
commit 18d3b23658
2 changed files with 17 additions and 6 deletions

View File

@ -4,6 +4,7 @@ import (
"encoding/binary" "encoding/binary"
"fmt" "fmt"
"io" "io"
"log"
"mpbl3p/proxy" "mpbl3p/proxy"
"mpbl3p/shared" "mpbl3p/shared"
"net" "net"
@ -110,9 +111,9 @@ func (f *InitiatedFlow) Reconnect() error {
return err return err
} }
//if err := conn.SetWriteBuffer(20); err != nil { if err := conn.SetWriteBuffer(20); err != nil {
// return err return err
//} }
f.conn = conn f.conn = conn
f.isAlive = true f.isAlive = true
@ -186,7 +187,9 @@ func (f *Flow) Produce(v proxy.MacVerifier) (proxy.Packet, error) {
func (f *Flow) consumeMarshalled() { func (f *Flow) consumeMarshalled() {
for { for {
t1 := time.Now()
data := <-f.toConsume data := <-f.toConsume
t2 := time.Now()
err := f.conn.SetWriteDeadline(time.Now().Add(5 * time.Second)) err := f.conn.SetWriteDeadline(time.Now().Add(5 * time.Second))
if err != nil { if err != nil {
@ -198,11 +201,15 @@ func (f *Flow) consumeMarshalled() {
f.consumeErrors <- err f.consumeErrors <- err
return return
} }
t3 := time.Now()
log.Printf("consumer: `%dns` spent waiting, `%dns` spent consuming", t2.Sub(t1).Nanoseconds(), t3.Sub(t2).Nanoseconds())
} }
} }
func (f *Flow) produceMarshalled() { func (f *Flow) produceMarshalled() {
for { for {
t1 := time.Now()
lengthBytes := make([]byte, 4) lengthBytes := make([]byte, 4)
if n, err := io.LimitReader(f.conn, 4).Read(lengthBytes); err != nil { if n, err := io.LimitReader(f.conn, 4).Read(lengthBytes); err != nil {
f.produceErrors <- err f.produceErrors <- err
@ -225,6 +232,10 @@ func (f *Flow) produceMarshalled() {
} }
} }
t2 := time.Now()
f.produced <- dataBytes f.produced <- dataBytes
t3 := time.Now()
log.Printf("producer: `%dns` spent producing, `%dns` spent waiting", t2.Sub(t1).Nanoseconds(), t3.Sub(t2).Nanoseconds())
} }
} }

View File

@ -24,9 +24,9 @@ func NewListener(p *proxy.Proxy, local string, v func() proxy.MacVerifier, g fun
panic(err) panic(err)
} }
//if err := conn.SetWriteBuffer(20); err != nil { if err := conn.SetWriteBuffer(20); err != nil {
// panic(err) panic(err)
//} }
f := NewFlowConn(conn) f := NewFlowConn(conn)