2
0
mirror of https://github.com/soheilhy/cmux.git synced 2024-11-14 11:31:28 +08:00
Commit Graph

98 Commits

Author SHA1 Message Date
Jingguo Yao
885b8d8a14 doc: fix a typo 2017-05-22 20:38:03 +08:00
Soheil Hassas Yeganeh
0068a46c9c Merge pull request #45 from soheilhy/fix-44
Eliminate blocking reads in the HTTP2 matcher.
2017-04-24 21:57:51 -04:00
Soheil Hassas Yeganeh
6a5d332559 Remove Go 1.5 from travis builds.
gRPC doesn't support Go 1.5 anymore, and the build would
fail if we keep testing with Go 1.5.
2017-04-24 21:45:35 -04:00
Soheil Hassas Yeganeh
c0f3570a02 Eliminate blocking reads in the HTTP2 matcher.
The HTTP2 matcher uses io.ReadFull to read the client preface.
If the client sends a string shorter than the preface (e.g.,
SSL version) io.ReadFull will block.

Replace io.ReadFull with Read and assume partial reads will not
match

Fixes #44
2017-04-23 00:08:19 -04:00
Soheil Hassas Yeganeh
b6ec57c1a4 Merge pull request #43 from soheilhy/dev/go18
Fix tests for Go 1.8+
2017-03-13 10:17:15 -04:00
Soheil Hassas Yeganeh
79b9df6ccf Add Go 1.8 to the travis config. 2017-03-13 09:57:57 -04:00
Soheil Hassas Yeganeh
210139db95 Change connection closed string in tests.
Go 1.8 and 1.9 use different text for the connection closed error.
Use their common prefix (i.e., "use of closed") in the tests for
them to pass on all Go versions.

Go 1.8: "use of closed network connection"
Go 1.9: "use of closed file or network connection"

Suggested-by: Damien Neil <dneil@google.com>
2017-03-13 09:57:57 -04:00
Soheil Hassas Yeganeh
bf4a8ede9e Merge pull request #36 from soheilhy/dev/fix-mem-grow
Fix memory growth
2016-09-25 21:07:37 -04:00
Soheil Hassas Yeganeh
f661dcfb59 Reset the sniffing buffer when not needed
The sniffing buffer will live as long as the connection is open,
and we should reset it as soon as the application has read all the
sniffed data.
2016-09-25 20:56:09 -04:00
Soheil Hassas Yeganeh
526b64db7a update the list of contributors. 2016-09-25 01:03:35 -04:00
Soheil Hassas Yeganeh
3ac8d3a667 Fix lint errors in cmux_test.go 2016-09-25 00:58:27 -04:00
Soheil Hassas Yeganeh
861c99e0fc Return not-match on different field values in HTTP2
Retun as soon as we have the matched field in the HTTP2 matcher
regardless of weather the value is matched or not. Fixes #35.

Issue #35 reports that cmux leaks memory when the client is HTTP2
but does not sends the expected header field. For example, when
the non-gRPC client sends a large field in the header and we are
matching for gRPC, we waste a lot of memory in the sniff buffer.
2016-09-25 00:58:17 -04:00
Soheil Hassas Yeganeh
13f520d62c Merge pull request #34 from ekle/master
SetReadDeadline for Matching
2016-09-05 16:05:55 -04:00
Andreas Jaekle
e132036cce SetReadDeadline for Matching 2016-09-05 19:56:50 +02:00
Soheil Hassas Yeganeh
b26951527b Merge pull request #33 from soheilhy/fix-b32
Fix index out of range in patricia tree
2016-07-15 11:38:34 -07:00
Soheil Hassas Yeganeh
eddb3b1467 Fix index out of range in patricia tree
Bug #32 reported that there is an index out of range error. This
issue was introduced in 703b087.

Fix #32 and add a test to detect this issue
2016-07-15 10:01:37 -07:00
Soheil Hassas Yeganeh
e85da3027e Merge pull request #30 from soheilhy/fix-patricia-tree
Fix race in patricia tree
2016-07-15 08:04:18 -07:00
Tamir Duberstein
df31d48636 Parallelize benchmarks 2016-07-14 22:03:14 -07:00
Soheil Hassas Yeganeh
fd01d3cc6c Fix race in patricia tree
This commit fixes a major issue added in 703b087a.

There are still wins on allocation though.

benchmark                      old ns/op     new ns/op     delta
BenchmarkCMuxConnHTTP1-4       783           836           +6.77%
BenchmarkCMuxConnHTTP2-4       895           806           -9.94%
BenchmarkCMuxConnHTTP1n2-4     1000          1026          +2.60%
BenchmarkCMuxConnHTTP2n1-4     916           961           +4.91%

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

benchmark                      old bytes     new bytes     delta
BenchmarkCMuxConnHTTP1-4       272           280           +2.94%
BenchmarkCMuxConnHTTP2-4       304           304           +0.00%
BenchmarkCMuxConnHTTP1n2-4     304           312           +2.63%
BenchmarkCMuxConnHTTP2n1-4     304           312           +2.63%
2016-07-14 22:01:30 -07:00
Soheil Hassas Yeganeh
f952454ed9 Add the list of contributors
Add the list of contributors in a separate file and add links
to the LICENSE and CONTRIBUTORS files.

Fixes #28
2016-07-09 14:07:27 -04:00
Soheil Hassas Yeganeh
00342b4d79 Add package level docs 2016-07-09 14:01:24 -04:00
Soheil Hassas Yeganeh
cd9b7d74b9 Add copyright notice headers on all Go files.
As per http://www.apache.org/legal/src-headers.html#headers

Fixes #28
2016-07-09 13:56:02 -04:00
Soheil Hassas Yeganeh
9d1e2a64dd Merge pull request #25 from soheilhy/devel-optimize-patricia
Optimize Patricia tree
2016-05-03 22:33:52 -04:00
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