Commit Graph

765 Commits

Author SHA1 Message Date
Jakob Buchgraber 8c18a0d355 netty: use custom http2 headers for decoding.
The DefaultHttp2Headers class is a general-purpose Http2Headers implementation
and provides much more functionality than we need in gRPC. In gRPC, when reading
headers off the wire, we only inspect a handful of them, before converting to
Metadata.

This commit introduces a Http2Headers implementation that aims for insertion
efficiency, a low memory footprint and fast conversion to Metadata.

  - Header names and values are stored in plain byte[].
  - Insertion is O(1), while lookup is now O(n).
  - Binary header values are base64 decoded as they are inserted.
  - The byte[][] returned by namesAndValues() can directly be used to construct
    a new Metadata object.
  - For HTTP/2 request headers, the pseudo headers are no longer carried over to
    Metadata.

A microbenchmark aiming to replicate the usage of Http2Headers in NettyClientHandler
and NettyServerHandler shows decent throughput gains when compared to DefaultHttp2Headers.

Benchmark                                             Mode  Cnt     Score    Error  Units
InboundHeadersBenchmark.defaultHeaders_clientHandler  avgt   10   283.830 ±  4.063  ns/op
InboundHeadersBenchmark.defaultHeaders_serverHandler  avgt   10  1179.975 ± 21.810  ns/op
InboundHeadersBenchmark.grpcHeaders_clientHandler     avgt   10   190.108 ±  3.510  ns/op
InboundHeadersBenchmark.grpcHeaders_serverHandler     avgt   10   561.426 ±  9.079  ns/op

Additionally, the memory footprint is reduced by more than 50%!

gRPC Request Headers: 864 bytes
Netty Request Headers: 1728 bytes
gRPC Response Headers: 216 bytes
Netty Response Headers: 528 bytes

Furthermore, this change does most of the gRPC groundwork necessary to be able
to cache higher ordered objects in HPACK's dynamic table, as discussed in [1].

[1] https://github.com/grpc/grpc-java/issues/2217
2016-09-09 23:15:18 +02:00
Carl Mastrangelo e79a27dec3 core: fix a javadoc bug in ClientCall 2016-09-09 13:33:00 -07:00
Carl Mastrangelo 35c3f8171b core/internal: replace make Stream id a primitive 2016-09-08 17:39:51 -07:00
Xiao Hang c69a4b8f19 core: add a new option to MethodDescriptor for caching support 2016-09-08 16:53:51 -07:00
Eric Anderson bdf8b01129 core,protobuf: Add simple argument introspection for methods
The cast required in protobuf makes me question how much I like
ReflectableMarshaller, but it seems to be pretty sound and the cast is
more an artifact of generics than the API.

Nano and Thrift were purposefully not updated, since getting just the
class requires making a new message instance. That seems a bit lame. It
probably is no burden to create an instance to get the class, and it may
not be too hard to improve the factory to provide class information, but
didn't want to bother at this point. Especially since nano users are
unlikely to need the introspection functionality.
2016-09-08 11:05:16 -07:00
Carl Mastrangelo f78644d762 core: add Metadata.discardAll()
Metadata.removeAll creates an iterator for looking through removed
values even if the call doens't use it.  This change adds a similar
method which doesn't create garbage.

This change makes it easier in the future to alter the internals
of Metadata where it may be expensive to return removed values.
2016-09-08 10:29:22 -07:00
Carl Mastrangelo 5379de726d core: fix indentation in MethodDescriptor 2016-09-07 17:40:21 -07:00
Carl Mastrangelo ca5a402fe6 netty: cache method path conversion
Benchmark                                      Mode      Cnt   Score   Error  Units
MethodDescriptorBenchmark.direct             sample  1179094  43.483 ± 0.610  ns/op
MethodDescriptorBenchmark.old                sample  1079285  66.210 ± 5.402  ns/op
MethodDescriptorBenchmark.transportSpecific  sample  1408070  36.800 ± 0.423  ns/op
2016-09-07 14:41:02 -07:00
Carl Mastrangelo 893ef44b4c all/tests: add a ClientCall and ServerCall suitable for use in tests 2016-09-02 17:09:49 -07:00
Carl Mastrangelo ea3f506249 core: avoid allocating Iterators in EquivalentAddressGroup, which is called for each new RPC
Benchmarked with 3 runs of 4 forks
Before:
Benchmark                         (direct)  (transport)    Mode     Cnt       Score     Error  Units
TransportBenchmark.unaryCall1024      true        NETTY  sample  255593  156248.670 ± 563.514  ns/op
Benchmark                         (direct)  (transport)    Mode     Cnt       Score     Error  Units
TransportBenchmark.unaryCall1024      true        NETTY  sample  261443  152753.415 ± 500.957  ns/op
Benchmark                         (direct)  (transport)    Mode     Cnt       Score     Error  Units
TransportBenchmark.unaryCall1024      true        NETTY  sample  258978  154205.374 ± 453.808  ns/op

After:
Benchmark                         (direct)  (transport)    Mode     Cnt       Score     Error  Units
TransportBenchmark.unaryCall1024      true        NETTY  sample  262194  152313.101 ± 502.563  ns/op
Benchmark                         (direct)  (transport)    Mode     Cnt       Score     Error  Units
TransportBenchmark.unaryCall1024      true        NETTY  sample  264811  150809.474 ± 477.459  ns/op
Benchmark                         (direct)  (transport)    Mode     Cnt       Score     Error  Units
TransportBenchmark.unaryCall1024      true        NETTY  sample  263606  151501.729 ± 593.149  ns/op
2016-09-02 15:48:23 -07:00
Kun Zhang c4f7f5c4fd core: split Context into a separate grpc-context artifact.
The Context API is not particularly gRPC-specific, and will be used by
Census as its context propagation mechanism.

Removed all dependencies to make it easy for other libraries to depend
on.
2016-09-02 13:18:35 -07:00
Kun Zhang 58d78dd0aa core: add ServerTransportFilter
Called whenever a ServerTransport is ready and terminated.  Has the
ability to modify transport attributes, which ServerCall.attributes()
are based on.

Related changes:

