为什么Websocket对于更大的消息和更多的用户连接到服务器而言,工作速度更快?

问题描述

我已经为websocket(+ STOMP消息格式)创建了性能测试,并且得到了奇怪的结果。对于较大的消息,对于以相同频率(大约每秒47条消息)发送消息的更多连接用户,我的请求时间更短。邮件大约有120个字节。

有一张显示我的结果的图表(每10秒钟交流添加一次用户(最后10个用户)):

enter image description here

仅1位用户

enter image description here

有客户端和服务器的配置: lib:“ @ stomp / stompjs”:“ ^ 5.4.4”

this.stompClient = new Client({
        brokerURL: this.serverUrl,splitLargeFrames: true,reconnectDelay: 1000,heartbeatIncoming: 4000,heartbeatOutgoing: 4000
    });

在服务器端是webscoket Stomp spring的认配置 Maven依赖项:

<dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-websocket</artifactId>
    </dependency>

控制器(捕获消息):

    @MessageMapping("/send/position")
public void updatePositionForPlayer(Player player,Principal user,@Header("requestTimestamp") Long requestTimestamp) {
....
}

发送回复

    @Override
public void sendToUser(String destination,GameObject gameObject,HeaderStatus status,String userSession,long requestTimestamp) {
    this.template.convertAndSendToUser(userSession,destination,gameObject,Map.of(
            "requestTimestamp",requestTimestamp,"status",status
    ));
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)