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

benchmarks for write with compression enabled/disabled #205

Merged
merged 1 commit into from Jan 14, 2017
Merged

benchmarks for write with compression enabled/disabled #205

merged 1 commit into from Jan 14, 2017

Conversation

FZambia
Copy link
Contributor

@FZambia FZambia commented Jan 13, 2017

This is to help in investigating #203

Output on my machine:

BenchmarkWriteNoCompression-4            3000000               503 ns/op              48 B/op          1 allocs/op
BenchmarkWriteWithCompression-4            30000             41481 ns/op             123 B/op          3 allocs/op

Investingating only BenchmarkWriteWithCompression, here is cpu profile output:

(pprof) top 10 --cum
1.14s of 1.55s total (73.55%)
Showing top 10 nodes out of 67 (cum >= 0.95s)
      flat  flat%   sum%        cum   cum%
         0     0%     0%      1.54s 99.35%  github.com/FZambia/websocket.(*Conn).WriteMessage
         0     0%     0%      1.54s 99.35%  github.com/FZambia/websocket.BenchmarkWriteWithCompression
         0     0%     0%      1.54s 99.35%  runtime.goexit
         0     0%     0%      1.54s 99.35%  testing.(*B).launch
         0     0%     0%      1.54s 99.35%  testing.(*B).runN
     0.02s  1.29%  1.29%      1.21s 78.06%  github.com/FZambia/websocket.(*Conn).NextWriter
     1.08s 69.68% 70.97%      1.08s 69.68%  runtime.memclr
     0.03s  1.94% 72.90%      1.03s 66.45%  github.com/FZambia/websocket.compressNoContextTakeover
         0     0% 72.90%      0.95s 61.29%  compress/flate.(*Writer).Reset
     0.01s  0.65% 73.55%      0.95s 61.29%  compress/flate.(*compressor).reset

(pprof) list NextWriter
Total: 1.55s
ROUTINE ======================== github.com/FZambia/websocket.(*Conn).NextWriter in /Users/a.emelin/work/gopath/src/github.com/FZambia/websocket/conn.go
      20ms      1.21s (flat, cum) 78.06% of Total
         .          .    444:   }
         .          .    445:
         .          .    446:   mw := &messageWriter{
         .          .    447:           c:         c,
         .          .    448:           frameType: messageType,
      20ms      180ms    449:           pos:       maxFrameHeaderSize,
         .          .    450:   }
         .          .    451:   c.writer = mw
         .          .    452:   if c.newCompressionWriter != nil && c.enableWriteCompression && isData(messageType) {
         .      1.03s    453:           w := c.newCompressionWriter(c.writer)
         .          .    454:           mw.compress = true
         .          .    455:           c.writer = w
         .          .    456:   }
         .          .    457:   return c.writer, nil
         .          .    458:}
(pprof) list compressNoContextTakeover
Total: 1.55s
ROUTINE ======================== github.com/FZambia/websocket.compressNoContextTakeover in /Users/a.emelin/work/gopath/src/github.com/FZambia/websocket/compression.go
      30ms      1.03s (flat, cum) 66.45% of Total
         .          .     33:   fr.(flate.Resetter).Reset(io.MultiReader(r, strings.NewReader(tail)), nil)
         .          .     34:   return &flateReadWrapper{fr}
         .          .     35:}
         .          .     36:
         .          .     37:func compressNoContextTakeover(w io.WriteCloser) io.WriteCloser {
      10ms       40ms     38:   tw := &truncWriter{w: w}
         .       10ms     39:   fw, _ := flateWriterPool.Get().(*flate.Writer)
         .      950ms     40:   fw.Reset(tw)
      20ms       30ms     41:   return &flateWriteWrapper{fw: fw, tw: tw}
         .          .     42:}
         .          .     43:
         .          .     44:// truncWriter is an io.Writer that writes all but the last four bytes of the
         .          .     45:// stream to another io.Writer.
         .          .     46:type truncWriter struct {

Heap:

$ go tool pprof --alloc_space websocket.test mem
Entering interactive mode (type "help" for commands)
(pprof) top 10 --cum
6.53MB of 8.64MB total (75.52%)
Showing top 10 nodes out of 23 (cum >= 5.13MB)
      flat  flat%   sum%        cum   cum%
         0     0%     0%     8.64MB   100%  runtime.goexit
    1.50MB 17.36% 17.36%     8.13MB 94.03%  github.com/FZambia/websocket.(*Conn).NextWriter
         0     0% 17.36%     8.13MB 94.03%  github.com/FZambia/websocket.(*Conn).WriteMessage
         0     0% 17.36%     8.13MB 94.03%  github.com/FZambia/websocket.BenchmarkWriteWithCompression
         0     0% 17.36%     8.13MB 94.03%  testing.(*B).runN
         0     0% 17.36%     7.24MB 83.83%  testing.(*B).launch
    1.50MB 17.36% 34.72%     6.63MB 76.67%  github.com/FZambia/websocket.compressNoContextTakeover
    3.53MB 40.80% 75.52%     5.13MB 59.31%  compress/flate.NewWriter
         0     0% 75.52%     5.13MB 59.31%  github.com/FZambia/websocket.glob..func1
         0     0% 75.52%     5.13MB 59.31%  sync.(*Pool).Get

(pprof) list NextWriter
Total: 8.64MB
ROUTINE ======================== github.com/FZambia/websocket.(*Conn).NextWriter in /Users/a.emelin/work/gopath/src/github.com/FZambia/websocket/conn.go
    1.50MB     8.13MB (flat, cum) 94.03% of Total
         .          .    444:   }
         .          .    445:
         .          .    446:   mw := &messageWriter{
         .          .    447:           c:         c,
         .          .    448:           frameType: messageType,
    1.50MB     1.50MB    449:           pos:       maxFrameHeaderSize,
         .          .    450:   }
         .          .    451:   c.writer = mw
         .          .    452:   if c.newCompressionWriter != nil && c.enableWriteCompression && isData(messageType) {
         .     6.63MB    453:           w := c.newCompressionWriter(c.writer)
         .          .    454:           mw.compress = true
         .          .    455:           c.writer = w
         .          .    456:   }
         .          .    457:   return c.writer, nil
         .          .    458:}
(pprof) list compressNoContextTakeover
Total: 8.64MB
ROUTINE ======================== github.com/FZambia/websocket.compressNoContextTakeover in /Users/a.emelin/work/gopath/src/github.com/FZambia/websocket/compression.go
    1.50MB     6.63MB (flat, cum) 76.67% of Total
         .          .     33:   fr.(flate.Resetter).Reset(io.MultiReader(r, strings.NewReader(tail)), nil)
         .          .     34:   return &flateReadWrapper{fr}
         .          .     35:}
         .          .     36:
         .          .     37:func compressNoContextTakeover(w io.WriteCloser) io.WriteCloser {
  512.02kB   512.02kB     38:   tw := &truncWriter{w: w}
         .     5.13MB     39:   fw, _ := flateWriterPool.Get().(*flate.Writer)
         .          .     40:   fw.Reset(tw)
       1MB        1MB     41:   return &flateWriteWrapper{fw: fw, tw: tw}
         .          .     42:}
         .          .     43:
         .          .     44:// truncWriter is an io.Writer that writes all but the last four bytes of the
         .          .     45:// stream to another io.Writer.
         .          .     46:type truncWriter struct {

@garyburd garyburd merged commit 561ac01 into gorilla:master Jan 14, 2017
@gorilla gorilla locked and limited conversation to collaborators Feb 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants