WO2017128789A1 - 一种通信方法及系统 - Google Patents

一种通信方法及系统 Download PDF

Info

Publication number
WO2017128789A1
WO2017128789A1 PCT/CN2016/103894 CN2016103894W WO2017128789A1 WO 2017128789 A1 WO2017128789 A1 WO 2017128789A1 CN 2016103894 W CN2016103894 W CN 2016103894W WO 2017128789 A1 WO2017128789 A1 WO 2017128789A1
Authority
WO
WIPO (PCT)
Prior art keywords
server
connection server
router
database
long connection
Prior art date
Application number
PCT/CN2016/103894
Other languages
English (en)
French (fr)
Inventor
张伟
Original Assignee
上海斐讯数据通信技术有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 上海斐讯数据通信技术有限公司 filed Critical 上海斐讯数据通信技术有限公司
Publication of WO2017128789A1 publication Critical patent/WO2017128789A1/zh

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/50Network services
    • H04L67/56Provisioning of proxy services

Definitions

  • the present invention relates to the field of communications, and in particular to a communication method and system.
  • the router it is now common practice for the router to establish a long connection with the server. If the user wants to remotely control the home device through the mobile terminal, the request message is sent to the server first, and then the server relays the request message to the router.
  • the server usually supports millions of long-connected clusters, which are composed of several long-connected servers. How to store and read long-connection information reasonably and efficiently is also a difficult point.
  • the invention discloses a communication method, comprising: S10 mobile terminal sends a plurality of parallel request information to a relay server; S20 transit server queries a database to obtain a long connection server corresponding to the router; and S30 transit server sends the plurality of parallel requests
  • the information is sent to the long connection server one by one according to a preset rule; the S40 long connection server forwards the request information to the router; the S50 long connection server receives the plurality of serial response messages sent by the router and forwards them to the relay server; the S60 transit server receives and The response message is processed, and the serial multiple response messages are converted into parallel response messages according to a preset rule and sent to the mobile terminal.
  • the invention adopts a parallel message serialization and serial message parallelization processing mechanism, and the parallel request
  • the information is sent to the long connection server for processing according to the preset rule, and the serial response information returned by the long connection server is converted into a parallel response message according to a preset rule and sent to the mobile terminal, which effectively solves the concurrent request in the prior art.
  • the problem of information congestion increases the signal transmission efficiency.
  • the database stores connection information of each router and a corresponding long connection server.
  • the database allocates a cache database for each persistent connection server; each cache database stores a MAC address of the persistent connection server and a hash value of the MAC address.
  • the invention can realize fast reading, querying and deleting corresponding connection information through the cache database, thereby improving the working efficiency of the long connection server.
  • the method further includes the steps of: S05, when detecting that the current long connection server is down, calculating a hash value of the MAC address of the persistent connection server; querying whether the hash value exists in the cache database; If it exists, it clears the connection information of the current long connection server in the cache database.
  • the invention can effectively improve the efficiency of querying and processing invalid information by calculating the hash value to query whether there is invalid storage information in the cache database.
  • the rule is sent to the long connection server one by one; the S40 long connection server forwards the request information to the router; the S50 long connection server receives the plurality of serial response messages sent by the router and forwards to the relay server; and the S60 relay server receives and processes the
  • the invention can reduce the message waiting time when the transit server performance is close to the bottleneck, reduce the overhead of the transit server, and improve the performance of the transit server.
  • the invention also discloses a communication system, comprising: a mobile terminal, a transit server, a long connection service Server, database and router; the mobile terminal sends parallel request information to the relay server; the relay server queries the database to obtain the long connection server corresponding to the router and parallels the plurality of The request information is sent to the long connection server one by one according to a preset rule; the long connection server forwards the request information to the router; and receives a plurality of serial response messages sent by the router and forwards the message to the relay server; The relay server receives and processes the response message, converts the serial multiple response messages into parallel response messages according to a preset rule, and sends the response message to the mobile terminal.
  • the database stores connection information of each router and a corresponding long connection server; the database allocates a cache database for each long connection server; each cache database stores a MAC address of the long connection server and the The hash value of the MAC address.
  • the method further includes: a clearing module, configured to calculate a hash value of the MAC address of the persistent connection server when detecting the current long connection server downtime; and query whether the hash value exists in the cache database; If it does not exist, clear the connection information of the current long connection server in the cache database.
  • a clearing module configured to calculate a hash value of the MAC address of the persistent connection server when detecting the current long connection server downtime; and query whether the hash value exists in the cache database; If it does not exist, clear the connection information of the current long connection server in the cache database.
  • the invention also discloses a communication system, comprising: a mobile terminal, a relay server, a long connection server, a database and a router; the mobile terminal sends parallel request information to the relay server; the relay server queries the database Obtaining the long connection server corresponding to the router, and sending the multiple pieces of parallel request information to the persistent connection server one by one according to a preset rule; the long connection server forwarding the request information to the router; and Receiving a plurality of serial response messages sent by the router and forwarding to the relay server; the relay server receives and processes the response message, and converts the serial multiple response messages into parallel responses according to a preset rule.
  • the message is sent to the mobile terminal;
  • the present invention can bring at least one of the following beneficial effects:
  • the present invention can effectively solve the problem by serializing the parallel request information.
  • the information congestion problem increases the signal transmission efficiency.
  • the present invention quickly utilizes server resources by dynamically adjusting the service thread life cycle and quickly clearing invalid information.
  • the invention uses multiple cache databases to store connection messages of each long connection server, thereby realizing fast reading, writing, querying and clearing information stored by each long connection server, thereby improving work efficiency.
  • FIG. 1 is a schematic diagram showing the main steps of a communication method of the present invention.
  • FIG. 3 is a schematic diagram of a long connection storage scheme of a communication method according to the present invention.
  • FIG. 4 is a schematic diagram showing the composition of a communication system of the present invention.
  • Mobile terminal 100. Mobile terminal, 200. Transit server, 300. Long connection server, 400. Router, 500. Database.
  • FIG. 1 is a schematic diagram of main steps of a communication method according to the present invention.
  • a method for controlling the router 400 by the mobile terminal 100 includes: S10: The mobile terminal 100 sends a plurality of parallel request information to the relay server 200; and the S20 relay server 200 queries the database.
  • the 500 obtains the long connection server 300 corresponding to the router 400; the S30 relay server 200 will The parallel request information is sent to the persistent connection server 300 one by one according to a preset rule; the S40 long connection server 300 forwards the request information to the router 400; the S50 long connection server 300 receives the plurality of serial response messages sent by the router 400 and forwards To the relay server 200; the S60 relay server 200 receives and processes the response message, converts the serial multiple response messages into parallel response messages according to a preset rule, and transmits and forwards them to the mobile terminal 100.
  • the same mobile terminal 100 may issue multiple requests simultaneously to the same router 400, and only one long connection channel, but to process concurrent requests, the present invention adds "parallel message serialization" to the relay server 200. Processing mechanism.
  • the so-called “parallel message serialization” means that the parallel request message enters a controller according to a certain preset rule, and then one piece is sent to the long connection server 300, and after the previous message is processed, the subsequent message is sent again. Connect to the server 300 long.
  • FIG. 2 is a flow chart of the serial/parallel message parallel/serialization processing of the communication method of the present invention.
  • the parallel messages sent by the mobile terminal 100 are serialized to form serial 1, 2, and 3, respectively.
  • the information is sent to the persistent connection server 300, and the persistent connection server 300 returns one by one.
  • the relay server 200 receives the response message returned by the persistent connection server 300, and passes the serial response message through parallelization processing to form parallel 1, 2, and 3 information to be transmitted to the mobile terminal 100.
  • parallel 1, 2, and 3 information to be transmitted to the mobile terminal 100.
  • the invention adopts a parallel message serialization and serial message parallelization processing mechanism, and sends parallel request information to the long connection server 300 for processing according to a preset rule, and serially responds the serial response information returned by the server 300.
  • the response message converted to the parallel response message is sent to the mobile terminal 100 according to the preset rule, which effectively solves the problem of information congestion in the concurrent request in the prior art, and improves the signal transmission efficiency.
  • the database stores connection information of each router 400 and the corresponding persistent connection server 300, and allocates a cache database for each persistent connection server 300; each cache database stores a MAC address of the persistent connection server 300 and the The hash value of the MAC address.
  • the invention calculates the MAC address into a hash value by using a hash algorithm and stores it in the cache database, compresses the data amount, and can quickly read, query and delete the corresponding connection information, thereby improving the working efficiency of the long connection server 300.
  • the foregoing embodiment is modified to obtain another communication method, including: the S10 mobile terminal sends a plurality of parallel request information to the relay server 200; the S20 relay server 200 queries the database 500 to obtain the long connection server 300 corresponding to the router 400.
  • the S30 relay server 200 sends the plurality of parallel request information to the persistent connection server 300 one by one according to a preset rule; the S40 long connection server 300 forwards the request information to the router 400; and the S50 long connection server 300 receives the transmission sent by the router 400.
  • a plurality of serial response messages are forwarded to the relay server 200;
  • the S60 relay server 200 receives and processes the response message, converts the serial multiple response messages into parallel response messages according to a preset rule, and sends them to the mobile The terminal 100;
  • S05 when detecting that the current long connection server 300 is down, calculating a hash value of the MAC address of the persistent connection server 300; querying whether the hash value exists in the cache database; if not, Clear the connection information of the current persistent connection server 300 in the cache database.
  • the cache database of the present invention has the following two advantages when dealing with long connections:
  • FIG. 3 is a schematic diagram of a long connection storage scheme of the communication method of the present invention.
  • a Redis cache database is taken as a specific example.
  • the present invention adopts a storage manner of multiple databases, that is, each long connection server 300 occupies one Redis cache database, and the long connection server 1, the long connection server 2, and the long connection server 3 occupy the Db1 in FIG. 2, respectively.
  • Three cache databases, Db2 and Db3, the format of the data storage is ⁇ MAC, ServerIP_ChannelID>.
  • each Redis cache database also stores a hash value of the MAC address of the long connection server 300.
  • the hash value of the MAC address is first calculated, and then the hash value is used to the corresponding database.
  • the query is performed in 500. If the hash value is not present in the database 500, it can be quickly determined that the information of the MAC address is not in the database 500, and the query speed can be improved.
  • the foregoing embodiment is modified to obtain another method for the mobile terminal 100 to control the router 400, including: S10, the mobile terminal 100 sends multiple pieces of parallel request information to the relay server 200; and the S15 relay server 200 generates multiple pieces according to the request information.
  • S20 transit server 200 queries database 500 to obtain long connection server 300 corresponding to router 400.
  • the S30 relay server 200 sends the plurality of parallel request information to the persistent connection server 300 one by one according to a preset rule; the S40 long connection server 300 forwards the request information to the router 400; and the S50 long connection server 300 receives the transmission sent by the router 400.
  • a plurality of serial response messages are forwarded to the relay server 200; the S60 relay server 200 receives and processes the response message, and the string is A plurality of response messages according to a preset rule conversion into parallel response message and transmits to the mobile terminal 100.
  • a large number of routers 400 are connected to the relay server 200, and a large number of parallel request messages are forwarded. How to properly control the quality of service is an important technical point.
  • each request Since the request message sent by the mobile terminal 100 is generally an HTTP-based synchronization request, each request generates a service thread on the relay server 200 side, and each service thread generates an overhead.
  • each service thread has its own life cycle, which is equal to the message processing time. That is, if the router 400 message can be returned quickly, the created service thread is quickly destroyed, so that the relay server 200 can use the resource to process the new request. However, if the router 400 does not respond to the message in time, the service thread will survive for a long time until the request message times out.
  • the present invention adopts a method for dynamically adjusting the service thread life cycle.
  • the basic idea is that the general router 400 message will be returned within T0 seconds.
  • the relay server 200 will increase the waiting time to T0+T1 seconds, the increase of T1 seconds increases the reliability of the message to a certain extent, but increases the overhead of the relay server 200 and reduces the performance of the relay server 200. Therefore, the basic idea of the present invention is that the performance of the relay server 200 does not reach the bottleneck. In this case, the relay server 200 waits for T0+T1 seconds.
  • the T1 waiting time is reduced, but the T1 minimum is 0, that is, the waiting time is at least T0. You can use a formula to represent the above relationship:
  • T T0+T1*(1-n/N), where the maximum number of service threads is N, the current number of service threads is n, and T is the message waiting time.
  • the relay server 200 resources can be better utilized.
  • FIG. 4 is a schematic diagram of a composition of a communication system according to an embodiment of the present invention.
  • a system for controlling a router 400 by a mobile terminal 100 includes: a mobile terminal 100, a relay server 200, and a long Connecting the server 300, the database 500, and the router 400; the mobile terminal 100 transmits parallel request information to the relay server 200; the relay server 200 queries the database 500 to obtain the long connection server 300 corresponding to the router 400.
  • the mobile terminal 100 cannot directly establish a connection with the router 400 when the router 400 does not have a public network IP address, but the mobile terminal 100 sends the message to the relay server 200.
  • the relay server 200 queries the database 500 for the connection information of the router 400, that is, which long connection server 300 the router 400 is connected to.
  • the message is then sent to the persistent connection server 300, which finally sends the message to the router 400.
  • the router 400 returns the message to the persistent connection server 300, which returns the message to the relay server 200, which returns the message to the mobile terminal 100.
  • the database 500 stores connection information of each router 400 and the corresponding long connection server 300; the database 500 allocates a cache database for each persistent connection server 300; each cache database stores the long connection server 300. MAC address and the MAC address Greek value.
  • the method further includes a clearing module, configured to calculate a hash value of the MAC address of the persistent connection server 300 when detecting that the current persistent connection server 300 is down; and query whether the hash value exists in the cache database. If it does not exist, the connection information of the current persistent connection server 300 in the cache database is cleared.
  • a clearing module configured to calculate a hash value of the MAC address of the persistent connection server 300 when detecting that the current persistent connection server 300 is down; and query whether the hash value exists in the cache database. If it does not exist, the connection information of the current persistent connection server 300 in the cache database is cleared.
  • the invention calculates the MAC address into a hash value by using a hash algorithm and stores it in the cache database, compresses the data amount, and can quickly read, query and delete the corresponding connection information, thereby improving the working efficiency of the long connection server 300.
  • the above embodiment is improved to obtain another communication system, including: a mobile terminal 100, a relay server 200, a long connection server 300, a database 500, and a router 400; the mobile terminal 100 transmits parallel request information to the office
  • the relay server 200 queries the database 500 to obtain the long connection server 300 corresponding to the router 400, and sends the plurality of parallel request information one by one to the persistent connection server 300 according to a preset rule.

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Mobile Radio Communication Systems (AREA)
  • Data Exchanges In Wide-Area Networks (AREA)

