2
0
mirror of https://github.com/soheilhy/cmux.git synced 2024-11-09 19:21:52 +08:00
Commit Graph

75 Commits

Author SHA1 Message Date
Soheil Hassas Yeganeh
703b087a39 Optimize Patricia tree
Remove all the extra allocations in the Patricia tree.

O(1) allocation for Patricia and  ~10% improvement for HTTP1 matching.

benchmark                      old ns/op     new ns/op     delta
BenchmarkCMuxConnHTTP1-4       908           782           -13.88%
BenchmarkCMuxConnHTTP2-4       835           818           -2.04%
BenchmarkCMuxConnHTTP1n2-4     1074          1033          -3.82%
BenchmarkCMuxConnHTTP2n1-4     1010          901           -10.79%

benchmark                      old allocs     new allocs     delta
BenchmarkCMuxConnHTTP1-4       5              3              -40.00%
BenchmarkCMuxConnHTTP2-4       4              4              +0.00%
BenchmarkCMuxConnHTTP1n2-4     6              4              -33.33%
BenchmarkCMuxConnHTTP2n1-4     6              4              -33.33%

benchmark                      old bytes     new bytes     delta
BenchmarkCMuxConnHTTP1-4       276           272           -1.45%
BenchmarkCMuxConnHTTP2-4       304           304           +0.00%
BenchmarkCMuxConnHTTP1n2-4     306           304           -0.65%
BenchmarkCMuxConnHTTP2n1-4     308           304           -1.30%
2016-05-03 22:28:32 -04:00
Soheil Hassas Yeganeh
d45bcbe1db Add more benchmarks
Add benchmarks for HTTP2 matchers and combinations of it with HTTP1Fast.
2016-05-03 22:14:35 -04:00
Soheil Hassas Yeganeh
9297b6de56 Merge pull request #24 from soheilhy/fix-java-client
Fix java gRPC client
2016-04-24 14:53:47 -04:00
Soheil Hassas Yeganeh
dc30a14f2d Add docs for the Java gRPC client 2016-04-24 14:52:49 -04:00
Soheil Hassas Yeganeh
d83a667cb2 Add Matchers that can write back on the channel
As reported in issue #22 reports that Java gRPC clients cannot
handshake with cmux'ed gRPC server, since the client does not
immediately send a header with the content-type field. The reason
is that the java client, block on receiving the first SETTING
frame.

Add MatchWriter that can match and write on the connection. Implement
a MatchWriter that writes a SETTING frame once it receives a SETTING
frame.
2016-04-24 14:47:08 -04:00
Soheil Hassas Yeganeh
255149b822 Merge pull request #23 from soheilhy/bytes-buffer
Replace TeeReader with a bytes buffer
2016-04-24 14:38:36 -04:00
Soheil Hassas Yeganeh
3077b24d47 Fix and optimize travis config
There is no point in running shadow and lints for all version of go.

Also, remove 1.3 and 1.4.
2016-04-24 14:10:41 -04:00
Soheil Hassas Yeganeh
d5924ef0b4 Fix a blocking issue in buffer reader
After sniffing and buffering data, if we try to read from
the socket again, bufio.Reader may block. This breaks HTTP handlers
in go1.5.2+ if one tries on browsers or with curl. Go's HTTP client,
however, is not broken. This issue is also there with TeeReader.

Return immediately with the data in the sniffed buffer.
2016-04-24 12:55:13 -04:00
Tamir Duberstein
59b6f01712 Replace buffer with bufferedReader
bufferedReader is an optimized implementation of io.Reader that behaves
like
```
io.MultiReader(bytes.NewReader(buffer.Bytes()), io.TeeReader(source, buffer))
```
without allocating.

This has a measurable effect on benchmarks:
```
name        old time/op    new time/op    delta
CMuxConn-4    1.09µs ± 4%    0.99µs ±19%   -9.32%  (p=0.000 n=17+19)

name        old alloc/op   new alloc/op   delta
CMuxConn-4      240B ± 0%      260B ± 0%   +8.33%  (p=0.000 n=20+20)

name        old allocs/op  new allocs/op  delta
CMuxConn-4      9.00 ± 0%      5.00 ± 0%  -44.44%  (p=0.000 n=20+20)
```

