批量事务的 TCP 套接字连接超时

发布于 2024-09-24 13:00:03 字数 1140 浏览 2 评论 0原文

我非常渴望在这方面获得一些帮助。

当通过不同服务器上的 TCP 套接字连接发送大量消息以进行 HSM 卡验证时,我们会遇到问题。

这是我们进行容量测试时所测试的内容: 我们测试了以 15 事务/秒的速度处理 3 个区块(共 30,000 个交易),并且在第三个区块时交易开始被拒绝。

情况是:

  1. 我们成功处理了区块 1 和区块 2,共处理了 30,000 笔交易。
  2. 在第三个区块,系统刚刚成功处理了 8,000 个交易,之后与 HSM 的连接被阻止。
  3. 我们看到所有 HSM 套接字都已使用,因此交易被拒绝。

我们认为由于消息量较大,某些套接字未关闭或超时

。下面是代码的要点。

    ; Open the device
    OPEN SOCK:(CONNECT=HOST_":"_PORT_":TCP":DELIMITER=$C(13,10,58,27,95):ATTACH="HSMCLIENT"):TIMOUT:"SOCKET"

    ELSE  SET ER=1 CLOSE SOCK QUIT "-1"
    ; Use the socket
    USE SOCK
    ; Write the request. The request message is packed and the bytesteam is written
    WRITE HREQ,#
    ; Read the first two bytes from the socket to identify the length of the reponse
    READ BRESP#2:TIMOUT ELSE  SET ER=1 CLOSE SOCK QUIT "-1"
    ; Calculate the length of the incoming data
    SET RESPLEN=$A(BRESP,1)_$A(BRESP,2)
    ; Now read the data of the calculated length
    READ BRESP#RESPLEN:TIMOUT ELSE  SET ER=1 CLOSE SOCK QUIT "-1"
    ; Cleanup
    CLOSE SOCK
    #ENDBYPASS

如果您能提供任何建议或推荐,我们将不胜感激。

谢谢

I am desperate to get some help on this one.

We are getting issues when a volume of messages are sent through TCP Socket Connection on a different server for HSM Card validation.

This is what we tested for volume testing:
We tested with processing 3 blocks of 30,000 transactions at 15 trans/sec and at the third block transactions started to be rejected.

The situation was:

  1. We processed block 1 and 2 with 30,000 transactions successfully.
  2. At the third block the system just processed 8,000 transactions successfully and after that the connections with HSM were blocked.
  3. We saw all HSM sockets were in used so transactions were rejected.

We think some of the sockets are not closed or getting timed out because of the volume of messages

Below is the gist of teh code.

    ; Open the device
    OPEN SOCK:(CONNECT=HOST_":"_PORT_":TCP":DELIMITER=$C(13,10,58,27,95):ATTACH="HSMCLIENT"):TIMOUT:"SOCKET"

    ELSE  SET ER=1 CLOSE SOCK QUIT "-1"
    ; Use the socket
    USE SOCK
    ; Write the request. The request message is packed and the bytesteam is written
    WRITE HREQ,#
    ; Read the first two bytes from the socket to identify the length of the reponse
    READ BRESP#2:TIMOUT ELSE  SET ER=1 CLOSE SOCK QUIT "-1"
    ; Calculate the length of the incoming data
    SET RESPLEN=$A(BRESP,1)_$A(BRESP,2)
    ; Now read the data of the calculated length
    READ BRESP#RESPLEN:TIMOUT ELSE  SET ER=1 CLOSE SOCK QUIT "-1"
    ; Cleanup
    CLOSE SOCK
    #ENDBYPASS

If you can provide any suggestion or recomendation that will be really appreciated.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

黒涩兲箜 2024-10-01 13:00:03

当您启动主动关闭时,您很可能将 HSM 上的套接字保留在 TIME_WAIT 状态。

由于连接建立的速率、TIME_WAIT 周期的持续时间以及有限数量的临时端口,您最终会耗尽可用端口并且无法接受更多连接。

您可以通过在事务完成后中止连接(发送 RST 而不是 FIN)来避免 HSM 套接字进入 TIME_WAIT。您可以通过在关闭连接之前将 Linger 选项设置为 false 来在代码中执行此操作。或者,您的 HSM 可能有一个可以发送的命令,该命令的意思是“谢谢,我已经完成了,请关闭连接”,这将允许它启动主动关闭,然后将 TIME_WAIT 移至客户端计算机(这可能不会)如果您只有一台客户端计算机,那么这会有所帮助,因为您只需将问题从 HSM 无法接受更多连接转变为无法启动它们...)。

You're most likely leaving the sockets in TIME_WAIT on the HSM as you're initiating the active close.

Due to the rate of connection establishment and the duration of the TIME_WAIT period and the finite number of ephemeral ports you eventually run out of available ports and can't accept any more connections.

You may be able to avoid the HSM's socket going into TIME_WAIT by aborting your connection on completion of your transaction (sending an RST rather than a FIN). You do this in code by setting the Linger option to false before closing your connection. Alternatively your HSM may have a command that you can send that means "thanks for that, I'm done, please close the connection" which would allow it to initiate the active close and then move the TIME_WAIT to the client machines (this may not help if you have a single client machine as you'll just switch the problem from the HSM not being able to accept more connections to you not being able to initiate them...).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文