From 415c6f6654db38660adadc776464d827f043a8ca Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Sat, 9 Jun 2018 22:11:19 +1000 Subject: [PATCH] Increment conn read/write stats asynchronously Acquiring the lock appears to be quite intensive. --- conn_stats.go | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/conn_stats.go b/conn_stats.go index 144ab0cb..9e01104b 100644 --- a/conn_stats.go +++ b/conn_stats.go @@ -68,16 +68,20 @@ type connStatsReadWriter struct { func (me connStatsReadWriter) Write(b []byte) (n int, err error) { n, err = me.rw.Write(b) - me.l.Lock() - me.c.wroteBytes(int64(n)) - me.l.Unlock() + go func() { + me.l.Lock() + me.c.wroteBytes(int64(n)) + me.l.Unlock() + }() return } func (me connStatsReadWriter) Read(b []byte) (n int, err error) { n, err = me.rw.Read(b) - me.l.Lock() - me.c.readBytes(int64(n)) - me.l.Unlock() + go func() { + me.l.Lock() + me.c.readBytes(int64(n)) + me.l.Unlock() + }() return }