Note that appropriate test coverage is provided by `TestRead`.
2016-02-28 19:41:37 -05:00
Soheil Hassas Yeganeh
7ec7ce7ad1 Merge pull request #21 from soheilhy/devel
Use the readable indentation for error flow
2016-02-27 18:16:04 -05:00
Soheil Hassas Yeganeh
e09914bfa3 Use the readable indentation for error flow 2016-02-27 13:04:49 -05:00
Soheil Hassas Yeganeh
d710784914 Merge pull request #20 from tamird/fix-read-again
(*MuxConn).Read: fix erroneous io.EOF return
2016-02-25 23:16:54 -05:00
Tamir Duberstein
49c66ff242 (*MuxConn).Read: fix erroneous io.EOF return
This fixes a bug where (*MuxConn).Read would return io.EOF if the
buffer was exactly the right size to fill the passed-in slice.
2016-02-25 21:59:10 -05:00
Soheil Hassas Yeganeh
d8cc6481fa Merge pull request #18 from tamird/vet-shadow
`go tool vet --shadow .`
2016-02-25 12:04:36 -05:00
Soheil Hassas Yeganeh
23074f6929 Merge pull request #17 from tamird/fix-write
buffer: do not retain passed-in memory
2016-02-25 12:03:57 -05:00
Tamir Duberstein
180c9ac049 go tool vet --shadow . 2016-02-25 11:47:10 -05:00
Tamir Duberstein
48443df968 buffer: do not retain passed-in memory
This is in violation of the io.Writer interface specification.
2016-02-25 11:40:31 -05:00
Soheil Hassas Yeganeh
1a2fcbde3a Merge pull request #16 from soheilhy/devel
Close the connections buffered for the listeners
2016-02-23 23:05:27 -05:00
Soheil Hassas Yeganeh
6f986603b0 Close the connections buffered for the listeners
This commit closes the connections that has been buffered
on the connection channel of the cmux listeners, when the
root listener is closed. With this change it is guaranteed
that the connections are either closed or handed of to the
child listeners (returned via Accept()).

There are a couple of changes to the tests to cover corner
cases and the new behavior.
2016-02-23 23:01:35 -05:00
Soheil Hassas Yeganeh
2625710699 Merge pull request #13 from tamird/fix-http2
http2: use io.ReadFull
2016-02-23 11:27:28 -05:00
Tamir Duberstein
204cc45a24 http2: use io.ReadFull
This fixes an issue where an earlier matcher does not sufficiently
populate the buffer, preventing HTTP2 from reading enough bytes on the
Read call.
2016-02-23 11:25:36 -05:00
Soheil Hassas Yeganeh
99ee7b080d Merge pull request #12 from tamird/fix-read
Reduce the number of calls needed to (*MuxConn).Read
2016-02-23 11:20:36 -05:00
Soheil Hassas Yeganeh
d5b9190ea9 Merge pull request #11 from tamird/fix-close
Tweak shutdown behaviour
2016-02-23 11:20:27 -05:00
Tamir Duberstein
235d98b021 Tweak shutdown behaviour
When the root listener is closed, child listeners will not be closed
until all parked connections are served. This prevents losing
connections that have been read from.