- Attribute keys for remote address and SSL session are now moved from
ServerCall to a neutral place io.grpc.Grpc, because they can also be
used from ServerTransportFilter, and probably will be used on the
client-side too.  The old keys on ServerCall is marked deprecated and
are equivalent to the new keys.
- Added transportReady() to ServerTransportListener.

Resolves #2132
2016-08-31 14:45:15 -07:00
Carl Mastrangelo 48c6b3d398 all/tests: unmock ClientCall and ServerCall 2016-08-30 09:58:02 -07:00
Carl Mastrangelo 3bf8d94f02 core/tests: add missing RunWith annotation 2016-08-29 12:53:52 -07:00
Carl Mastrangelo 6d28a93e21 core: simplify timeout header processing
Changes slightly improve performance

Benchmark                    (serialized)    Mode     Cnt    Score    Error  Units
GrpcUtilBenchmark.encodeNew         1000n  sample  336623   51.718 ±  1.417  ns/op
GrpcUtilBenchmark.encodeNew         1000u  sample  236574   77.555 ± 20.875  ns/op
GrpcUtilBenchmark.encodeNew         1000m  sample  224392   71.155 ±  1.600  ns/op
GrpcUtilBenchmark.encodeNew         1000S  sample  229616   67.269 ±  2.037  ns/op
GrpcUtilBenchmark.encodeNew         1000M  sample  215301   70.282 ±  1.933  ns/op
GrpcUtilBenchmark.encodeNew         1000H  sample  225063   73.679 ± 20.430  ns/op
GrpcUtilBenchmark.encodeOld         1000n  sample  311832   85.519 ±  1.729  ns/op
GrpcUtilBenchmark.encodeOld         1000u  sample  291613   92.320 ±  1.732  ns/op
GrpcUtilBenchmark.encodeOld         1000m  sample  271871   93.447 ±  1.872  ns/op
GrpcUtilBenchmark.encodeOld         1000S  sample  234932  117.956 ± 16.810  ns/op
GrpcUtilBenchmark.encodeOld         1000M  sample  224636  124.310 ± 20.249  ns/op
GrpcUtilBenchmark.encodeOld         1000H  sample  226764  130.803 ± 19.211  ns/op
GrpcUtilBenchmark.parseNew          1000n  sample  320709   60.480 ±  1.303  ns/op
GrpcUtilBenchmark.parseNew          1000u  sample  316349   64.447 ± 13.673  ns/op
GrpcUtilBenchmark.parseNew          1000m  sample  318209   61.705 ±  2.580  ns/op
GrpcUtilBenchmark.parseNew          1000S  sample  319629   59.342 ±  1.758  ns/op
GrpcUtilBenchmark.parseNew          1000M  sample  305715   59.362 ±  1.489  ns/op
GrpcUtilBenchmark.parseNew          1000H  sample  314919   60.224 ±  1.563  ns/op
GrpcUtilBenchmark.parseOld          1000n  sample  279243   64.040 ±  1.510  ns/op
GrpcUtilBenchmark.parseOld          1000u  sample  278008   71.313 ± 13.620  ns/op
GrpcUtilBenchmark.parseOld          1000m  sample  272633   67.872 ±  2.967  ns/op
GrpcUtilBenchmark.parseOld          1000S  sample  280955   63.966 ±  2.490  ns/op
GrpcUtilBenchmark.parseOld          1000M  sample  257645   71.329 ±  2.117  ns/op
GrpcUtilBenchmark.parseOld          1000H  sample  282510   68.425 ± 17.650  ns/op
2016-08-26 17:32:41 -07:00
Eric Anderson 656e8ce37f core: Remove com.google.common.collect usages for Android
This reduces the number of methods gRPC brings in by ~450, which is
substantial. Each application will see different numbers though,
depending on their usage and their other dependencies.

A very rough (under) counting for number of methods included because of
gRPC in android-interop-test is 2746, and that is reduced to 2313 (-433)
by this change. That count includes grpc, guava, okhttp, okio, and nano.
The actual reduction of methods is 447, with the discrepency due to
reduction of methods in java.util and java.lang. Of the 433 removed
methods, 377 are from com.google.common.collect and 61 from
com.google.common.base. The removal costed an increase of 5 methods
(total 1671) within io.grpc itself.
2016-08-26 15:13:45 -07:00
Carl Mastrangelo 7c847acf57 core: clarify EOS dataframe error came from server 2016-08-25 17:59:29 -07:00
Lukasz Strzalkowski 864158bdfb core: add tests for ResolvedServerInfo 2016-08-25 16:11:40 -07:00
Carl Mastrangelo 26a08cd75e core: add DoNotMock annotations 2016-08-25 11:14:43 -07:00
Kun Zhang 7909abf065 core: remove unused code path.
writeKnownLength() is never called with compressed == true, because in
most cases it's impossible to know the size of the compressed message.
2016-08-24 15:38:49 -07:00
Lukasz Strzalkowski 23652c5b03 core: change API of NameResolver#onUpdate
Instead of `List<List<ResolvedServerInfo>>`, `onUpdate` now takes
`List<ResolvedServerInfoGroup>` as an argument and every `ResolvedServerInfoGroup`
object can have `Attributes` attached to it which means that we can provide
attributes on each level:

  * root level via `onUpdate` argument (applies to all servers)
  * group level via property of `ResolvedServerInfoGroup` (applies to all servers
    in the group)
  * host level via property of `ResolvedServerInfo` (applies to a single server)
2016-08-24 15:14:57 -07:00
Lukasz Strzalkowski 577164c42f Rename Dummy load balancer to PickFirst 2016-08-23 09:15:56 -07:00
Lukasz Strzalkowski 5345be2ba0 core: Add equals/hashCode
Defines equality conditions for `Attributes` and `ResolvedServerInfo`.
2016-08-23 09:07:41 -07:00
Carl Mastrangelo c47d948a47 protobuf: copy input data before decoding
CodedInputStream is risk averse in ways that hurt performance when
parsing large messages.  gRPC knows how large the input size is as it
is being read from the wire, and only tries to parse it once the entire
message has been read in.  The message is represented as chunks of
memory strung together in a CompositeReadableBuffer, and then wrapped
in a custom BufferInputStream.