Abstract

本发明公开了一种通信方法,包括:S10移动终端发送多条并行的请求信息至中转服务器;S20中转服务器查询数据库得到路由器对应的长连接服务器;S30中转服务器将多条并行的请求信息按照预设规则逐条发送至长连接服务器;S40长连接服务器转发请求信息至路由器;S50长连接服务器接收路由器发送的多条串行的响应消息并转发至中转服务器;S60中转服务器接收并处理响应消息并转发至移动终端。本发明采用并行消息串行化和串行消息并行化的处理机制,有效解决了现有技术中并发请求时信息拥堵的难题,提高了信号传输效率。

Description

一种通信方法及系统 技术领域
本发明涉及通信领域,特别是一种通信方法及系统。
背景技术
随着互联网技术的发展,很多家用设备都需要接入互联网,形成智能家居系统。基于现在的IPV4网络协议下,大多数设备都无法拥有独立的公网IP地址,而需要与其它设备共享公网IP地址,这样就使得远程控制设备变得困难。
现在普遍的做法是,路由器与服务端建立长连接,如果用户通过移动终端要远程控制家里的设备,需要先将请求消息发送给服务器,然后服务器中转该请求消息到路由器。
现在利用服务器做中继的方法,有两个问题:
1.移动终端和路由器的交互经常是并发请求,而长连接通道只有一个,如何利用这一个通道来做并发访问是一个难点。
2.服务器通常要支持数百万的长连接集群,由数台长连接服务器组成,如何合理高效地存储与读取长连接信息,也是一个难点。
发明内容
本发明的目的是提供一种通信方法及系统,用于解决移动终端远程控制路由器的问题。
本发明提供的技术方案如下:
本发明公开了一种通信方法,包括:S10移动终端发送多条并行的请求信息至中转服务器;S20中转服务器查询数据库获得与路由器对应的长连接服务器;S30中转服务器将所述多条并行的请求信息按照预设规则逐条发送至长连接服务器;S40长连接服务器转发所述请求信息至路由器;S50长连接服务器接收路由器发送的多条串行的响应消息并转发至中转服务器;S60中转服务器接收并处理所述响应消息,将所述串行的多条响应消息按照预设规则转换成并行的响应消息并发送至移动终端。
本发明采用并行消息串行化和串行消息并行化的处理机制,将并行的请求 信息按照预设规则逐条发送至长连接服务器进行处理,并将长连接服务器返回的串行的响应信息按照预设规则转换成并行的响应消息发送至移动终端,有效解决了现有技术中并发请求时信息拥堵的难题,提高了信号传输效率。
进一步优选的,所述数据库存储有每个路由器与对应的长连接服务器的连接信息。
进一步优选的,所述数据库为每个长连接服务器分配一个缓存数据库;每个缓存数据库存储长连接服务器的MAC地址以及所述MAC地址的哈希值。
本发明通过缓存数据库能够实现快速读取、查询和删除相应的连接信息,提高长连接服务器工作效率。
进一步优选的,还包括步骤:S05当检测到当前的长连接服务器宕机时,计算所述长连接服务器的MAC地址的哈希值;在缓存数据库中查询是否存在所述哈希值;若不存在,则清除缓存数据库中当前长连接服务器的连接信息。
本发明通过计算哈希值查询缓存数据库中是否存在无效的存储信息,有效提高了查询和处理无效信息的效率。
本发明还公开了另一种通信方法,包括:S10移动终端发送多条并行的请求信息至中转服务器务器;S15中转服务器根据所述请求信息生成多条服务线程;所述中转服务器为每个服务线程分配生命周期T;超过当前所述服务线程的生命周期时,清除当前服务线程所述生命周期T=T0+T1*(1-n/N),其中T0为预设第一时间,T1为预设第二时间,n为当前服务线程数,N为最大服务线程数;S20中转服务器查询数据库获得与路由器对应的长连接服务器;S30中转服务器将所述多条并行的请求信息按照预设规则逐条发送至长连接服务器;S40长连接服务器转发所述请求信息至路由器;S50长连接服务器接收路由器发送的多条串行的响应消息并转发至中转服务器;S60中转服务器接收并处理所述响应消息,将所述串行的多条响应消息按照预设规则转换成并行的响应消息并发送至移动终端。
本发明通过动态调节服务线程生命周期,在中转服务器性能接近瓶颈时能减少消息等待时间,降低了中转服务器的开销,提高了中转服务器的性能。
本发明还公开了一种通信系统,包括:移动终端、中转服务器、长连接服 务器、数据库以及路由器;所述移动终端将并行的请求信息发送至所述中转服务器;所述中转服务器查询所述数据库获得与所述路由器对应的所述长连接服务器并将所述多条并行的请求信息按照预设规则逐条发送至长连接服务器;所述长连接服务器转发所述请求信息至所述路由器;以及,接收所述路由器发送的多条串行的响应消息并转发至中转服务器;所述中转服务器接收并处理所述响应消息,将所述串行的多条响应消息按照预设规则转换成并行的响应消息并发送至所述移动终端。
进一步优选的,所述数据库存储有每个路由器与对应的长连接服务器的连接信息;所述数据库为每个长连接服务器分配一个缓存数据库;每个缓存数据库存储长连接服务器的MAC地址以及所述MAC地址的哈希值。
进一步优选的,还包括清除模块,用于当检测到当前的长连接服务器宕机时,计算所述长连接服务器的MAC地址的哈希值;在缓存数据库中查询是否存在所述哈希值;若不存在,则清除缓存数据库中当前长连接服务器的连接信息。
本发明还公开了一种通信系统,包括:移动终端、中转服务器、长连接服务器、数据库以及路由器;所述移动终端将并行的请求信息发送至所述中转服务器;所述中转服务器查询所述数据库获得与所述路由器对应的所述长连接服务器并将所述多条并行的请求信息按照预设规则逐条发送至长连接服务器;所述长连接服务器转发所述请求信息至所述路由器;以及,接收所述路由器发送的多条串行的响应消息并转发至中转服务器;所述中转服务器接收并处理所述响应消息,将所述串行的多条响应消息按照预设规则转换成并行的响应消息并发送至所述移动终端;所述中转服务器具体包括:线程控制模块,用于根据所述请求信息生成多条服务线程;以及用于为每个服务线程分配生命周期T;超过当前所述服务线程的生命周期时,清除当前服务线程所述生命周期T=T0+T1*(1-n/N),其中T0为预设第一时间,T1为预设第二时间,n为当前服务线程数,N为最大服务线程数。
与现有技术相比,本发明能够带来以下至少一项有益效果:
1、本发明通过将并行的请求信息进行串行化处理,能够有效解决当 前同一个移动终端向同一台路由器同时发出多个请求时信息拥堵问题,提高信号传输效率。
2、本发明通过动态调节服务线程生命周期,快速清除无效信息,从而更好地利用服务器的资源。
3、本发明采用多个缓存数据库存储每台长连接服务器的连接消息,实现快速读写、查询、清除每台长连接服务器存储的信息,提高工作效率。
附图说明
下面将以明确易懂的方式,结合附图说明优选实施方式,对一种通信方法及系统的上述特性、技术特征、优点及其实现方式予以进一步说明。
图1是本发明一种通信方法的主要步骤示意图;
图2是本发明通信方法的串/并行消息并/串行化处理的流程图;
图3是本发明一种通信方法的长连接存储方案示意图;
图4是本发明一种通信系统的组成示意图。
附图标号说明:
100.移动终端,200.中转服务器,300.长连接服务器,400.路由器,500.数据库。
具体实施方式
为了更清楚地说明本发明实施例或现有技术中的技术方案,下面将对照附图说明本发明的具体实施方式。显而易见地,下面描述中的附图仅仅是本发明的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其他的附图,并获得其他的实施方式。
为使图面简洁,各图中只示意性地表示出了与本发明相关的部分,它们并不代表其作为产品的实际结构。另外,以使图面简洁便于理解,在有些图中具有相同结构或功能的部件,仅示意性地绘示了其中的一个,或仅标出了其中的一个。在本文中,“一个”不仅表示“仅此一个”,也可以表示“多于一个”的情形。
图1为本发明一种通信方法的主要步骤示意图。作为本发明的一个具体实施例,如图1所示,一种移动终端100控制路由器400的方法,包括:S10移动终端100发送多条并行的请求信息至中转服务器200;S20中转服务器200查询数据库500得到与路由器400对应的长连接服务器300;S30中转服务器200将所述多 条并行的请求信息按照预设规则逐条发送至长连接服务器300;S40长连接服务器300转发所述请求信息至路由器400;S50长连接服务器300接收路由器400发送的多条串行的响应消息并转发至中转服务器200;S60中转服务器200接收并处理所述响应消息,将所述串行的多条响应消息按照预设规则转换成并行的响应消息并发送并转发至移动终端100。
具体的,同一个移动终端100可能会向同一台路由器400同时发出多个请求,而长连接通道只有一个,但是却要处理并发的请求,本发明在中转服务器200中增加了“并行消息串行化”的处理机制。所谓的“并行消息串行化”就是将并行的请求消息按照一定的预设规则进入一个控制器,然后一条条发往长连接服务器300,等前面的消息得到处理结果后,后面的消息再发往长连接服务器300。
图2是本发明通信方法的串/并行消息并/串行化处理的流程图,从图3中可见,移动终端100发出的并行消息经过串行化处理分别形成串行的1、2、3信息发送到长连接服务器300,长连接服务器300逐条响应返回。同理,中转服务器200接收长连接服务器300返回的响应消息,并将串行的响应消息经过并行化处理形成并行的1、2、3信息发送至移动终端100。对与移动终端100而言,无需关注服务器端的处理过程。
本发明采用并行消息串行化和串行消息并行化的处理机制,将并行的请求信息按照预设规则逐条发送至长连接服务器300进行处理,并将长连接服务器300返回的串行的响应信息按照预设规则转换成并行的响应消息发送至移动终端100,有效解决了现有技术中并发请求时信息拥堵的难题,提高了信号传输效率。
优选的,数据库存储每个路由器400与对应的长连接服务器300的连接信息,同时为每个长连接服务器300分配一个缓存数据库;每个缓存数据库中存储有长连接服务器300的MAC地址以及所述MAC地址的哈希值。本发明通过采用哈希算法将MAC地址计算成哈希值并存储在缓存数据库中,压缩了数据量,能够实现快速读取、查询和删除相应的连接信息,提高长连接服务器300工作效率。
对上述实施例进行改进,得到另一种通信方法,包括:S10移动终端发送多条并行的请求信息至中转服务器务器200;S20中转服务器200查询数据库500获得与路由器400对应的长连接服务器300;S30中转服务器200将所述多条并行的请求信息按照预设规则逐条发送至长连接服务器300;S40长连接服务器300转发所述请求信息至路由器400;S50长连接服务器300接收路由器400发送的多条串行的响应消息并转发至中转服务器200;S60中转服务器200接收并处理所述响应消息,将所述串行的多条响应消息按照预设规则转换成并行的响应消息并发送至移动终端100;S05当检测到当前的长连接服务器300宕机时,计算所述长连接服务器300的MAC地址的哈希值;在缓存数据库中查询是否存在所述哈希值;若不存在,则清除缓存数据库中当前长连接服务器300的连接信息。
具体的,如何处理海量的连接信息也是本发明的重点。在处理长连接时,本发明的缓存数据库具有以下两点有益效果:
1.快速地读写。
2.如果某台长连接服务器300宕机了,则该长连接服务器300的存储信息是无效的,该长连接服务器300所有的连接信息被立刻从缓存数据库中清除。
图3是本发明通信方法的长连接存储方案示意图,本方案中,以Redis缓存数据库为具体实例。如图3所示,本发明采取了多个数据库的存储方式,即每台长连接服务器300占用一个Redis缓存数据库,图2中长连接服务器1、长连接服务器2以及长连接服务器3分别占用Db1、Db2和Db3三个缓存数据库,数据存储的格式为<MAC,ServerIP_ChannelID>。并且,每个Redis缓存数据库也存储了长连接服务器300MAC地址的哈希值,中转服务器200根据MAC地址进行查询时,先计算出该MAC地址的哈希值,然后根据哈希值到对应的数据库500中进行查询,如果该数据库500中没有该哈希值,则可以很快地判断出,该MAC地址的信息不在该数据库500中,可以提高查询速度。
当某台长连接服务器300宕机时,由于本方案采用的是每台服务器有自己独立的缓存数据库,可以立刻请求缓存数据库来清除无效的信息。本发明通过计算哈希值查询缓存数据库中是否存在无效的存储信息,有效提高了查询和处 理无效信息的效率。
对上述实施例进行改进,得到另一种移动终端100控制路由器400的方法,包括:S10移动终端100发送多条并行的请求信息至中转服务器200;S15中转服务器200根据所述请求信息生成多条服务线程;所述中转服务器200为每个服务线程分配生命周期T;超过当前所述服务线程的生命周期时,清除当前服务线程;所述生命周期T=T0+T1*(1-n/N),其中T0为预设第一时间,T1为预设第二时间,n为当前服务线程数,N为最大服务线程数;S20中转服务器200查询数据库500获得与路由器400对应的长连接服务器300;S30中转服务器200将所述多条并行的请求信息按照预设规则逐条发送至长连接服务器300;S40长连接服务器300转发所述请求信息至路由器400;S50长连接服务器300接收路由器400发送的多条串行的响应消息并转发至中转服务器200;S60中转服务器200接收并处理所述响应消息,将所述串行的多条响应消息按照预设规则转换成并行的响应消息并发送至移动终端100。
具体的,在同一时刻,会有大量的路由器400与中转服务器200相连,并且有大量的并行的请求消息要转发,如何很好地控制服务质量是一个很重要的技术点。
由于移动终端100发出的请求消息一般都是基于HTTP的同步请求,所以每次请求都会在中转服务器200端产生一个服务线程,每个服务线程都会产生一段开销。一般而言,每个服务线程都会有自己的生命周期,这个生命周期就等于消息处理时间。也就是说,如果路由器400消息能够很快地返回,那么创建的服务线程就会很快地销毁,这样中转服务器200可以把资源用于处理新的请求。但如果路由器400没有及时地响应消息,那么这个服务线程就会生存很长时间,直到请求消息超时才会被销毁。
对于以上问题,本发明采用了一种动态调节服务线程生命周期的方法,其基本思想是,一般路由器400消息会在T0秒时间内返回,为了增加可靠性,中转服务器200会将等待时间提高到T0+T1秒,增加了T1秒一定程度上提高了消息的可靠度,但确增加了中转服务器200的开销,降低了中转服务器200的性能。因此,本发明的基本思想是,在中转服务器200性能未达到瓶颈的情 况下,中转服务器200等待T0+T1秒,当中转服务器200的性能接近瓶颈时,减小T1等待时间,但T1最小为0,也就是说,等待时间最小为T0。可以用一个公式来表示以上关系:
T=T0+T1*(1-n/N),其中,设最大服务线程数为N,当前服务线程数为n,T为消息等待时间。
通过以上方法,可以更好地利用中转服务器200资源。
图4为本发明一种通信系统的组成示意图,作为本发明的一个具体实施例,如图4所示,一种移动终端100控制路由器400的系统,包括:移动终端100、中转服务器200、长连接服务器300、数据库500以及路由器400;所述移动终端100将并行的请求信息发送至所述中转服务器200;所述中转服务器200查询数据库500得到与所述路由器400对应的所述长连接服务器300并将所述多条并行的请求信息按照预设规则逐条发送至长连接服务器300;所述长连接服务器300转发所述请求信息至所述路由器400;以及,接收所述路由器400发送的多条串行的响应消息并转发至中转服务器200;所述中转服务器200接收并处理所述响应消息,将所述串行的多条响应消息按照预设规则转换成并行的响应消息并发送至所述移动终端100。
具体的,如图4所示,其中长连接服务器300为多个,分别连接一个路由器400。由于路由器400通常不一定有公网IP地址,所以移动终端100在路由器400没有公网IP地址的情况下,无法与路由器400直接建立连接,而是移动终端100将报文发送给中转服务器200,中转服务器200从数据库500中查询得到该路由器400的连接信息,也就是该路由器400与哪台长连接服务器300是处于连接状态。然后将报文发送给该长连接服务器300,长连接服务器300最后将报文发送给路由器400。路由器400将消息返回给长连接服务器300,长连接服务器300将消息返回给中转服务器200,中转服务器200将消息返回给移动终端100。
优选的,所述数据库500存储有每个路由器400与对应的长连接服务器300的连接信息;所述数据库500为每个长连接服务器300分配一个缓存数据库;每个缓存数据库存储长连接服务器300的MAC地址以及所述MAC地址的哈 希值。
优选的,还包括清除模块,用于当检测到当前的长连接服务器300宕机时,计算所述长连接服务器300的MAC地址的哈希值;在缓存数据库中查询是否存在所述哈希值;若不存在,则清除缓存数据库中当前长连接服务器300的连接信息。
本发明通过采用哈希算法将MAC地址计算成哈希值并存储在缓存数据库中,压缩了数据量,能够实现快速读取、查询和删除相应的连接信息,提高长连接服务器300工作效率。
对上述实施例进行改进,得到另一种一种通信系统,包括:移动终端100、中转服务器200、长连接服务器300、数据库500以及路由器400;所述移动终端100将并行的请求信息发送至所述中转服务器200;所述中转服务器200查询所述数据库500获得与所述路由器400对应的所述长连接服务器300并将所述多条并行的请求信息按照预设规则逐条发送至长连接服务器300;所述长连接服务器300转发所述请求信息至所述路由器400;以及,接收所述路由器400发送的多条串行的响应消息并转发至中转服务器200;所述中转服务器200接收并处理所述响应消息,将所述串行的多条响应消息按照预设规则转换成并行的响应消息并发送至所述移动终端100;所述中转服务器200具体包括:线程控制模块,用于根据所述请求信息生成多条服务线程;以及用于为每个服务线程分配生命周期T;超过当前所述服务线程的生命周期时,清除当前服务线程所述生命周期T=T0+T1*(1-n/N),其中T0为预设第一时间,T1为预设第二时间,n为当前服务线程数,N为最大服务线程数。
应当说明的是,上述实施例均可根据需要自由组合。以上所述仅是本发明的优选实施方式,应当指出,对于本技术领域的普通技术人员来说,在不脱离本发明原理的前提下,还可以做出若干改进和润饰,这些改进和润饰也应视为本发明的保护范围。