This also allows moving the main test to package cmux_test, but that
will happen in a separate change.
2016-02-23 11:13:16 -05:00
Tamir Duberstein
9a9119af9d fix flaky test TestErrorHandler
Before this change, this test would fail after about 50 runs. After
this change, I was able to run it 200 times without failure.
2016-02-23 11:06:01 -05:00
Tamir Duberstein
6490dea199 Reduce the number of calls needed to (*MuxConn).Read
Also affects (*buffer).Read.
2016-02-23 09:49:37 -05:00
Soheil Hassas Yeganeh
95fd8b5c56 Merge pull request #10 from tamird/cleanup-error-handler
TestErrorHandler: assert that the error handler runs
2016-02-22 22:47:19 -05:00
Tamir Duberstein
15b1cf90b1 TestErrorHandler: assert that the error handler runs
Also fixes a race condition using an atomic and adds the race detector
to Travis CI.
2016-02-22 22:33:02 -05:00
Soheil Hassas Yeganeh
4796322bac Merge pull request #8 from tamird/fix-leaks
fix test-only goroutine leaks
2016-02-22 22:25:32 -05:00
Tamir Duberstein
e5e53dfc73 avoid (*testing.T).FailNow in non-main goroutines 2016-02-22 22:13:34 -05:00
Tamir Duberstein
ffd8d50a7c fix test-only goroutine leaks
This makes real test failures' stack traces much easier to read.
2016-02-22 22:13:34 -05:00
Soheil Hassas Yeganeh
fd2424be4b Merge pull request #9 from tamird/DRY
Refactor redundant code.
2016-02-22 22:02:58 -05:00
Soheil Hassas Yeganeh
dcd94116ef Merge pull request #7 from tamird/vet
Add `go vet` to Travis CI
2016-02-22 21:43:55 -05:00
Tamir Duberstein
5746da9df6 DRY 2016-02-21 12:59:08 -05:00
Tamir Duberstein
93090fcbbc Add go vet to Travis CI 2016-02-21 12:39:43 -05:00
Tamir Duberstein
b5e73ea381 remove named returns and useless closures 2016-02-21 12:09:02 -05:00
Tamir Duberstein
ecc37f82cd let the kernel assign ports 2016-02-21 12:07:55 -05:00
Tamir Duberstein
4f1b8abafd Add Go 1.5 & 1.6 to Travis CI 2016-02-21 12:02:55 -05:00
Tamir Duberstein
92a63c4fce errcheck
go/src/github.com/soheilhy/cmux/cmux.go:127:13	c.Close()
go/src/github.com/soheilhy/cmux/cmux.go:134:9	c.Close()
go/src/github.com/soheilhy/cmux/cmux.go:137:15	m.root.Close()
go/src/github.com/soheilhy/cmux/cmux_test.go:43:9	s.Serve(l)
go/src/github.com/soheilhy/cmux/cmux_test.go:52:20	defer r.Body.Close()
go/src/github.com/soheilhy/cmux/cmux_test.go:72:12	s.Register(TestRPCRcvr{})
go/src/github.com/soheilhy/cmux/cmux_test.go:103:15	defer l.Close()
go/src/github.com/soheilhy/cmux/cmux_test.go:109:15	go muxl.Serve()
go/src/github.com/soheilhy/cmux/cmux_test.go:116:20	defer r.Body.Close()
go/src/github.com/soheilhy/cmux/cmux_test.go:125:15	defer l.Close()
go/src/github.com/soheilhy/cmux/cmux_test.go:133:15	go muxl.Serve()
go/src/github.com/soheilhy/cmux/cmux_test.go:141:15	defer l.Close()
go/src/github.com/soheilhy/cmux/cmux_test.go:147:15	go muxl.Serve()
go/src/github.com/soheilhy/cmux/example_recursive_test.go:27:9	s.Serve(l)
go/src/github.com/soheilhy/cmux/example_recursive_test.go:56:12	s.Register(&RecursiveRPCRcvr{})
go/src/github.com/soheilhy/cmux/example_recursive_test.go:88:15	go tlsm.Serve()
go/src/github.com/soheilhy/cmux/example_recursive_test.go:89:12	tcpm.Serve()
go/src/github.com/soheilhy/cmux/example_test.go:30:9	s.Serve(l)
go/src/github.com/soheilhy/cmux/example_test.go:34:9	io.Copy(ws, ws)
go/src/github.com/soheilhy/cmux/example_test.go:41:9	s.Serve(l)
go/src/github.com/soheilhy/cmux/example_test.go:53:12	s.Register(&ExampleRPCRcvr{})
go/src/github.com/soheilhy/cmux/example_test.go:68:13	grpcs.Serve(l)
go/src/github.com/soheilhy/cmux/example_test.go:97:9	m.Serve()
go/src/github.com/soheilhy/cmux/example_tls_test.go:24:9	s.Serve(l)
go/src/github.com/soheilhy/cmux/example_tls_test.go:69:9	m.Serve()
go/src/github.com/soheilhy/cmux/matchers.go:151:14	hdec.Write(f.HeaderBlockFragment())
2016-02-21 12:02:37 -05:00
Soheil Hassas Yeganeh
ec462e9c0e Replace log.Fatal with log.Panic 2016-02-21 10:46:12 -05:00
Tamir Duberstein
6c298ce7b1 Simplify formatting in patricia.go
`gofmt -s -w .`
2016-02-21 10:41:14 -05:00
Soheil Hassas Yeganeh
3ca13bcd9e Remove the unncessary var and const blocks 2016-02-21 10:37:29 -05:00
Tamir Duberstein
48deeb47a3 golint
cmux.go:28:1: exported method ErrNotMatched.Temporary should have comment or be unexported
cmux.go:29:1: exported method ErrNotMatched.Timeout should have comment or be unexported
cmux.go:38:2: exported var ErrListenerClosed should have comment or be unexported
cmux.go:165:6: exported type MuxConn should have comment or be unexported
2016-02-21 10:34:32 -05:00
Tamir Duberstein
05566d752e vet: buffer_test.go:65: possible formatting directive in Fatal call 2016-02-21 10:33:47 -05:00
Soheil Hassas Yeganeh
345ba38c5f Merge pull request #6 from emosbaugh/flag_parse_in_library
rely on project to call flag.Parse rather than when used as library
2016-02-20 13:50:53 -05:00
Ethan Mosbaugh
4ebe86a5a2 rely on project to call flag.Parse rather than when used as library 2016-02-09 07:53:32 -08:00
Tamir Duberstein
563c371a98 Cleanup code in cmux and bench_test.
This commit is a partial cherry pick of pull request #3, for code cleanup.
2015-12-19 22:37:27 -05:00
Soheil Hassas Yeganeh
89dd8ce1fd Return an error in Accept() when root is closed.
As reported in #4, when the root listener is closed, calling Accept
on mux'd listeners would block forever, instead of returning an error.
This is because of a bug introduced in b90740d.

This commit fixes #4 by selecting on both donec and connc of muxed
listeners.

Added a test case to guard against this issue.
2015-12-19 22:28:37 -05:00
Soheil Hassas Yeganeh
44439c27f0 Merge pull request #2 from tamird/update-readme-reasons
README: clarify why TLS is limited
2015-12-13 15:36:20 -05:00
Tamir Duberstein
4239e597d0 README: clarify why TLS is limited 2015-12-11 15:22:57 -05:00