Commit Graph

732 Commits

Author SHA1 Message Date
Eric Anderson e92b2275f9 Update to Error Prone 2.4
Most of the changes should be semi-clear why they were made. However, BadImport
may not be as obvious: https://errorprone.info/bugpattern/BadImport . That
impacted classes named Type, Entry, and Factory. Also
PublicContructorForAbstractClass:
https://errorprone.info/bugpattern/PublicConstructorForAbstractClass

The JdkObsolete issue is already resolved but is not yet in a release.
2020-08-06 10:56:16 -05:00
Eric Anderson 80d62bfce2 Upgrade to Mockito 3.3.3
verifyZeroInteractions has the same behavior as verifyNoMoreInteractions. It
was deprecated in Mockito 3.0.1 and replaced with verifyNoInteractions, which
does not change behavior depending on previous verify() calls. All instances
were replaced with verifyNoInteractions, except those in
ApplicationThreadDeframerTest which were replaced with verifyNoMoreInteractions
since there is a verify() call in `@Before`.
2020-08-06 10:49:23 -05:00
Eric Anderson 8400b17200 Bump Jetty ALPN to 2.0.10 for Java 8u252
Since Travis in on Java 8u252, we won't actually be testing Jetty ALPN at this
point. We're also not testing the Java 9 ALPN API on Java 8, since our current
version of Netty doesn't support it (but an upgrade is available that does).
2020-06-25 11:50:15 -05:00
Eric Anderson 295d927d8b core: Add migrating deframer
This provides a substantial ~3x performance increase to Netty async
streaming with small messages. It also increases OkHttp performance for
the same benchmark 40% and decreases unary latency by 3µs for Netty and
10µs for OkHttp.

We avoid calling listener after closure because the Executor used for
RPC callbacks may no longer be available. This issue was already
present in the ApplicationThreadDeframer, but full-stream compression is
not really deployed so was unnoticed.