Claims (10)

  1. 一种通信方法,其特征在于,包括:
    S10移动终端发送多条并行的请求信息至中转服务器;
    S20中转服务器查询数据库获得与路由器对应的长连接服务器;
    S30中转服务器将所述多条并行的请求信息按照预设规则逐条发送至长连接服务器;
    S40长连接服务器转发所述请求信息至路由器;
    S50长连接服务器接收路由器发送的多条串行的响应消息并转发至中转服务器;
    S60中转服务器接收并处理所述响应消息,将所述串行的多条响应消息按照预设规则转换成并行的响应消息并发送至移动终端。
  2. 如权利要求1所述的通信方法,其特征在于,所述数据库存储有每个路由器与对应的长连接服务器的连接信息。
  3. 如权利要求2所述的通信方法,其特征在于,所述数据库为每个长连接服务器分配一个缓存数据库;每个缓存数据库存储长连接服务器的MAC地址以及所述MAC地址的哈希值。
  4. 如权利要求3述的通信方法,其特征在于,还包括步骤:
    S05当检测到当前的长连接服务器宕机时,计算所述长连接服务器的MAC地址的哈希值;
    在数据库中查询是否存在所述哈希值;若不存在,则清除数据库中当前长连接服务器的连接信息。
  5. 如权利要求1所述的通信方法,其特征在于,所述步骤S10移动终端发送多条并行的请求信息至中转服务器务器之后还包括步骤:
    S15中转服务器根据所述请求信息生成多条服务线程;所述中转服务器为每个服务线程分配生命周期T;超过当前所述服务线程的生命周期时,清除当前服务线程;
    所述生命周期T=T0+T1*(1-n/N),其中T0为预设第一时间,T1为预设第二时间,n为当前服务线程数,N为最大服务线程数。
  6. 一种通信系统,其特征在于,包括:移动终端、中转服务器、长连接服务器、数据库以及路由器;
    所述移动终端将并行的请求信息发送至所述中转服务器;
    所述中转服务器查询所述数据库获得与所述路由器对应的所述长连接服务器并将所述多条并行的请求信息按照预设规则逐条发送至长连接服务器;
    所述长连接服务器转发所述请求信息至所述路由器;以及,接收所述路由器发送的多条串行的响应消息并转发至中转服务器;
    所述中转服务器接收并处理所述响应消息,将所述串行的多条响应消息按照预设规则转换成并行的响应消息并发送至所述移动终端。
  7. 如权利要求6所述的通信系统,其特征在于,所述数据库存储有每个路由器与对应的长连接服务器的连接信息。
  8. 如权利要求7所述的通信系统,其特征在于,所述数据库为每个长连接服务器分配一个缓存数据库;每个缓存数据库存储长连接服务器的MAC地址以及所述MAC地址的哈希值。
  9. 如权利要求8所述的通信系统,其特征在于,还包括:
    清除模块,用于当检测到当前的长连接服务器宕机时,计算所述长连接服务器的MAC地址的哈希值;在缓存数据库中查询是否存在所述哈希值;若不存在,则清除缓存数据库中当前长连接服务器的连接信息。
  10. 如权利要求6所述的通信系统,其特征在于,所述中转服务器具体包括:
    线程控制模块,用于根据所述请求信息生成多条服务线程;以及用于为每个服务线程分配生命周期T;超过当前所述服务线程的生命周期时,清除当前服务线程;所述生命周期T=T0+T1*(1-n/N),其中T0为预设第一时间,T1为预设第二时间,n为当前服务线程数,N为最大服务线程数。
