Increment conn read/write stats asynchronously

Acquiring the lock appears to be quite intensive.
This commit is contained in:
Matt Joiner 2018-06-09 22:11:19 +10:00
parent a9bdb438dc
commit 415c6f6654
1 changed files with 10 additions and 6 deletions

View File

@ -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
}