DirectExecutor saw a 5-6µs latency increase via MigratingDeframer.
DirectExecutor usages should see no benefit from MigratingDeframer, so
disable it in that case.
2020-06-18 15:48:29 -05:00
Elliotte Rusty Harold 417d7700dd
deps: Update guava to 29.0 (#7079) 2020-06-03 13:48:02 -07:00
Reginald McDonald 408136301e
netty: return status code unavailable when netty channel has unresolved InetSocketAddress (#7023) 2020-05-21 16:15:53 -07:00
Nicholas Titcombe 3601190143
netty: use getOrCreate() for new instances of ChannelLogger AttributeKey. (#7048) 2020-05-21 12:43:35 -07:00
AgentK d89dd2db33
netty: log SocketExceptions at FINE, too
This PR changes the `NettyServerTransport#getLogLevel` method to log 
`SocketException`s to `LogLevel.FINE`, rather than exclusively pure
IOExceptions. This may fix an unintentional regression introduced in
c166ec2c, although the message in my java version (14.0.1) wouldn't have
passed the old logic for quieting either. This also fixes the issue
raised in #6423 that was locked for inactivity.

This fixes 
```
[2020/05/14 20:21:52   INFO] [io.grpc.netty.NettyServerTransport.connections] Transport failed
java.net.SocketException: Connection reset
        at java.base/sun.nio.ch.SocketChannelImpl.throwConnectionReset(SocketChannelImpl.java:345)
        at java.base/sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:376)
        at io.netty.buffer.PooledUnsafeDirectByteBuf.setBytes(PooledUnsafeDirectByteBuf.java:288)
        at io.netty.buffer.AbstractByteBuf.writeBytes(AbstractByteBuf.java:1125)
        at io.netty.channel.socket.nio.NioSocketChannel.doReadBytes(NioSocketChannel.java:347)
        at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:148)
        at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:677)
        at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:612)
        at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:529)
        at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:491)
        at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:905)
        at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
        at java.base/java.lang.Thread.run(Thread.java:832)
```
being logged to level INFO, which occurs whenever a socket is improperly 
closed by the client, such as with the grpc-health-probe (They've got an
[open issue](https://github.com/grpc-ecosystem/grpc-health-probe/issues/34)
for this)
2020-05-15 15:31:35 -07:00
Jihun Cho 1c50bcafd5
netty: enable auto flow control tuning by default (#7015) 2020-05-11 16:38:58 -07:00
ZHANG Dapeng 0044f8ce56
all: migrate gradle build to java-library plugin
- Use gradle configuration `api` for dependencies that are part of grpc public api signatures.
- Replace deprecated gradle configurations `compile`, `testCompile`, `runtime` and `testRuntime`.
- With minimal change in dependencies: If we need dep X and Y to compile our code, and if X transitively depends on Y, then our build would still pass even if we only include X as `compile`/`implementation` dependency for our project. Ideally we should include both X and Y explicitly as `implementation` dependency for our project, but in this PR we don't add the missing Y if it is previously missing.
2020-05-04 16:44:30 -07:00
Jihun Cho 83a3b25e80
netty: allow to use bandwidth delay product (#6979) 2020-05-01 15:39:22 -07:00
Jihun Cho 0059c5ac04
netty: use netty default SO_BACKLOG (#6956) 2020-04-22 09:10:17 -07:00
Benedict Jin 9411e9716c
netty: support setting options of boss in NettyServer (#6947) 2020-04-21 10:20:20 -07:00
Kun Zhang 17b2b96d8a
netty: log the selection of allocators (#6930) 2020-04-15 14:44:02 -07:00
Eric Anderson 9ead606b84
netty: Reduce race window size between GOAWAY and new streams
The race between new streams and transport shutdown is #2562, but it is still
far from being generally solved. This reduces the race window of new streams
from (transport selection → stream created on network thread) to (transport
selection → stream enqueued on network thread). Since only a single thread now
needs to do work in the stream creation race window, the window should be
dramatically smaller.

This only reduces GOAWAY races when the server performs a graceful shutdown
(using two GOAWAYs), as that is the only non-racy way on-the-wire to shutdown a
connection in HTTP/2.
2020-04-10 12:03:23 -07:00
Eric Anderson 2c250ace52 netty: prevent interruption during bind from leaking channel
Fixes #6850
2020-03-27 17:21:22 -07:00
ZHANG Dapeng 5677a0b723
api,netty: fix MethodDescriptor and InternalKnownTransport for netty-shaded
Resolves #6765
2020-02-27 12:53:11 -08:00
ZhenLian 557da62305
netty: Upgrade Netty (4.1.45.Final) & tcnative (2.0.28.Final) 2020-02-06 10:03:14 -08:00
sanjaypujare 461d30adfb
netty: fix server and client handlers to check the correct alpn list (#6603) 2020-02-04 13:03:34 -08:00
Jihun Cho 2acca6ea3b
all: fix lint warnings (#6658) 2020-01-30 10:00:39 -08:00
Kun Zhang 74cde7e8b4
netty: add an internal option to disable native buffer (#6619)
This is needed for internal rollout where the native memory usage from netty makes task more prone to exceeding memory limits.
2020-01-21 11:37:02 -08:00
ZHANG Dapeng b8474d61c9
netty: fix a race for channelz at server transport creation
A race condition was reported by user in #6601:

`ServerImpl.start()` calls `NettyServer.start()` while holding `ServerImpl.lock`. `NettyServer.start()` awaits a submitted runnable in eventloop. However, this pending runnable may never be executed because the eventloop might be executing some other task, like `ServerListenerImpl.transportCreated()`, that is trying to acquire `ServerImpl.lock` causing a deadlock.

This PR resolves the particular issue reported in #6601 for server with a single port, but `NettyServer` (https://github.com/grpc/grpc-java/blob/v1.26.0/netty/src/main/java/io/grpc/netty/NettyServer.java#L251) and `ServerImpl` (https://github.com/grpc/grpc-java/blob/v1.26.0/core/src/main/java/io/grpc/internal/ServerImpl.java#L184) in general still have the same potential risk of deadlock, which need further fix.
2020-01-16 11:53:37 -08:00
Aleksei Kandybaev 18e099d9d3 netty: fix ENHANCE_YOUR_CALM debug data logging (#6596) 2020-01-13 14:59:23 -08:00
sanjaypujare dba09163de
netty: remove 'grpc-exp' from the list of next-protocol-versions in ALPN (#6592) 2020-01-09 16:41:20 -08:00
Eric Anderson c606519a5d bazel: Support maven_install
maven_install is strongly superior to previous forms of grabbing dependencies
from Maven as it computes the appropriate versions to use from the full
transitive dependencies of all libraries used by an application. It also has
much less boilerplate and includes dependencies with generated targets.

In the future we will drop the jvm_maven_import_external usages and require
maven_install, at which point we can swap to using the `@maven' repository and
no longer depend on compat_repositories.

Fixes #5359
2019-12-30 12:08:42 -08:00
ZhenLian 19805233ef netty: Add Executor When Creating SslContext
This PR is to add one more Executor parameter when creating the SslContext.
In Netty, we already have this implementation for passing Executor when creating SslContext: netty/netty#8847. This extra Executor is used to take some time-consuming tasks when doing SSL handshake. However, in current gRPC implementation, we are not using this API.

In this PR, the relevant changes are:

1. get the executorPool from ChannelBuilder or ServerBuilder

2. pass the executorPool all the way down to ClientTlsHandler

3. fill executorPool in when creating SslHandler
2019-12-30 08:33:16 -08:00
Kun Zhang 212da14200
netty: enable io.grpc.netty.useCustomAllocator by default (take 2) (#6528)
Since #6526 has resolved the memory leak, let's turn it back on.
2019-12-18 08:33:29 -08:00
Kun Zhang ada575dd24
netty: use singleton for the custom allocator. (#6526)
The allocator has a circular reference that prevents it from GC'ed,
thus causes memory leak if gRPC Channels are created and shutdown
(even cleanly) on a regular basis.

See https://github.com/netty/netty/issues/6891#issuecomment-457809308
and internal b/146074696.
2019-12-16 17:35:40 -08:00
Kun Zhang c032e2ebf9
Revert "netty: enable io.grpc.netty.useCustomAllocator by default (#6459)" (#6517)
This reverts commit b0e00fd4ba.

It may cause leak of netty native buffers when creating and shutting
down Channels on a regular basis.
2019-12-13 10:48:53 -08:00
Eric Anderson 9a646518cb
netty: NettyServer should close ProtocolNegotiator 2019-12-10 16:46:30 -08:00
Jihun Cho 1573e0d400
netty: log NativeIoException as FINE level (#6477)
resolves #6478
2019-12-03 13:05:04 -08:00
Kun Zhang b0e00fd4ba
netty: enable io.grpc.netty.useCustomAllocator by default (#6459) 2019-11-22 16:13:35 -08:00
ZHANG Dapeng 2d454d478c
Revert "Revert "all: remove deprecated usePlaintext(boolean)""
This reverts commit 316a739e67.
2019-11-18 16:53:52 -08:00
Kun Zhang d77419557a
netty: reduce default worker ELG thread number by half, to number of CPU cores (#6439)
This would cut the amount of per-thread direct buffer allocations by half, especially with light traffic. This will also cut the amount of file descriptors that's created per thread by half.

Internal benchmark results (median of 5 runs) doesn't show any significant change:
```
                          Before (STDEV)           After (STDEV)
grpc-java-java-multi-qps-integrity_only
Actual QPS               711,004 (6,246)         704,372 (6,873) 
QPS per Client CPU        23,921   (252)          24,188   (252)

grpc-java-java-multi-throughput-integrity_only
Actual QPS                35,326    (48)          35,294    (29) 
QPS per Client CPU         3,362    (17)           3,440    (13)

grpc-java-java-single-latency-integrity_only
Median latency (us)          127  (2.77)             129  (3.13)

grpc-java-java-single-throughput-integrity_only
Actual QPS                   581 (11.60)             590  (7.08)
QPS per Client CPU           490 (10.98)             498  (5.63)
```
2019-11-18 16:26:37 -08:00
Kun Zhang 89cd64328d
netty: provide an option to lower netty allocator chunk size from 16MB to 2MB (#6407)
This would reduce the amount of direct buffer allocations, especially with light traffic. This should mitigate internal issue b/143075435

The change is currently optional and is only effective if system property "io.grpc.netty.useCustomAllocator" is set to "true" ignoring the case.

Internal benchmark results (median of 5 runs) doesn't show any significant change:
```
                          Before (STDEV)           After (STDEV)
grpc-java-java-multi-qps-integrity_only
Actual QPS               717,848 (7,445)         715,061 (2,122) 
QPS per Client CPU        23,768   (799)          23,842   (295)

grpc-java-java-multi-throughput-integrity_only
Actual QPS                35,631   (204)          35,298    (25) 
QPS per Client CPU         3,362    (56)           3,316    (18)

grpc-java-java-single-latency-integrity_only
Median latency (us)          130  (1.82)             125  (5.36)

grpc-java-java-single-throughput-integrity_only
Actual QPS                    593 (5.14)             587  (3.76)
QPS per Client CPU            502 (4.51)             494  (6.92)

```
2019-11-14 15:50:11 -08:00
Steve Rao 1118793bfb netty: improve code readability (#6375) 2019-11-12 08:48:58 -08:00
Steve Rao a408d086bd netty: unified log prompt (#6386) 2019-11-05 19:47:50 -08:00
Steve Rao 1adf403bb1 netty: remove redundant variable references 2019-11-05 17:48:51 -08:00
Eric Anderson 28149944ad netty: Deflake WriteBufferingAndExceptionHandlerTest
It appears the problem is that server.close() was missing sync(), so the
event loop was still processing the closure when the next test started.

This change is more aggressive than it needs to be, but should make it
less bug-prone.

Fixes #5574
2019-11-04 17:52:57 -08:00
sanjaypujare 48b41dce9e
xds: Client and server proto negotiators and handlers added to SdsProtocolNegotiators (#6319) 2019-10-24 15:27:53 -07:00
Jihun Cho c166ec2c4e netty: use FINE log for pure IOExceptions 2019-10-24 15:17:16 -07:00
ZHANG Dapeng 316a739e67
Revert "all: remove deprecated usePlaintext(boolean)"
This reverts commit 296857b4e7.
2019-10-10 15:56:47 -07:00
ZHANG Dapeng 296857b4e7
all: remove deprecated usePlaintext(boolean) 2019-10-08 09:27:39 -07:00
Eric Anderson 2caa77d48f netty: Implicitly enable Conscrypt when it is available
This implicit loading is more conservative than the loading for
tcnative, as Conscrypt will only be implicitly loaded if there are no
other options. This means the Java 9+ JSSE is preferred over Conscrypt
without explicit user configuration.

While we would generally prefer Conscrypt over JSSE, we want to allow
the user to configure their security providers. There wasn't a good way
to do that with netty-tcnative and the performance of JSSE at the time
was abysmal.

While generally being a good way to allow adopting Conscrypt, this also
allows easily using App Engine Java 8's provided Conscrypt which can
substantially reduce binary size.

See googleapis/google-cloud-java#6425
2019-10-07 11:37:50 -07:00
Jihun Cho e9ac1b4a76
all: update modules to wait until other module's sourceSet is available (#6232) 2019-10-02 15:05:44 -07:00
Carl Mastrangelo ab2aff48dc netty,okhttp,cronet: add option to use get/put when methods are safe/idempotent
This change adds two booleans to the ChannelBuilders to
allow transports to use get and put.   These are currently defaulted to
on, but unset on the method descriptors.   This change is 1/2 that will
allow the safe / idempotent bits to be set on generated proto code.
Part 2/2 will actually enable it.

The use case for this is for interceptors that implement caching logic.
They need to be able to access the safe/idempotent bits on the MD in
order to decide to how to handle the request, even if gRPC doesn't use
GET / PUT HTTP methods.
2019-09-25 14:57:17 -07:00
Eric Anderson bd48891dab netty: Check for TE header after checking Content-Type
Checking too early leads to false-positives, like if a non-gRPC client
contacts the server or a grpc-web client.
2019-09-25 14:04:19 -07:00
Jihun Cho 16392bc733
netty: converts Proxy handler into new protocol negotiation style (#6159) 2019-09-19 15:29:03 -07:00
Anar Sultanov ba0fd84d79 netty: Rely on ChannelFactory in NettyServer instead of dynamic classes
Fixes #5649
2019-09-17 15:59:29 -07:00
Eric Anderson 2b945774b6 Apply animalsniffer plugin explicitly when needed 2019-09-13 09:42:17 -07:00