PCT/CN2016/103894 2016-01-25 2016-10-29 一种通信方法及系统 WO2017128789A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201610048569.4A CN105592163B (zh) 2016-01-25 2016-01-25 一种通信方法及系统
CN201610048569.4 2016-01-25

Publications (1)

Publication Number Publication Date
WO2017128789A1 true WO2017128789A1 (zh) 2017-08-03

Family

ID=55931366

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2016/103894 WO2017128789A1 (zh) 2016-01-25 2016-10-29 一种通信方法及系统

Country Status (2)

Country Link
CN (1) CN105592163B (zh)
WO (1) WO2017128789A1 (zh)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113645323A (zh) * 2021-07-29 2021-11-12 广州鲁邦通智能科技有限公司 一种高并发状态下防止mac地址重复写入的方法、单元和系统

Families Citing this family (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105592163B (zh) * 2016-01-25 2018-07-17 上海斐讯数据通信技术有限公司 一种通信方法及系统
CN106341345B (zh) * 2016-08-18 2019-12-20 北京奇虎科技有限公司 一种并发请求的处理方法及装置
CN106301944B (zh) * 2016-08-30 2020-02-11 上海斐讯数据通信技术有限公司 一种路由器网络中转读写方法及中转服务器
CN106850731A (zh) * 2016-10-14 2017-06-13 水熊有限公司 一种远程控制的方法、服务器和系统
CN106790607B (zh) * 2016-12-29 2020-11-03 北京奇虎科技有限公司 发送离线消息的方法及装置
CN112559134B (zh) * 2020-12-23 2023-04-07 安徽航天信息有限公司 一种分布式WebSocket集群构建方法、装置、系统及存储介质

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1992709A (zh) * 2005-12-27 2007-07-04 中兴通讯股份有限公司 一种终端设备和终端适配器间处理at命令的方法
CN102394867A (zh) * 2011-10-10 2012-03-28 深圳市金槌拍卖行有限公司 网络并发通讯请求转串行队列技术
CN102932444A (zh) * 2012-10-29 2013-02-13 上海银商资讯有限公司 金融实时交易系统中的负载均衡模块
US20140108596A1 (en) * 2012-10-17 2014-04-17 Wal-Mart Stores, Inc. Http parallel processing router
CN105592163A (zh) * 2016-01-25 2016-05-18 上海斐讯数据通信技术有限公司 一种通信方法及系统

Family Cites Families (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101719929A (zh) * 2009-11-20 2010-06-02 山东中创软件商用中间件股份有限公司 一种实现Web Service下实时数据传输的方法
CN104009938B (zh) * 2014-06-17 2016-08-17 合一网络技术(北京)有限公司 基于路由层面的长连接的方法和系统
CN104144080B (zh) * 2014-07-24 2018-01-02 上海斐讯数据通信技术有限公司 采用远端设备对终端设备进行管理的系统及方法
CN105024860A (zh) * 2015-07-23 2015-11-04 上海斐讯数据通信技术有限公司 一种远程通信控制方法及系统

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1992709A (zh) * 2005-12-27 2007-07-04 中兴通讯股份有限公司 一种终端设备和终端适配器间处理at命令的方法
CN102394867A (zh) * 2011-10-10 2012-03-28 深圳市金槌拍卖行有限公司 网络并发通讯请求转串行队列技术
US20140108596A1 (en) * 2012-10-17 2014-04-17 Wal-Mart Stores, Inc. Http parallel processing router
CN102932444A (zh) * 2012-10-29 2013-02-13 上海银商资讯有限公司 金融实时交易系统中的负载均衡模块
CN105592163A (zh) * 2016-01-25 2016-05-18 上海斐讯数据通信技术有限公司 一种通信方法及系统

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113645323A (zh) * 2021-07-29 2021-11-12 广州鲁邦通智能科技有限公司 一种高并发状态下防止mac地址重复写入的方法、单元和系统

Also Published As

Publication number Publication date
CN105592163B (zh) 2018-07-17
CN105592163A (zh) 2016-05-18

Similar Documents

Publication Publication Date Title
WO2017128789A1 (zh) 一种通信方法及系统
US11411897B2 (en) Communication method and communication apparatus for message queue telemetry transport
JP5122025B2 (ja) 中継器およびチップ回路
WO2018184491A1 (zh) 资源获取方法、装置及系统
JP4755683B2 (ja) ピア・ツー・ピア(p2p)・ネットワークを効率的に拡張するための方法、装置、およびプログラム
KR101592459B1 (ko) 패킷 포워딩 방법 및 시스템
JP2016540448A (ja) 仮想拡張lanの通信方法、装置、及びシステム
US11202252B2 (en) Inclusion of a message proxy in a service based architecture
WO2014190791A1 (zh) 一种网关设备身份设置的方法及管理网关设备
CN104301238A (zh) 一种报文处理方法、装置及系统
US20220286495A1 (en) Domain Name Query Method and Related Device
WO2020073907A1 (zh) 转发表项的更新方法及装置
JP2016525256A (ja) 冗長データアクセスを提供するための方法および装置
WO2020038443A1 (zh) 桥接通信的方法和设备
WO2020206783A1 (zh) 一种数据传输调度方法和系统
WO2011072610A1 (zh) 一种内容发布与获取的方法、装置和系统
JP2016515361A (ja) アプリケーションにより提供される送信メタデータに基づくネットワーク送信調整
CN103281317A (zh) 一种软件定义网络的攻击测试方法
CN104468620A (zh) 一种无线局域网中arp劫持与性能增强的方法
EP2979166A1 (en) Network printing
KR102526770B1 (ko) 추가의 네트워크 주소 변환 테이블을 참조하여 빠른 패킷 포워딩을 제공하는 전자 장치
CN114553965B (zh) 内网设备的调度方法、网络设备及存储介质
CN111966502B (zh) 用于调整实例数的方法、装置、电子设备及可读存储介质
JP5815838B2 (ja) ルータにおいて通信を管理するための技法
KR102565409B1 (ko) 인스턴스 수 조절 방법, 장치, 전자 기기 및 판독 가능한 저장 매체

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 16887662

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 16887662

Country of ref document: EP

Kind code of ref document: A1