Commit Graph

182 Commits

Author SHA1 Message Date
Yuxuan Li cb02ab4d25 change error message from InvalidArgument to ResourceExhausted 2017-04-13 16:51:56 -07:00
Yuxuan Li 8788b75675 merge master resolve conflicts 2017-04-13 16:28:15 -07:00
apolcyn 0e8b58d22f use proto.Buffer API for protobuf codec and cache proto.Buffer structs (#1010)
* use a global sharded pool of proto.Buffer caches in protoCodec

* fix goimports

* make global buffer pool index counter atomic

* hack to remove alloc in encode_len_struct

* remove extra slice alloc in proto codec marshal

* replce magic number for proto size field length with constant

* replace custom cache with sync.Pool

* remove 1 line functions in codec.go and add protoCodec microbenchmarks

* add concurrent usage test for protoCodec

* fix golint.gofmt,goimport checks

* fix issues in codec.go and codec_test.go

* use go parallel benchmark helpers

* replace proto.Codec with a guess of size needed

* update Fatalf -> Errorf in tests

* wrap proto.Buffer along with cached last size into larger struct for pool use

* make wrapped proto buffer only a literal

* fix style and imports

* move b.Run into inner function

* reverse micro benchmark op order to unmarshal-marshal and fix benchmark setup-in-test bug

* add test for large message

* remove use of defer in codec.marshal

* revert recent changes to codec bencmarks

* move sub-benchmarks into >= go-1.7 only file

* add commentfor marshaler and tweak benchmark subtests for easier usage

* move build tag for go1.7 on benchmarks to inside file

* move build tag to top of file

* comment Codec, embed proto.Buffer into cached struct and add an int32 cap
2017-04-12 20:35:59 -07:00
Yuxuan Li fa2968617c Merge branch 'master' into service_config_pr 2017-04-06 14:12:34 -07:00
Yuxuan Li 6f8b55318a fix the testMaxMsgSizeServerAPI failure 2017-04-06 14:08:04 -07:00
dfawley 1d27587e10 Change status package to deal with concrete types instead of interfaces (#1171) 2017-04-06 11:41:07 -07:00
lyuxuan f02290b023 Merge branch 'master' into service_config_pr 2017-04-05 11:15:55 -07:00
dfawley b507112439 Add status package for reporting gRPC status and errors (#1156)
When an error implemented by the status package is returned from a service
handler, the server will transmit a rich status message in the
"grpc-status-details-bin" trailing metadata field if any detailed data is
attached to the error.  Client-side, we will decode them if present in the
server's response and return them to the user code performing the RPC.

This is backward compatible with the existing errors supported by the grpc
package.  However, the grpc.Errorf, grpc.Code and grpc.ErrorDesc functions for
managing errors are now deprecated; status.Errorf and status.Status type
asserions should be used instead.
2017-04-05 10:35:40 -07:00
MakMukhi f45e6e3b30 Bug fix(Issue#1141): Check if peer is nil before trying to derefer it. (#1143) 2017-04-04 15:08:14 -07:00
Yuxuan Li 13b5f120b0 merge master 2017-04-03 15:20:13 -07:00
Yuxuan Li 50d4175072 Add client and service side apis for limiting the send/recv msg size. Update MethodConfig struct 2017-04-03 15:03:24 -07:00
Menghan Li 14a6be430b Add grpc.Version string and use it in the UA (#1144) 2017-03-24 11:29:02 -07:00
Tamir Duberstein 9871e09f09
Use codes.Code.String() rather than logging integers
This produces better human-readable error messages.
2017-02-27 14:13:02 -05:00
Yuxuan Li 6810d34606 fix issue #1056 and #1050 2017-02-13 17:37:53 -08:00
Mahak Mukhi dfb494c6e5 post review update 2017-02-08 14:15:59 -08:00
Mahak Mukhi 66de296a37 post review update 2017-02-07 14:46:28 -08:00
Mahak Mukhi 794873f0a2 Added calloption to retrieve peer information 2017-02-07 10:41:32 -08:00
Mark D. Roth 6e0ace39fe Change max message size fields from uint64 to uint32. 2017-01-26 14:43:08 -08:00
Mark D. Roth 325a0c2061 Update comment. 2017-01-09 12:59:10 -08:00
Qi Zhao 09aecb094e Add the initial service config support (#1009)
* Add the initial service config support

* start scWatcher later

* remove timeoutCh

* address the comments

* deal with dial timeout

* defer cancel for the newly created context for correct lifetime management

* fix the defer order

* added other 2 missing cancels
2016-12-19 16:31:00 -08:00
Menghan Li 3f9a96ea71 move inPayload.RecvTime to after unmarshal 2016-11-07 16:29:25 -08:00
Menghan Li 5938492b60 fix comments 2016-11-07 15:16:52 -08:00
Menghan Li a4edc462a2 renaming 2016-11-07 15:16:52 -08:00
Menghan Li c698588285 Renaming types and variables 2016-11-07 15:16:52 -08:00
Menghan Li 1054f1c42b add payload with original type to payload stats 2016-11-07 15:16:52 -08:00
Menghan Li 17ee5a3637 Add package stats, and export stats on server side. 2016-11-07 15:16:52 -08:00
Mak Mukhi 727a60e4d1 update server reflection code to comply with the change to the grpc generator 2016-10-21 18:06:55 -07:00
Menghan Li 5e734ab23e Avoid creating transport stream error outside of transport 2016-09-02 11:57:42 -07:00
iamqizhao fc500c24f6 fix go vet error 2016-07-29 18:08:00 -07:00
iamqizhao b13920a0cf add the mem alloc guard on server 2016-07-29 16:19:20 -07:00
iamqizhao 8c908a8c1d Reject over-sized requests on server 2016-07-26 16:44:49 -07:00
Menghan Li ffdfb592e8 Fix type assertion error after rebase 2016-07-08 10:35:38 -07:00
Daniel Ruehle 3802318f46 Make Errorf return pointer to rpcError 2016-07-08 10:28:36 -07:00
iamqizhao be59d023f2 refactor error handling a bit 2016-06-29 15:21:44 -07:00
iamqizhao 213a20c4fe bug fix, typo fix and slight error refactoring 2016-06-28 16:08:19 -07:00
iamqizhao 01ef81a4d9 minor fix including removal of debugging logs, error code fix, etc. 2016-06-27 15:30:20 -07:00
iamqizhao 3e71fb360d Support fail-fast mode and make it the default 2016-06-27 14:36:59 -07:00
Menghan Li cf04b299b7 Change SupportPackageIsVersion variable 2016-06-10 11:48:20 -07:00
joe2far 487ada6517 Fixed typos in docstrings 2016-06-07 12:01:07 +01:00
iamqizhao e0f9f26e85 remove the checking of empty string for recvCompress 2016-05-11 11:01:26 -07:00
iamqizhao b506f13d5b change the error code when the required decompressor is not installed 2016-05-11 10:46:23 -07:00
iamqizhao 113bf2f219 Change some compression related error code 2016-05-10 13:54:10 -07:00
iamqizhao 61e92eacc3 Phase 1 to add the server interceptor 2016-04-18 16:18:34 -07:00
Qi Zhao d07d0562ff Merge pull request #601 from stevvooe/backoff-strategy
backoff: allow configuration of backoff strategy
2016-04-11 10:32:33 -07:00
Stephen J Day 47b74a63a8 backoff: allow configuration of backoff strategy
The backoff function and parameters have been pulled up into an
interface `backoffStrategy`. The default parameters are now part of a
package variable `DefaultBackoffConfig`. The strategy is then plumbed
through `dialOptions`. As a result of this PR, the
maximum backoff delay can now be set using the `WithBackoffConfig` dial
option.

While the addition of strategy may seem premature, this allows one to
simply export `BackoffStrategy` and `WithBackoff` to allow arbirarily
configurable backoff strategies.

Signed-off-by: Stephen J Day <stephen.day@docker.com>
2016-04-07 20:17:57 -07:00
Menghan Li 71e3dbec56 Use ErrorDetail() to provide better error msg for malformed HTTP2 2016-03-28 11:34:29 -07:00
David Symonds 710dbc764f Prepare for adding a compatibility marker to proto generated code.
This will assert at build time that the generated code is compatible
with the grpc package that it is linked to. A future change in the
grpc plugin for protoc-gen-go will generate a line like
	const _ = grpc.SupportPackageIsVersion1

This constant will be renamed in the future when incompatible changes
are made that require synchronised updates to grpc and protoc-gen-go.
2016-03-07 10:12:28 +11:00
Brad Fitzpatrick 110fd99e30 Fix crashes where transports returned errors unhandled by the message parser.
The http.Handler-based transport body reader was returning error types
not understood by the recvMsg parser. See #557 for some background and
examples.

Fix the http.Handler transport and add tests. I copied in a subset of
the http2 package's serverTest type, adapted slightly to work with
grpc. In the process of adding tests, I discovered that
ErrUnexpectedEOF was also not handled by the regular server
transport. Document the rules and fix that crash as well.

Unrelated stuff in this CL:

* make tests listen on localhost:0 instead of :0, to avoid Mac firewall
  pop-up dialogs.

* rename parser.s field to parser.r, to be more idiomatic that it's an
  io.Reader and not anything fancier. (it's not acting like type
  stream, even if that's the typical concrete type)

* move 5 byte temp buffer into parser, rather than allocating it for
  each new message. (drop in the bucket improvement in garbage; more
  to do later)

* rename http2RSTErrConvTab to http2ErrConvTab, per Qi's earlier
  CL. Also add the HTTP/1.1-required error mapping for completeness,
  not that it should ever arise with gRPC, also per Qi's earlier CL
  referenced in #557.
2016-02-24 15:09:17 -08:00
Brad Fitzpatrick 7346c871b0 Add a ServeHTTP method to *grpc.Server
This adds new http.Handler-based ServerTransport in the process,
reusing the HTTP/2 server code in x/net/http2 or Go 1.6+.

All end2end tests pass with this new ServerTransport.

Fixes grpc/grpc-go#75

Also:
Updates grpc/grpc-go#495 (lets user fix it with middleware in front)
Updates grpc/grpc-go#468 (x/net/http2 validates)
Updates grpc/grpc-go#147 (possible with x/net/http2)
Updates grpc/grpc-go#104 (x/net/http2 does this)
2016-02-12 00:16:28 +00:00
iamqizhao af8888dc8d remove Compressor/DecompressorGenerator 2016-01-29 14:38:20 -08:00
iamqizhao 61d7c39d4c comments and gofmt 2016-01-25 11:18:41 -08:00
iamqizhao da3bb0c9f7 Support compression 2016-01-22 18:21:41 -08:00
iamqizhao ea6e7189de Move callInfo into the right position 2016-01-07 14:44:36 -08:00
Justin Nuß da435e3a08 Keep length as uint for overflow check 2015-10-22 12:21:04 +02:00
Justin Nuß cbdc43cf9a Fix variable name in comment 2015-10-21 20:47:16 +02:00
Justin Nuß 20ed1e924e Replace bytes.Buffer with properly sized []byte in encode 2015-10-21 20:47:16 +02:00
iamqizhao 984280ba37 change the type of length 2015-10-15 13:22:54 -07:00
iamqizhao 61c1259226 some cleanup 2015-10-15 10:59:39 -07:00
David Symonds d3cb35a50a Fix decoding of message headers for messages with lengths >= 2^24.
recvMsg was interpreting buf[1] as the payload format instead of buf[0];
since compressionNone (the only thing supported) == 0, recvMsg got lucky
for message lengths under 2^24, which has buf[1] == 0.

Fix the error, and ditch the constants in recvMsg. I think they were the
cause of the bug.

Also make encode fail more clearly if someone tries to transmit a
message that exceeds 2^32 bytes.

Fixes #399.
2015-10-15 18:56:48 +11:00
Qi Zhao 6c8d213d08 Merge pull request #385 from nuss-justin/master
Avoid some allocations in recvMsg
2015-10-06 22:39:18 -07:00
Justin Nuß e2cb78fabb Combine const declarations into one block 2015-10-07 06:37:58 +02:00
iamqizhao e63d714a45 fix the wrong reference link 2015-10-06 16:05:45 -07:00
Justin Nuß 5165699f37 Define constants for header size and format index 2015-10-06 20:53:17 +02:00
Justin Nuß 95d129f7d8 Remove unnecessary uint8 conversion 2015-10-06 06:32:01 +02:00
Justin Nuß c9fdfdd500 Avoid some allocations in recvMsg
Reading the header by hand avoids some allocations and improves the
performance of recvMsg.

benchmark                              old ns/op     new ns/op     delta
BenchmarkClientStreamc1-8              125267        110733        -11.60%
BenchmarkClientStreamc8-8              21561         20971         -2.74%
BenchmarkClientStreamc64-8             13573         12825         -5.51%
BenchmarkClientStreamc512-8            13937         13300         -4.57%
BenchmarkClientUnaryc1-8               223208        257968        +15.57%
BenchmarkClientUnaryc8-8               46168         45618         -1.19%
BenchmarkClientUnaryc64-8              33740         33038         -2.08%
BenchmarkClientUnaryc512-8             33137         32663         -1.43%
BenchmarkClientStreamNoTracec1-8       115559        107506        -6.97%
BenchmarkClientStreamNoTracec8-8       20853         20376         -2.29%
BenchmarkClientStreamNoTracec64-8      12119         11935         -1.52%
BenchmarkClientStreamNoTracec512-8     13087         12479         -4.65%
BenchmarkClientUnaryNoTracec1-8        225577        244701        +8.48%
BenchmarkClientUnaryNoTracec8-8        42211         41884         -0.77%
BenchmarkClientUnaryNoTracec64-8       30313         29655         -2.17%
BenchmarkClientUnaryNoTracec512-8      29914         29637         -0.93%

benchmark                              old allocs     new allocs     delta
BenchmarkClientStreamc1-8              46             40             -13.04%
BenchmarkClientStreamc8-8              47             41             -12.77%
BenchmarkClientStreamc64-8             46             40             -13.04%
BenchmarkClientStreamc512-8            46             40             -13.04%
BenchmarkClientUnaryc1-8               100            91             -9.00%
BenchmarkClientUnaryc8-8               100            91             -9.00%
BenchmarkClientUnaryc64-8              100            91             -9.00%
BenchmarkClientUnaryc512-8             96             88             -8.33%
BenchmarkClientStreamNoTracec1-8       42             36             -14.29%
BenchmarkClientStreamNoTracec8-8       43             37             -13.95%
BenchmarkClientStreamNoTracec64-8      42             36             -14.29%
BenchmarkClientStreamNoTracec512-8     42             36             -14.29%
BenchmarkClientUnaryNoTracec1-8        87             78             -10.34%
BenchmarkClientUnaryNoTracec8-8        87             78             -10.34%
BenchmarkClientUnaryNoTracec64-8       87             78             -10.34%
BenchmarkClientUnaryNoTracec512-8      84             77             -8.33%

benchmark                              old bytes     new bytes     delta
BenchmarkClientStreamc1-8              2015          1919          -4.76%
BenchmarkClientStreamc8-8              2016          1920          -4.76%
BenchmarkClientStreamc64-8             2015          1919          -4.76%
BenchmarkClientStreamc512-8            2007          1901          -5.28%
BenchmarkClientUnaryc1-8               5981          5837          -2.41%
BenchmarkClientUnaryc8-8               5980          5837          -2.39%
BenchmarkClientUnaryc64-8              5956          5813          -2.40%
BenchmarkClientUnaryc512-8             5743          5611          -2.30%
BenchmarkClientStreamNoTracec1-8       1887          1791          -5.09%
BenchmarkClientStreamNoTracec8-8       1888          1792          -5.08%
BenchmarkClientStreamNoTracec64-8      1916          1789          -6.63%
BenchmarkClientStreamNoTracec512-8     1894          1811          -4.38%
BenchmarkClientUnaryNoTracec1-8        4301          4158          -3.32%
BenchmarkClientUnaryNoTracec8-8        4301          4157          -3.35%
BenchmarkClientUnaryNoTracec64-8       4282          4140          -3.32%
BenchmarkClientUnaryNoTracec512-8      4131          4077          -1.31%
2015-10-05 19:52:11 +02:00
Michal Witkowski 1a7cf7f696 fix difference between unitary and stream codec error handling 2015-10-03 18:43:53 +01:00
Qi Zhao 04b80892a6 Revert "fix difference between unitary and stream codec error handling" 2015-10-02 14:07:05 -07:00
Michal Witkowski 594f4bf133 fix difference between unitary and stream codec error handling 2015-10-01 17:37:17 +01:00
iamqizhao 35df01a371 rename Desc to ErrorDesc 2015-09-22 17:00:48 -07:00
iamqizhao 39130707bd add accessor for the error desc of rpcError 2015-09-22 16:39:14 -07:00
iamqizhao e35bf02914 revise reconnect backoff strategy 2015-07-28 11:12:07 -07:00
iamqizhao 6682b35fb6 return codes.OK for nil error 2015-04-15 11:42:35 -07:00
iamqizhao 8b08b2d7b2 Interface change to accommodate the support of non-protobuf data formats 2015-03-25 15:18:07 -07:00
iamqizhao e10de7abd1 fix some bugs 2015-03-13 00:16:18 -07:00
iamqizhao 7efb0d7d75 fix a comment 2015-03-04 19:10:21 -08:00
iamqizhao 757a7ce4cb remove err checking because bytes.Buffer.Write and bytes.Buffer.WriteByte always return nil 2015-03-04 00:50:30 -08:00
Matt T. Proud c91d17acf1 Benchmark encode and cut encoding inefficiency.
This commit introduces the first microbenchmark for grpc, wherein
`encode` is benchmarked according to message size.  A conclusion of
the benchmark is that the removal of type switching found in
`binary.Write`, which is used in `encode` produces the following
encoding time and memory allocation footprint:

```
$ # Return to previous commit but benchmark.
$ go test ./... -test.bench="Benchmark*" > /tmp/before
$ # Return to working copy.
$ go test ./... -test.bench="Benchmark*" > /tmp/after
$ benchcmp /tmp/before /tmp/after
benchmark                 old ns/op     new ns/op     delta
BenchmarkEncode1B         1282          936           -26.99%
BenchmarkEncode1KiB       4865          4184          -14.00%
BenchmarkEncode8KiB       22686         21560         -4.96%
BenchmarkEncode64KiB      134451        116762        -13.16%
BenchmarkEncode512KiB     514044        361224        -29.73%
BenchmarkEncode1MiB       767096        636725        -17.00%

benchmark                 old MB/s     new MB/s     speedup
BenchmarkEncode1B         6.24         8.55         1.37x
BenchmarkEncode1KiB       212.11       246.63       1.16x
BenchmarkEncode8KiB       361.46       380.33       1.05x
BenchmarkEncode64KiB      487.50       561.35       1.15x
BenchmarkEncode512KiB     1019.94      1451.45      1.42x
BenchmarkEncode1MiB       1366.95      1646.84      1.20x

benchmark                 old allocs     new allocs     delta
BenchmarkEncode1B         6              3              -50.00%
BenchmarkEncode1KiB       8              5              -37.50%
BenchmarkEncode8KiB       8              5              -37.50%
BenchmarkEncode64KiB      8              5              -37.50%
BenchmarkEncode512KiB     8              5              -37.50%
BenchmarkEncode1MiB       8              5              -37.50%

benchmark                 old bytes     new bytes     delta
BenchmarkEncode1B         384           328           -14.58%
BenchmarkEncode1KiB       2816          2760          -1.99%
BenchmarkEncode8KiB       17283         17227         -0.32%
BenchmarkEncode64KiB      147856        147802        -0.04%
BenchmarkEncode512KiB     1065344       1065288       -0.01%
BenchmarkEncode1MiB       2113920       2113864       -0.00%
```

..., which is apropos of the comment in [encoding/binary]
(http://golang.org/pkg/encoding/binary), wherein ...

> This package favors simplicity over efficiency.

... is stated.

If `encode` is deemed to need further memory efficiencies, a mechanism
whereby a `proto.Buffer` is retained may be warranted, which is why the
original TODO remains.  The proposed improvement in this change is
simple and low-hanging.

I did not want to introduce yet-another protocol buffer message for
tests, but the ones under ...

> interop/grpc_testing/test.proto
> test/grpc_testing/test.proto

... have a fundamental dependency on `grpc` package due to their
generated stubs, which produces a cycle in the imports if the benchmark
were to attempt to import them for profiling.  The newly created ...

> test/grpc_message/test.proto

... protocol buffer package has no generated RPC service stubs, which
means it can be imported into the `grpc` package root without cycle.
2015-03-03 09:42:00 +01:00
Matt T. Proud a720ae6f48 Make error conveyance more idiomatic.
This commit applies two bulk changes to the grpc error reporting
mechanisms:

(1.) Error strings for errors that originate within grpc are prefixed
    with the package name for better clarity for where they originate
    since they could percolate up in the users call chains to the
    originator.

(2.) Errors that are, in fact, singletons have been converted from
    fmt.Errorf to errors.New and assigned as package-level variables.
    This bodes particularly well for enabling API customers to elect to
    handle these errors upon receipt via equality comparison.  This had
    been previous impossible with the original API.

Supplementarily, ``gofmt -w -s=true`` has been run on the repository to
cleanup residual defects, and it has detected and repaired a few.

TEST=Manual go test ./...
2015-02-19 13:17:17 +01:00
iamqizhao 634392a1c6 Remove the 2nd RecvProto in the generated code for client streaming 2015-02-18 22:18:01 -08:00
David Symonds 416f68f4b3 Update import paths to use the new official location of the Go gRPC package. 2015-02-09 11:46:20 +11:00
David Symonds 9e789c396b Rename top level package from "rpc" to "grpc".
Also move the nascent package doc to doc.go.
2015-02-09 11:45:33 +11:00
David Symonds e71095e0ec Move source files up one level.
The top-level directory in this repository is going to be
the main "grpc" package.
2015-02-09 11:33:38 +11:00