如何解决CloudHub 中的 HTTP 请求连接超时是指定的 3 倍
我们有一个要求,当体验 API 调用流程 API 时,如果流程 API 关闭,它需要在 5 秒内超时。
因此我们将 HTTP 请求组件配置为使用 HTTP_Request_configuration 中的 connectionTimeout 属性:
<http:request-connection host="${http.process.api.host}" port="${http.process.api.port}"
maxConnections="${http.process.api.maxConnections}" connectionIdleTimeout="${http.process.api.timeout}"
responseBufferSize="${http.process.api.bufferSize}">
<http:client-socket-properties >
<sockets:tcp-client-socket-properties connectionTimeout="${http.process.api.client.timeout}"/>
</http:client-socket-properties>
</http:request-connection>
并且在 Studio 中进行测试时,它工作正常(API 在本地执行并配置为在 CloudHub 中命中 Process API)并在 http.process.api.client.timeout 属性中设置的大约 5 秒内超时 (5000) .
但是当 Experience API 部署到 CloudHub 并且我们对其进行测试时,超时发生在 15 秒后。
如果我们将超时时间降低到 4000 毫秒,大约需要 12 秒,2000 毫秒,大约需要 6 秒等等。
知道为什么以及如何在 CloudHub 中修复它吗?
干杯, 史蒂夫
额外细节(16/05/2021):
两个网络用例:
- Postman(本地)> Exp API(云中心)> Process API(云中心)
- Postman(本地)> Exp API(本地(工作室))> Process API(云中心)
在 Process API 关闭的情况下测试 (1) 时,超时发生在 15 秒后。 在 Process API 关闭的情况下测试 (2) 时,超时发生在 5 秒后。
我们使用的是 Mule Runtime 4.3,HTTP 连接器是 1.5.6 版。
这里是完整的 HTTP 请求配置:
<http:request-config name="process-api-HTTPS_Request_configuration" doc:name="HTTP Request configuration" doc:id="6532744b-8be1-4443-b441-f95a66148de3" basePath="${http.process.api.basepath}" responseTimeout="${http.process.api.response.timeout}">
<http:request-connection host="${http.process.api.host}" port="${http.process.api.port}"
maxConnections="${http.process.api.maxConnections}" connectionIdleTimeout="${http.process.api.timeout}"
responseBufferSize="${http.process.api.bufferSize}" protocol="HTTPS">
<tls:context >
<tls:trust-store insecure="true" />
</tls:context>
<http:client-socket-properties >
<sockets:tcp-client-socket-properties connectionTimeout="${http.process.api.client.timeout}" />
</http:client-socket-properties>
</http:request-connection>
</http:request-config>
和 HTTP 请求:
<http:request method="POST" doc:name="Process API Request" doc:id="fa1f1a2f-ea97-4829-8f84-677477b7ddfd" config-ref="process-api-HTTPS_Request_configuration" path="${http.process.api.path}">
<http:headers ><![CDATA[#[output application/java
---
{
"source" : p('constant.header.source'),"correlationId" : correlationId,"Content-Type" : "application/json","X-Client-Secret" : p('secure::process.api.clientsecret'),"X-Client-Id" : p('secure::process.api.clientid')
}]]]></http:headers>
</http:request>
属性:
http.process.api.protocol=HTTPS
http.process.api.host=mule-worker-internal-xxxx-process-api-dev.au-s1.cloudhub.io
http.process.api.port=8092
http.process.api.basepath=/api/v1/
http.process.api.timeout=5000
http.process.api.client.timeout=5000
http.process.api.response.timeout=5000
http.process.api.maxConnections=-1
http.process.api.bufferSize=1024
http.process.api.path.general=/leads/product
体验 API 日志:
09:49:13.891 05/16/2021 Worker-0 [MuleRuntime].uber.509: [xxxx-exp-api-1a-tst].post:\enquiries\general:application\json:experience-api-config.cpu_LITE @b8fba0c INFO
event:57bfc3f0-b5dc-11eb-9e1f-061654e69fc6 Send Enquiries flow START
09:49:13.892 05/16/2021 Worker-0 [MuleRuntime].uber.509: [xxxx-exp-api-1a-tst].post:\enquiries\general:application\json:experience-api-config.cpu_LITE @b8fba0c INFO
event:57bfc3f0-b5dc-11eb-9e1f-061654e69fc6 Start Process API General Enquiry Request
09:49:26.772 05/16/2021 Worker-0 connection-pool-delays-thread-pool(1) ERROR
event:57bfc3f0-b5dc-11eb-9e1f-061654e69fc6 Error sending HTTP request to https://mule-worker-internal-xxxx-proc-api-1a-tst.au-s1.cloudhub.io:8092/api/v1/leads/product
09:49:26.784 05/16/2021 Worker-0 connection-pool-delays-thread-pool(1) ERROR
event:57bfc3f0-b5dc-11eb-9e1f-061654e69fc6
********************************************************************************
Message : HTTP POST on resource 'https://mule-worker-internal-xxxx-proc-api-1a-tst.au-s1.cloudhub.io:8092/api/v1/leads/product' Failed: Connect timeout.
Element : xxxx-managementFlow:post:general/processors/1 @ xxxx-exp-api-1a-tst:process/xxxx-management.xml:10 (Lead Management Process API General Enquiry)
Element DSL : <http:request method="POST" doc:name="Process API General Enquiry" doc:id="fa1f1a2f-ea97-4829-8f84-677477b7ddfd" config-ref="process-api-HTTPS_Request_configuration" path="${http.process.api.path.general}">
<http:headers>#[output application/java
---
{
"source" : p('constant.header.source'),"X-Client-Id" : p('secure::process.api.clientid')
}]</http:headers>
</http:request>
Error type : HTTP:CONNECTIVITY
FlowStack : at xxxx-managementFlow:post:general(xxxx-managementFlow:post:general/processors/1 @ xxxx-exp-api-1a-tst:process/xxxx-management.xml:10 (Process API General Enquiry))
at impl-experience-main:enquiries-general:subFlow(impl-experience-main:enquiries-general:subFlow/processors/1 @ xxxx-exp-api-1a-tst:implementation/impl-experience-main.xml:9 (xxxx-managementFlow:post:general))
at post:\enquiries\general:application\json:experience-api-config(post:\enquiries\general:application\json:experience-api-config/processors/0 @ xxxx-exp-api-1a-tst:experience-api.xml:56 (impl-experience-main:send-Feedback:subFlow))
at experience-api-main(experience-api-main/processors/1 @ xxxx-exp-api-1a-tst:experience-api.xml:28 (Request Router))
Payload Type : org.mule.runtime.core.internal.streaming.bytes.ManagedCursorStreamProvider
--------------------------------------------------------------------------------
Root Exception stack trace:
java.net.ConnectException: Connect timeout
at org.glassfish.grizzly.connectionpool.SingleEndpointPool$ConnectCompletionHandler.cancelled(SingleEndpointPool.java:1290)
at org.glassfish.grizzly.impl.SafeFutureImpl.notifyCompletionHandlers(SafeFutureImpl.java:185)
at org.glassfish.grizzly.impl.SafeFutureImpl.done(SafeFutureImpl.java:277)
at org.glassfish.grizzly.impl.SafeFutureImpl$Sync.innerCancel(SafeFutureImpl.java:389)
at org.glassfish.grizzly.impl.SafeFutureImpl.cancel(SafeFutureImpl.java:247)
at org.glassfish.grizzly.connectionpool.SingleEndpointPool$ConnectTimeoutWorker.doWork(SingleEndpointPool.java:1365)
at org.glassfish.grizzly.connectionpool.SingleEndpointPool$ConnectTimeoutWorker.doWork(SingleEndpointPool.java:1357)
at org.glassfish.grizzly.utils.DelayedExecutor$DelayedRunnable.run(DelayedExecutor.java:171)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:593)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:573)
at java.lang.Thread.run(Thread.java:748)
********************************************************************************
09:49:26.798 05/16/2021 Worker-0 connection-pool-delays-thread-pool(1) ERROR
event:57bfc3f0-b5dc-11eb-9e1f-061654e69fc6
********************************************************************************
Message : HTTP POST on resource 'https://mule-worker-internal-xxxx-proc-api-1a-tst.au-s1.cloudhub.io:8092/api/v1/leads/product' Failed: Connect timeout.
Error type : HTTP:CONNECTIVITY
Payload Type : org.mule.runtime.core.internal.streaming.bytes.ManagedCursorStreamProvider
--------------------------------------------------------------------------------
Root Exception stack trace:
java.net.ConnectException: Connect timeout
at org.glassfish.grizzly.connectionpool.SingleEndpointPool$ConnectCompletionHandler.cancelled(SingleEndpointPool.java:1290)
at org.glassfish.grizzly.impl.SafeFutureImpl.notifyCompletionHandlers(SafeFutureImpl.java:185)
at org.glassfish.grizzly.impl.SafeFutureImpl.done(SafeFutureImpl.java:277)
at org.glassfish.grizzly.impl.SafeFutureImpl$Sync.innerCancel(SafeFutureImpl.java:389)
at org.glassfish.grizzly.impl.SafeFutureImpl.cancel(SafeFutureImpl.java:247)
at org.glassfish.grizzly.connectionpool.SingleEndpointPool$ConnectTimeoutWorker.doWork(SingleEndpointPool.java:1365)
at org.glassfish.grizzly.connectionpool.SingleEndpointPool$ConnectTimeoutWorker.doWork(SingleEndpointPool.java:1357)
at org.glassfish.grizzly.utils.DelayedExecutor$DelayedRunnable.run(DelayedExecutor.java:171)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:593)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:573)
at java.lang.Thread.run(Thread.java:748)
********************************************************************************
09:49:26.838 05/16/2021 Worker-0 [MuleRuntime].uber.509: [xxxx-exp-api-1a-tst].experience-api-main.cpu_INTENSIVE @223e1c0 ERROR
event:57bfc3f0-b5dc-11eb-9e1f-061654e69fc6 Unhandled Error
09:49:26.863 05/16/2021 Worker-0 [MuleRuntime].uber.509: [xxxx-exp-api-1a-tst].experience-api-main.cpu_INTENSIVE @223e1c0 ERROR
event:57bfc3f0-b5dc-11eb-9e1f-061654e69fc6
********************************************************************************
Message : HTTP POST on resource 'https://mule-worker-internal-xxxx-proc-api-1a-tst.au-s1.cloudhub.io:8092/api/v1/leads/product' Failed: Connect timeout.
Error type : HTTP:CONNECTIVITY
Payload Type : org.mule.runtime.core.internal.streaming.bytes.ManagedCursorStreamProvider
--------------------------------------------------------------------------------
Root Exception stack trace:
java.net.ConnectException: Connect timeout
at org.glassfish.grizzly.connectionpool.SingleEndpointPool$ConnectCompletionHandler.cancelled(SingleEndpointPool.java:1290)
at org.glassfish.grizzly.impl.SafeFutureImpl.notifyCompletionHandlers(SafeFutureImpl.java:185)
at org.glassfish.grizzly.impl.SafeFutureImpl.done(SafeFutureImpl.java:277)
at org.glassfish.grizzly.impl.SafeFutureImpl$Sync.innerCancel(SafeFutureImpl.java:389)
at org.glassfish.grizzly.impl.SafeFutureImpl.cancel(SafeFutureImpl.java:247)
at org.glassfish.grizzly.connectionpool.SingleEndpointPool$ConnectTimeoutWorker.doWork(SingleEndpointPool.java:1365)
at org.glassfish.grizzly.connectionpool.SingleEndpointPool$ConnectTimeoutWorker.doWork(SingleEndpointPool.java:1357)
at org.glassfish.grizzly.utils.DelayedExecutor$DelayedRunnable.run(DelayedExecutor.java:171)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:593)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:573)
at java.lang.Thread.run(Thread.java:748)
********************************************************************************
启用更多日志记录:
org.mule.service.http.impl.service.HttpMessageLogger
org.mule.service.http
org.mule.extension.http
org.mule.runtime.core.internal.processor.LoggerMessageProcessor
我可以看到内部超时发生在 4 秒左右(我将时间减少到 4000 毫秒): https://pastebin.com/PaM3vEGF
但是异常处理增加了很多时间,所以客户端响应是 12 秒。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。