When passed to Protobuf, CodedInputStream attempts to read data out
of this InputStream into CIS's internal 4K buffer.  For messages that
are much larger, CIS copies from the input in chunks of 4K and saved in
an ArrayList.  Once the entire message size is read in, it is re-copied
into one large byte array and passed back up.  This only happens for
ByteStrings and ByteBuffers that are read out of CIS.  (See
CIS.readRawBytesSlowPath for implementation).

gRPC doesn't need this overhead, since we already have the entire
message in memory, albeit in chunks.  This change copies the composite
buffer into a single heap byte buffer, and passes this (via
UnsafeByteOperations) into CodedInputStream.  This pays one copy to
build the heap buffer, but avoids the two copes in CIS.  This also
ensures that the buffer is considered "immutable" from CIS's point of
view.

Because CIS does not have ByteString aliasing turned on, this large
buffer will not accidentally be kept in memory even if only tiny fields
from the proto are still referenced.  Instead, reading ByteStrings out
of CIS will always copy.  (This copy, and the problems it avoids, can
be turned off by calling CIS.enableAliasing.)

Benchmark results will come shortly, but initial testing shows
significant speedup in throughput tests.  Profiling has shown that
copying memory was a large time consumer for messages of size 1MB.
2016-08-17 15:45:21 -07:00
Carl Mastrangelo 1285477133 all: add parameter name to checkNotNull
After debugging #2153, it would have been nice to know what the exact
parameter was that was null. This change adds a name for each
checkNotNull (and tries to normalized on static imports in order to
shorten lines)
2016-08-12 14:55:00 -07:00
Kun Zhang 7a33fae8e8 core: fix a deadlock in TransportSet.
Resolves #2152
2016-08-10 09:47:25 -07:00
Eric Anderson c8648dc54e core: Remove usage of LogExceptionRunnable from Deadline
io.grpc should not be depending on anything from internal. Also, the
convenience method of Deadline is part of our public API and shouldn't
use LogExceptionRunnable because it would surprise our users.

Swapped to lower-case 'log' since the logger is not immutable.
2016-08-09 14:02:45 -07:00
Carl Mastrangelo 5384f9706a core: propagate name resolution errors 2016-08-08 17:53:58 -07:00
Eric Anderson 7c44a4e111 docs: Clarify the relationship between Status*Exception 2016-08-04 15:33:31 -07:00
Eric Anderson d394cef775 core: Avoid wrapping Errors in RuntimeException 2016-08-04 14:25:40 -07:00
Eric Anderson 7d464fcb02 inprocess: Avoid creating unnecessary threads
Implementations of ManagedClientTransport.start() are restricted from
calling the passed listener until start() returns, in order to avoid
reentrency problems with locks. For most transports this isn't a
problem, because they need additional threads anyway. InProcess uses no
additional threads naturally so ends up needing a thread just to
notifyReady. Now transports can just return a Runnable that can be run
after locks are dropped.

This was originally intended to be a performance optimization, but the
thread also causes nondeterminism because RPCs are delayed until
notifyReady is called. So avoiding the thread reduces needless fakes
during tests.
2016-08-02 13:16:36 -07:00
Kun Zhang 1775ab3847 core: call newStream() and applyRequestMetadata() under context.
`ClientTransport.newStream()` and
`CallCredentials.applyRequestMetadata()` is now called under the context
of the call.  This can be used to pass any call-specific information to
`CallCredentials`.
2016-07-29 17:24:38 -07:00
ZHANG Dapeng 41f166fd1e doc: fix io.grpc package level javadoc not showing up
- Resolves {@link ...} with full class name
- Javadoc can show up in package-summary.html
2016-07-28 12:39:48 -07:00
Naveen Reddy Chedeti 2860959d5f Support Thrift Messages 2016-07-28 08:48:27 -07:00
Kun Zhang 093ab06530 core: Log a warning in ClientCall.cancel if no detail is provided.
Resolves #2054
2016-07-25 10:30:54 -07:00
Kun Zhang d0c173b5d2 core: Remove default implementation for ClientCall.cancel.
Resolves #2050
2016-07-25 09:50:06 -07:00
Louis Ryan e276359f0e Force the immediate release of reference counted resources on AppEngine
to avoid executors backed by request-scoped threads from becoming
zombies
See
https://cloud.google.com/appengine/docs/java/javadoc/com/google/appengine/api/ThreadManager.html#currentRequestThreadFactory--
2016-07-22 13:56:44 -07:00
Eric Anderson 2cd884ea80 core: Reduce DeadlineTest flake
To my knowledge, there has been just a single DeadlineTest flake since
the code was fixed to avoid issues with I/O due to class loading:

io.grpc.DeadlineTest > defaultTickerIsSystemTicker[0] FAILED
    java.lang.AssertionError: <-21431071 ns from now> and <0 ns from now> should have been within <20000000ns> of each other

But we don't really need fine-grained verification during the test
though; if the code is not using nanoTime, then it is almost certainly
not going to have even a day of accuracy (except on a fresh VM). So
checking for a second of accuracy vs 20ms shouldn't really be an issue.
2016-07-20 09:53:00 -07:00
Eric Anderson 4289aaf79c core: Hard-code a list of providers for Android
Class.getResource() is expensive on Android, which is used by
ServiceLoader. So we hard-code a list for Android instead.

Fixes #2037
2016-07-20 09:49:59 -07:00
Eric Anderson 083ea8e6aa core: Add missing assert in CallOptionsTest 2016-07-19 11:12:28 -07:00
Eric Anderson 2e4138aa5c core: Fix doc to refer to ImplBase 2016-07-14 16:06:58 -07:00
Louis Ryan f52b4e52cd Make the OkHTTP transport AppEngine friendly. AppEngine may support
conscrypt at some point which would allow ALPN to function
Clarify the SSLContext.getDefault is not used when constructing the
default SSLSocketFactory.
2016-07-13 18:27:43 -07:00
Eric Anderson d2cc576320 core: Fix ErrorProne errors 2016-07-13 14:14:15 -07:00
Eric Anderson bfcb04c196 core: Allow avoiding Provider loading, for Android 2016-07-11 10:02:23 -07:00
Eric Anderson 7fb43d2a1e core: Add generics to raw types in KeepAliveManagerTest
Swapping to doReturn is necessary since passing a <?> to thenReturn()
does not match the <?> of OngoingStubbing (without a cast).
2016-07-10 11:57:07 -07:00
Eric Anderson 0e47be1287 core: Save accept encoding since Metadata is not thread-safe
Metadata has been passed to the application. The application may be
modifying Metadata concurrently, so we must not access Metadata after
that point.

