我正在使用gRPC运行微服务,并在服务器端从客户端获得了许多onError()回调。
t.printStackTrace()显示:
io.grpc.StatusRuntimeException: UNKNOWN
at io.grpc.Status.asRuntimeException(Status.java:526)
at io.grpc.stub.ClientCalls$StreamObserverToCallListenerAdapter.onClose(ClientCalls.java:385)
at io.grpc.ForwardingClientCallListener.onClose(ForwardingClientCallListener.java:41)
at io.grpc.internal.CensusTracingModule$TracingClientInterceptor$1$1.onClose(CensusTracingModule.java:339)
at io.grpc.internal.ClientCallImpl.closeObserver(ClientCallImpl.java:443)
at io.grpc.internal.ClientCallImpl.access$300(ClientCallImpl.java:63)
at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl.close(ClientCallImpl.java:525)
at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl.access$600(ClientCallImpl.java:446)
at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl$1StreamClosed.runInContext(ClientCallImpl.java:557)
at io.grpc.internal.ContextRunnable.run(ContextRunnable.java:37)
at io.grpc.internal.SerializingExecutor.run(SerializingExecutor.java:107)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
如果我关闭除测试客户端之外的所有连接,则异常将消失。
所以,我想知道是否有任何限制(在服务器端)有关MAX的实例数:
io.grpc.ManagedChannel
io.grpc.stub.StreamObserver
如果有,我怎样才能调整/放大它们?
任何帮助将不胜感激。
答案 0 :(得分:0)
UNKNOWN
状态通常表示服务器以某种方式失败。您可能想要检查服务器日志。
服务器可以拥有的连接数和RPC数没有实际限制。有太多连接的文件描述符可能会用完。有可能达到RPC限制,导致它们排队,直到可以发送它们。和任何事情一样,你可能会遇到内存使用和类似的限制。
答案 1 :(得分:0)
@Eric是正确的。 在这里,我只是展示了我遇到的问题。希望也可以帮助其他人解决同样的问题。
在服务器端,我发现有很多例外,例如
Apr 19, 2018 5:06:07 PM io.grpc.internal.SerializingExecutor run
SEVERE: Exception while executing runnable io.grpc.internal.ServerImpl$JumpToApplicationThreadServerStreamListener$1MessagesAvailable@752265fc
redis.clients.jedis.exceptions.JedisException: Could not return the resource to the pool
at redis.clients.jedis.JedisPool.returnResource(JedisPool.java:256)
at redis.clients.jedis.JedisPool.returnResource(JedisPool.java:16)
at redis.clients.jedis.Jedis.close(Jedis.java:3409)
...
at io.grpc.stub.ServerCalls$StreamingServerCallHandler$StreamingServerCallListener.onMessage(ServerCalls.java:251)
at io.grpc.internal.ServerCallImpl$ServerStreamListenerImpl.messagesAvailable(ServerCallImpl.java:251)
at io.grpc.internal.ServerImpl$JumpToApplicationThreadServerStreamListener$1MessagesAvailable.runInContext(ServerImpl.java:592)
at io.grpc.internal.ContextRunnable.run(ContextRunnable.java:37)
at io.grpc.internal.SerializingExecutor.run(SerializingExecutor.java:107)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused by: redis.clients.jedis.exceptions.JedisConnectionException: java.net.SocketTimeoutException: Read timed out
at redis.clients.util.RedisInputStream.ensureFill(RedisInputStream.java:202)
at redis.clients.util.RedisInputStream.readByte(RedisInputStream.java:40)
at redis.clients.jedis.Protocol.process(Protocol.java:151)
at redis.clients.jedis.Protocol.read(Protocol.java:215)
at redis.clients.jedis.Connection.readProtocolWithCheckingBroken(Connection.java:340)
at redis.clients.jedis.Connection.getAll(Connection.java:310)
at redis.clients.jedis.Connection.getAll(Connection.java:302)
at redis.clients.jedis.Pipeline.sync(Pipeline.java:99)
at redis.clients.jedis.Pipeline.clear(Pipeline.java:85)
at redis.clients.jedis.BinaryJedis.resetState(BinaryJedis.java:1781)
at redis.clients.jedis.JedisPool.returnResource(JedisPool.java:252)
... 13 more
Caused by: java.net.SocketTimeoutException: Read timed out
由于它提到了redis,我查看了相关代码,发现JedisPoolConfig可能没有足够的线程,并且默认超时可能太短。
所以我放大了两个,问题就解决了。
换句话说,服务器没有足够的资源来在期望的时间内处理客户端请求。这导致gRPC服务器失败,因此称为客户端onError()方法。
谢谢@Eric。