Fixes #1947
2016-07-10 11:28:04 -07:00
Xiao Hang d9001ca448 Keepalive support
Creates a KeepAliveManager which should be used by each transport. It does keepalive pings and shuts down the transport if does not receive an response in time.
It prevents the connection being shut down for long lived streams. It could also detect broken socket in certain platforms.
2016-07-08 17:18:47 -07:00
Kun Zhang a86c5bf327 docs: Fix an issue link on ExperimentalApi. 2016-07-08 12:03:17 -07:00
Kun Zhang 527fd67cc8 core: Channel Idleness
Resolves #1276

Idle mode is where the channel does not keep live connections, and does
not have running NameResolver and LoadBalancer.

TransportSet aggregates the in-use state of transports, including the
delayed transport and real transports. Channel aggregates the in-use
state of TransportSets and delayed tranports.

Channel starts in idle mode. It exits idle mode if one of the following
occurs:
 1. A new Call requests for a transport.
 2. The channel's in-use state turns to true.
 3. Someone calls exitIdleMode().

Channel enters the idle mode if its in-use state has been false for the
configured timeout (disabled by default). It shuts down all
TransportSets, NameResolver and LoadBalancer. Interim transports and OOB
transports are LoadBalancer's responsibility.

There is a race that could cause annoyance if IDLE_TIMEOUT was too
small (e.g., 0). A TransportSet's delayed transport is holding streams,
which keeps its in-use state in true. When a real transport is ready,
all streams are transferred to the real transport, immediately after
which the delayed transport's in-use state turns to false, while the
real transport's in-use state may have not turned to true, because some
transport (e.g. netty) may have a brief delay between newStream() being
called and the stream being created internally. This could cause the
channel's aggregated in-use state be in false for a brief time, if which
is longer than IDLE_TIMEOUT, could make channel go to idle mode. Even
though the channel would go back to non-idle again, idle mode would
shutdown all transports and NameResolver and LoadBalancer which leads to
spurious error in the application.

We minimize the chance of such race by setting the minimum timeout to 1
second.

Related chanes:
- ManagedChannelImplTest now switched to use fake executors.
- Turn a few anonymous runnables into named classes. This is more useful for debugging.
2016-07-08 11:36:16 -07:00
Eric Anderson 16b096b571 Reduce default max message size to 4 MiB
Fixes #1676
2016-07-07 13:34:53 -07:00
Carl Mastrangelo 8d9283116c core: add @GaurdedBy annotations for mutable state of ServerImpl
Commit 5487ea8f54 unintentionally fixed a race condition in

shutdownNow, but the race was detected when being used inside Google.  This could have
been avoided by the enforceable documentation of GaurdedBy annotations.  These make it
clear what locks should be held, promote documentation for newly added server state,
and can be automatically checked by static analysis.
2016-07-01 16:11:20 -07:00
Eric Anderson 32fd329e1c core: Rename withCredentials to withCallCredentials on CallOptions
It was withCallCredentials on the stub to avoid confusion with channel
credentials (which don't exist in Java at this time, but do in other
languages), and having the method names be different doesn't add value.
2016-07-01 11:18:38 -07:00
ZHANG Dapeng f149e4c175 compiler: deprecate interfaces and add ImplBase in codegen
first step to address issue #1469:

- leave and deprecate interfaces in codegen
- introduce `ServiceImplBase`,
- `AbstractService` is deprecated and extends `ServiceImplBase`
- static `bindService()` is deprecated
2016-06-29 21:17:03 -07:00
ZHANG Dapeng 8ed2dc8bec testware: fix flakes caused by pickUnusedPort
Resolves #1756

The thread-unsafe method `io.grpc.testing.TestUtils.pickUnusedPort` causes flakes (#1756) in windows. Need to avoid use of this method in test as in windows the tests are running in different jvms and concurrent calls of this method in multiple processes tend to return the same port number.

There are some usages of this method in benchmarks, so moved the method to `io.grpc.benchmarks.Utils` and the method will only be used in benchmarks and not in test.
2016-06-28 13:34:38 -07:00
Eric Anderson fe5b7e3e9b core: Improve error message when lacking NameResolverProviders
This is to improve debugging as in #1982.
2016-06-27 15:21:17 -07:00
Eric Anderson 29776ca947 core: Fix onReady race by adding DelayedStreamListener
onReady/isReady previously could disagree causing a sort of deadlock
where the application isn't sending because grpc said not to, but won't
be informed to send via onReady later.

This is a stack trace from inprocessTransportOutboundFlowControl. The
line numbers are from this commit but with the changes to DelayedStream
disabled:

at io.grpc.internal.DelayedStream.isReady(DelayedStream.java:306)
  (That is isReady returning false because fallThrough == false)
at io.grpc.internal.ClientCallImpl.isReady(ClientCallImpl.java:382)
at io.grpc.stub.ClientCalls$CallToStreamObserverAdapter.isReady(ClientCalls.java:289)
at io.grpc.stub.ClientCallsTest$8$1.run(ClientCallsTest.java:403)
  (And yet that was the onReady callback, and it won't be called again)
at io.grpc.stub.ClientCalls$StreamObserverToCallListenerAdapter.onReady(ClientCalls.java:377)
at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl$4.runInContext(ClientCallImpl.java:481)
at io.grpc.internal.ContextRunnable.run(ContextRunnable.java:52)
at io.grpc.internal.SerializeReentrantCallsDirectExecutor.execute(SerializeReentrantCallsDirectExecutor.java:65)
at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl.onReady(ClientCallImpl.java:478)
at io.grpc.internal.DelayedStream$DelayedStreamListener.onReady(DelayedStream.java:366)
at io.grpc.inprocess.InProcessTransport$InProcessStream$InProcessServerStream.request(InProcessTransport.java:284)
at io.grpc.internal.ServerCallImpl.request(ServerCallImpl.java:99)
at io.grpc.stub.ServerCalls$ServerCallStreamObserverImpl.request(ServerCalls.java:345)
at io.grpc.stub.ClientCallsTest.inprocessTransportOutboundFlowControl(ClientCallsTest.java:432)

Fixes #1932
2016-06-27 13:35:52 -07:00
William Thurston 88a0378912 core: Add a RoundRobin LoadBalancer. 2016-06-27 09:56:26 -07:00
Carl Mastrangelo 46f418da94 core: fix race with exception in onMessage
Fixes #1652
2016-06-24 16:25:55 -07:00
Carl Mastrangelo 6c59770a5b core: update issue for Contexts experimental status 2016-06-24 15:45:06 -07:00
Eric Anderson 5487ea8f54 Remove unused variables
This fixed a threading issue in ServerImpl because the unused variable
should have been used.
2016-06-24 12:11:03 -07:00
Carl Mastrangelo e11917e1b8 core: add package level javadoc.
Fixes #714
2016-06-24 10:48:27 -07:00
Carl Mastrangelo 6f2c1ea078 core: mark Context as not experimental
Updates #1705
2016-06-23 13:18:56 -07:00
Kun Zhang adbc3f7ab9 doc: add flow-control example to ClientCall javadoc.
Resolves #1479
2016-06-23 10:57:18 -07:00
Eric Anderson 23f34be649 core: Move ServerMethodDefinition back into top-level class
This effectively reverts part of 3df1446d.
2016-06-23 09:31:46 -07:00
Eric Anderson cd9042b49b core: Harden ServiceDescriptor API
Over-specifying List prevents fewer things to be passed in and makes it
less efficient to use a Map later. We definitely don't want people
extending this class.
2016-06-23 09:31:46 -07:00
Eric Anderson bf588b0be8 core: Add convenience builder for ServerServiceDefinition
This adds back the previous builder, which eases upgrading.
2016-06-23 09:31:46 -07:00
Eric Anderson 66ab956f9e Reapply "Eliminate MethodDescriptor from startCall and interceptCall for servers"
This reverts commit ef178304cb, which
itself was a revert.
2016-06-23 09:27:47 -07:00
ZHANG Dapeng 2eaa540e35 doc: Status's cause is not transmitted from server to client (#1962) 2016-06-22 09:24:34 -07:00
Carl Mastrangelo 95d44b47f4 core: make ServerInterceptor non experimental
Fixes #1711
2016-06-22 09:05:23 -07:00
Carl Mastrangelo b51749baa4 core: make BindableService no longer experimental.
Fixes #1701
2016-06-22 09:03:26 -07:00
Kun Zhang d6a090a884 auth: handle null value from getRequestMetadata().
It appears some Credentials implementations may return null.
2016-06-21 16:56:50 -07:00
Eric Anderson b7ed883aec core: Avoid loading ManagedChannelProvider from NameResolverProvider
Not all users are triggering the loading of ManagedChannelProvider, so
avoid the unnecessary loading. Also, since class initialization is
involved, exception handling tends to get strange and hard to diagnose
issues.
2016-06-20 15:32:45 -07:00
Eric Anderson ef178304cb Revert "Eliminate MethodDescriptor from startCall and interceptCall for servers"
This reverts commit 3df1446deb.

The commit was adding to the difficulty of integration for testing. By
itself it isn't bad, so this is a temporary revert until the many other
commits are absorbed and then it will be reapplied.

This does have a manual edit for ClientCallsTest.
2016-06-20 15:18:18 -07:00
Kun Zhang 11a314e31a Delete the old ClientCall.cancel().
It's deprecated since 0.14.0.
2016-06-17 09:54:02 -07:00
Jakob Buchgraber 63d8274661 core: don't create a new context for each client call. Fixes #1926
Also, undo the hack that makes sure AsyncClient's stack doesn't overflow as it's no longer needed.
2016-06-16 16:02:17 +02:00
Kun Zhang 38b950f4f9 core: add transportInUse() to transport listener.
A transport is "in use" iff number of streams > 0. In following changes
the channel will use this information when deciding whether it should
transit to the IDLE mode (#1276).
2016-06-15 13:40:44 -07:00
Jakob Buchgraber 33cd6bee0e core: Overwrite values for existing custom call options.
When a custom calloption is overwritten we keep its old value around.
This patch actually overwrites the old value.
2016-06-15 10:29:05 +02:00
Kun Zhang e7c735abea Make ServerCallHandler non-experimental. 2016-06-14 13:54:29 -07:00
Eric Anderson a2076f4ec8 core: Enable per-message compression bit by default
This does not enable compression by default, but if the application
chooses to enable compression for a Call, messages will be compressed
without also needing to enable per-message compression.

Disabling per-message compression is intended as a security feature and
should be relatively rarely used, but it was the default. Thus we
required clients to use more advanced interfaces unnecessarily.

To keep client and server behavior consistent, the server also has
per-message compression enabled by default. However, to prevent
compressing on the wire by default, servers no longer enable compression
for the response by default.
2016-06-14 10:51:32 -07:00
Eric Anderson 26bace63e5 core: Improve fail fast status messages
Don't wrap the Status when a fail-fast RPC is already queued when the
transport fails, since that Status is directly responsible for the
failing of the RPC. For future fail-fast RPCs, use the saved status as a
cause to make debugging easier.

This came out of #1330, where the unnecessary nesting of the status
codes just added noise.
2016-06-14 09:55:18 -07:00
Eric Anderson 56a2938830 core: Add NameResolverProvider
This allows moving DnsNameResolver out of io.grpc and removes another
reference of io.grpc.internal from io.grpc. It allows allows
NameResolvers to be pluggable just by being in the class path (as is
already done for ManagedChannels and Servers).
2016-06-14 09:49:52 -07:00
Louis Ryan 3df1446deb Eliminate MethodDescriptor from startCall and interceptCall for servers
Make the MethodDescriptor a property of ServerCall
Move ServerMethodDefinition into ServerServiceDefinition
2016-06-13 14:39:58 -07:00
Eric Anderson 0b55c81548 core: Move ACCEPT_ENCODING_JOINER to DecompressorRegistry
This removes a reference of io.grpc.internal from io.grpc. It also
optimizes server call handling for outbound grpc-accept-encoding header,
as had already been done for client call.
2016-06-13 13:42:58 -07:00
Jakob Buchgraber 4b127f2231 core: Fix CallOptions 'wait for ready' and toString()
- CallOptions 'wait for ready' was not passed between with*() calls and therefore
it was not possible to enable it via a stub.

- Properly format custom call options in toString() output.
2016-06-13 21:04:25 +02:00
Jakob Buchgraber 7da48ae13e core: log exceptions thrown by Runnable's executed via schedule(..). Fixes #1237 2016-06-13 18:39:26 +02:00
ZHANG Dapeng 9d4a43fb79 core: fail fast implementation
resolves #1759
2016-06-11 09:30:16 -07:00
Kun Zhang 432cec7973 core: CallCredentials
Introduce CallCredentials as a first-class option to allow applications
to set per-call credentials into headers for outgoing RPCs. This will
supersede ClientAuthInterceptor. It has access to more
information (e.g., transport attributes, MethodDescriptor) and allow
results to be returned asynchronously, e.g., from a blocking I/O, which
was problemantic with ClientAuthInterceptor.
2016-06-09 17:46:15 -07:00
William Thurston a05ab57561 core: emit lists of lists from NameResolver 2016-06-09 08:30:55 -07:00
Kun Zhang 05ce5455da core: A missed-out test for #1896 2016-06-07 11:57:25 -07:00
ZHANG Dapeng b88ea27b53 core/internal: add 3-arg newStream method to ClientTransport interface (#1898)
adding 
ClientStream newStream(MethodDescriptor<?, ?> method, Metadata headers, CallOptions callOptions);
to ClientTransport interface

Created this PR first because both fail fast implementation and another change will be using this interface change
2016-06-06 19:43:15 -07:00
Jakob Buchgraber 53cd333531 core: add test for complete() without close() exception in AbstractServerStream. Fixes #615 2016-06-03 07:27:57 +02:00
Eric Anderson c6fd94ca85 Implement shutdownNow
Fixes #448
2016-06-02 17:39:59 -07:00
Kun Zhang 631a9d5fac Fix URI construction.
This fixes two issues.

1) Use the URI constructor with multiple arguments to construct the placeholder
URI for direct address, so that special characters can be correctly
escaped. This resolves #1883.

It requires the second fix.

2) Stop URI from mistreating paths as authorities.

There is a bug in URI constructors that take multiple arguments.  They simply
concatenate escaped components and try to parse the resulting string.

For example, URI("dns", null, "//127.0.0.1", null), which is what we do
internally when the application passes "/127.0.0.1" as the target, is supposed
to create a [scheme="dns", path="//127.0.0.1"].  Instead, it internally composes
"dns://127.0.0.1", which is parsed into [scheme="dns", authority="127.0.0.1"].

To avoid this issue, we pass empty string instead of null as the authority to
the URI constructor. The constructor would make "dns:////127.0.0.1" internally
which can be parsed correctly.
2016-06-02 17:10:44 -07:00
elandau 90323ad5d4 core: add custom CallOptions 2016-06-02 09:14:48 -07:00
Carl Mastrangelo 2ed39c92eb core: cache decompressor registry encodings, and make it copy on write 2016-06-02 09:10:42 -07:00
Kun Zhang 90506405c9 Differentiate transport to LB services and to servers.
TransportManager has a new method, createOobTransportProvider(), which
accepts an EquivalentAddressGroup and the authority string. This
addresses two requirements:

1. Per GRPCLB protocol, connections to the remote load-balancer may use a
different authority than the channel's (#1137).

2. For idle state determination, Channel needs to exclude the transport to
the LB service when looking at live RPCs and (#1276).
2016-06-01 18:23:09 -07:00
Carl Mastrangelo 676bf4854f core: fix nags from linter 2016-06-01 13:58:07 -07:00
Carl Mastrangelo 02eb24b3bd core,netty,okhttp: move user agent removal closer to where it is set 2016-06-01 12:55:21 -07:00
Jakob Buchgraber 028d0844dd core: add test for deframer closed exception. fixes #1795 2016-06-01 20:44:29 +02:00
Kun Zhang c08d74fec4 TransportSet shutdown() also shuts down the pending transport.
Previously TransportSet.shutdown() only shuts down the active transport,
which means a transport will not be shutdown if it's not ready yet. This
issue was introduced by #1494 that postponed the assignment of the
active transport till transport ready.
2016-05-29 15:45:03 -07:00
ZHANG Dapeng 361936401f core/internal: fix regex pattern 2016-05-26 14:02:15 -07:00
Eric Anderson 7052d8b5e9 core: Promote Deadline API to stable
Fixes #1706
2016-05-26 13:33:48 -07:00
Carl Mastrangelo 4204eb8cd9 core: allocate less garbage iterators in Metadata.serialize
Before:
HeadersBenchmark.convertClientHeaders             10  sample   99004   806.749 ±   4.692  ns/op
HeadersBenchmark.convertClientHeaders             20  sample  105673  1540.814 ±  86.361  ns/op
HeadersBenchmark.convertClientHeaders             50  sample  188978  3347.881 ±  71.778  ns/op
HeadersBenchmark.convertClientHeaders            100  sample  189913  6626.884 ±  94.348  ns/op
HeadersBenchmark.convertServerHeaders             10  sample  107884   766.328 ±  49.338  ns/op
HeadersBenchmark.convertServerHeaders             20  sample  122568  1303.501 ±   8.820  ns/op
HeadersBenchmark.convertServerHeaders             50  sample  109281  2920.586 ±  93.654  ns/op
HeadersBenchmark.convertServerHeaders            100  sample  196784  6429.566 ± 108.588  ns/op

After:
HeadersBenchmark.convertClientHeaders             10  sample  113274   715.382 ±  5.412  ns/op
HeadersBenchmark.convertClientHeaders             20  sample  128654  1294.677 ± 67.867  ns/op
HeadersBenchmark.convertClientHeaders             50  sample  112598  2814.925 ± 62.291  ns/op
HeadersBenchmark.convertClientHeaders            100  sample  116920  5383.146 ± 90.205  ns/op
HeadersBenchmark.convertServerHeaders             10  sample  130004   626.243 ±  3.528  ns/op
HeadersBenchmark.convertServerHeaders             20  sample  142054  1185.193 ± 80.272  ns/op
HeadersBenchmark.convertServerHeaders             50  sample  115153  2795.715 ± 92.956  ns/op
HeadersBenchmark.convertServerHeaders            100  sample  119520  5249.636 ± 56.089  ns/op
2016-05-25 15:12:40 -07:00
Carl Mastrangelo 1cc76d8132 core,netty,okhttp: move user agent out of client call and into the transport 2016-05-25 15:11:42 -07:00
Eric Anderson 641cb357c6 Tweak -Xlint warnings
This now catches a few more places we needed -Xlint:-options.
InProcessSocketAddress is technically already in our stable API, so I
maintained its current serialVersionUID.
2016-05-24 15:04:07 -07:00
Eric Anderson e4ea237597 core: Refactor TransportSet in prep for fail fast
This is functionally equivalent. Some tests needed changes because they
were verifying internal behavior.
2016-05-24 14:40:07 -07:00
Carl Mastrangelo 5e30b2f7ba netty: speed up header conversion by caching user agent string
Performance gain seems to be about 100-200ns based on a a couple trials.

Benchmark                                 (headerCount)  (validate)    Mode     Cnt     Score    Error  Units
HeadersBenchmark.convertClientHeadersOld             10       false  sample  187490   858.234 ±  3.992  ns/op
HeadersBenchmark.convertClientHeadersOld             20       false  sample  113589  1407.557 ± 45.178  ns/op
HeadersBenchmark.convertClientHeadersOld             50       false  sample  100725  3141.936 ± 55.175  ns/op
HeadersBenchmark.convertClientHeadersOld            100       false  sample  109742  5707.748 ± 38.222  ns/op
HeadersBenchmark.convertHeaders                      10       false  sample  109137   748.486 ±  4.060  ns/op
HeadersBenchmark.convertHeaders                      20       false  sample  133639  1238.528 ± 51.914  ns/op
HeadersBenchmark.convertHeaders                      50       false  sample  107914  2915.602 ± 10.017  ns/op
HeadersBenchmark.convertHeaders                     100       false  sample  110305  5682.404 ± 44.032  ns/op
2016-05-23 17:49:30 -07:00
Łukasz Strzałkowski ac9a5a5679 Make Code.status() public, add Status#fromCode()
Closes #1722
2016-05-23 17:03:48 -07:00
Eric Anderson 8033cdd3a7 core: Add unit test for Contexts.interceptCall 2016-05-23 13:51:10 -07:00
Eric Anderson 6382015f9d internal: Split-state AbstractStream; sending and receiving
This introduces an AbstractStream2 that is intended to replace the
current AbstractStream. Only server-side is implemented in this commit
which is why AbstractStream remains. This is mostly a reorganization of
AbstractStream and children, but minor internal behavioral changes were
required which makes it appear more like a reimplementation.

A strong focus was on splitting state that is maintained on the
application's thread (with Stream) and state that is maintained by the
transport (and used for StreamListener). By splitting the state it makes
it much easier to verify thread-safety and to reason about interactions.

I consider this a stepping stone for making even more changes to
simplify the Stream implementations and do not think some of the changes
are yet at their logical conclusion. Some of the changes may also
immediately be replaced with something better. The focus was to improve
readability and comprehesibility to more easily make more interesting
changes.

The only thing really removed is some state checking during sending
which is already occurring in ServerCallImpl.
2016-05-23 12:33:49 -07:00
Carl Mastrangelo e19848092d core, interop-testing: always set message encoding, and use it in interop tests
This change updates the behavior of the core compression semantics.  Previously,
if the codec was "identity", nothing was set on the wire.  This is allowed by
the spec, but doesn't match what wrapped languages do.

Additionally, the interop tests will now attempt to honor the requested
compression.
2016-05-18 12:04:25 -07:00
Carl Mastrangelo 4e268da29b core: Don't lose server call exception when message fails to close 2016-05-13 15:59:06 -07:00
nmittler 951b5a4ca2 Adding metadata to Status exceptions.
Fixes #681
2016-05-13 15:52:06 -07:00
Jakob Buchgraber ce002bd449 core: allow ClientCall.cancel before start. Fixes #1536 (#1822) 2016-05-13 22:20:02 +02:00
nmittler d9d4d8b70f Updating status codes to match the spec.
Fixes #1605
2016-05-09 13:55:50 -07:00
Kun Zhang 91b087e526 Remove an obsolete comment on ServerServiceDefinition.
Commit 9597382 introduced InternalHandlerRegistry as the main registry,
which uses a flat map from fullMethodNames to handlers, thus addressed
the original intention of this comment.
2016-05-05 09:25:04 -07:00
Kun Zhang 95973827f5 Refactor HandlerRegistry.
See #933

- Create InternalHandlerRegistry, an immutable look-up table. Handlers
  passed to ServerBuilder.addService() go to this registry. This covers
  the most common use cases. By keeping the registry internal we could
  freely change the registry's interface to accommodate optimizations,
  e.g., for hpack.

- The internal registry uses a flat fullMethodName -> handler look-up
  table instead of a hierarchical one used before. It faster because it
  saves one look-up and a substring.

- Introduces the fallback registry, settable by
  ServerBuilder.fallbackHandlerRegistry(), for advanced users who want a
  dynamic registry. Moved the current MutableHandlerRegistryImpl to
  io.grpc.util.MutableHandlerRegistry as a stock implementation of the
  fallback registry. The io.grpc.MutableHandlerRegistry interface is now
  removed.
2016-05-04 17:12:32 -07:00
Carl Mastrangelo dc80b52da6 context: Remove tests for Key Equality. 2016-05-04 16:39:55 -07:00
Carl Mastrangelo bc661e7fbb all: Finish adding tracking issues for ExperimentalApi 2016-05-03 16:15:57 -07:00
Carl Mastrangelo 0f9e3fa2ea all: Add issues for many of the experimental API annotations 2016-05-03 13:24:28 -07:00
Eric Anderson b5e6d420a3 Return Context from fork instead of CancellableContext
It is trivial to call withCancellation() after the fork().
CancellableContexts are required to be cancelled eventually, so
returning Context instead is easier when cancellation is not necessary.

Fixes #1626
2016-05-03 09:19:31 -07:00
ZHANG Dapeng dda4ad7441 remove the dependency on Guava's Throwables.getCausalChain #1663 (#1749)
resolves #1663
2016-04-29 19:43:21 -07:00
Jakob Buchgraber 46eefe34fb Strip cause from InProcessTransport between client and server. Fixes #1716 2016-04-29 23:36:59 +02:00
Carl Mastrangelo f7dc4d2cc6 Try to use ScheduledThreadpoolExecutor 2016-04-29 13:59:28 -07:00
Jakob Buchgraber 9de87e3acd Add tests for call.cancel() from within messageRead. 2016-04-29 18:16:58 +02:00
Jakob Buchgraber 645bb24c6c Add private constructor to Contexts and mark statusFromCancelled experimental. Fixes #1737 and #1736. (#1738) 2016-04-28 17:12:14 +02:00
Eric Anderson b0ed77ad81 Specify Status*Exception is to be used in StreamObserver.onError 2016-04-27 16:45:05 -07:00
Kun Zhang 16e168951a Allow application to pass cancellation details.
Resolves #1221

Add ClientCall.cancel(String, Throwable) and deprecate
ClientCall.cancel(). Will delete cancel() after all known third-party
overriders have switched to overriding the new one.
2016-04-27 09:38:18 -07:00
Carl Mastrangelo 00f8f349b2 Don't allocate extra byte for each MessageFramer 2016-04-21 10:48:53 -07:00
Carl Mastrangelo 5baee2d935 Fix some corner cases with MessageFramer 2016-04-21 10:45:07 -07:00
Kun Zhang 8502730d07 Attach an exception to client-initiated CANCELLED.
This tells us where is the cancellation initiated, which is important
information for debugging.
2016-04-20 17:38:01 -07:00
wangyuntao 7d8ee1e9d8 some spelling mistakes 2016-04-19 08:39:20 -07:00
Carl Mastrangelo d0d946ec9f new name 2016-04-18 16:21:53 -07:00
Carl Mastrangelo c4e8b1f10f Rename internal.Server to internal.TransportServer 2016-04-18 15:50:20 -07:00
Eric Anderson 6ab27aba13 Update checkstyle version and sync style updates 2016-04-18 09:15:25 -07:00
Sky Ao 1d8aefad69 create AuthorityOverridingTransportFactory instance only when authorityOverride is set 2016-04-18 08:43:30 -07:00
Kun Zhang 0f86671f8d Handle exceptions from LoadBalancer.handleResolvedAddresses()
And pass the exception to LoadBalancer.handleNameResolutionError(), in
the hope that it canb e propagated to the application, instead of
leaving the RPC hang forever.

Resolves #1407
2016-04-14 16:23:36 -07:00
Kun Zhang 7659f6ed68 Handle empty address list from NameResolver.
Passing an empty list to NameResolver.Listener.onUpdate() will trigger
onError(). It is documented in the javadoc and enforced by
ManagedChannelImpl.

Forbid empty address list in EquivalentAddressGroup.

Resolves #1657
2016-04-14 13:43:07 -07:00
Carl Mastrangelo 51fd870cfd Add getting the port out of a Server 2016-04-13 13:54:45 -07:00
Kun Zhang 43439325bc Delayed transport creates real streams in executor.
setTransport() is called by the transportReady() callback, which is run
inside transport thread. When it creates real streams, it also
serializes all buffered requests, which is not supposed to be done in
transport thread. This change offloads the work to the application
executor.

Resolves #1606

Also fix ManagedChannelImplTest flakes by adding timeouts to all
verify()s on mockStream.start().
2016-04-12 16:33:58 -07:00
buchgr fd8fd517d2 Context deadline propagation should cascade. Fixes #1205
A call's timeout as specified in its metadata should be set depending
on the deadline of the call's context. If a call has an explicit deadline
set (through CallOptions), then the smaller deadline (from context and call options)
should be used to compute the timeout.

Also, a new method Contexts.statusFromCancelled(Context) was introduced that attempts
to map a canceled context to a gRPC status.
2016-04-12 21:43:49 +02:00
Carl Mastrangelo 7d889b6911 Reuse metadata array when making http2 headers, and reduce some array copies 2016-04-08 13:08:07 -07:00
Łukasz Strzałkowski 90fbf9b274 Adapt BindableService in ServerBuilder#addService
Makes binding services to server as simple as it can get.
2016-04-08 11:14:26 -07:00
Eric Anderson 30d4f95a58 Deflake CallOptionsTest.withDeadlineNanoTime
Two prong approach: increase the tolerance and decrease code between
nanoTime() calls.

Fixes #1645
2016-04-08 10:35:40 -07:00
Carl Mastrangelo 2c3a63fe75 Remove some array copies in metadata 2016-04-07 12:58:44 -07:00
Eric Anderson bd87b3f739 Allow nanoTime to wrap around in Deadline
A nanoTime result must be subtracted from another result to be useful;
you must do t1 - t2 < 0 instead of t1 < t2.
2016-04-06 12:08:31 -07:00
Eric Anderson d36a03c7b1 Use ticker in Deadline testing to remove flakes 2016-04-06 12:05:14 -07:00
Carl Mastrangelo b3bc7fc499 Try out using Truth library 2016-04-05 11:33:20 -07:00
Carl Mastrangelo 5c4ff7ad08 Remove unused method 2016-04-01 14:04:55 -07:00
Carl Mastrangelo f64a02f2ef Remove Flakes caused by assertEquals 2016-03-31 16:20:40 -07:00