Request monitoring method, network device and storage medium
By obtaining index data in the WebSocket connection on the iOS side, the problem that the existing technology cannot monitor the WebSocket connection process is solved, real-time monitoring and improvement of the connection process is achieved, and connection efficiency and success rate are improved.
Patent Information
- Application Number
- CN202111498465.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-09
- Publication Date
- 2024-12-03
- Estimated Expiration
- 2041-12-09
AI Technical Summary
The existing technology cannot monitor and analyze the metric data of WebSocket connections in real time, resulting in the inability to effectively improve the connection process.
The iOS side uses a buried point monitoring method to obtain the metric data during the WebSocket connection process, including the request start and completion time, the HTTP request sending and receiving time, SSL authentication and handshake time, etc., and use the exchange function to add the monitoring method to the WebSocket connection call In the method, monitoring and improvement of the connection process is achieved.
Real-time monitoring of WebSocket connections is realized, and it can detect slow or failed connections in a timely manner, and targeted measures are taken to improve connection efficiency and success rate.
Smart Images

Figure CN114363204B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of Internet technology, and in particular to a request monitoring method, network equipment and storage medium. Background Art
[0002] SRWebSocket is a framework for establishing WebSocket connections in iOS, which was open sourced by Facebook. Currently, many businesses need to use the WebSocket protocol, and iOS uses the SocketRocket framework to initiate WebSocket requests. The WebSocket protocol is a two-way simultaneous communication protocol with a wide range of uses, such as social networking, gaming, or collaborative office scenarios.
[0003] However, there is currently no way to obtain indicator data during the process of establishing a WebSocket connection, and thus it is impossible to improve the WebSocket connection. Summary of the invention
[0004] The purpose of the embodiments of the present invention is to provide a request monitoring method, a network device and a storage medium, which can obtain indicator data used to analyze the speed of WebSocket connection, the speed of loading and whether the connection is successful, so as to effectively improve the WebSocket connection.
[0005] To solve the above technical problems, an embodiment of the present invention provides a request monitoring method, including: embedding a monitoring method in each method called to establish a WebSocket connection on the iOS side; wherein the monitoring method is used to host the called method; when a WebSocket connection is initiated on the iOS side, the indicator data in the process of the WebSocket connection is obtained according to the hosting time of the hosted method by the monitoring method.
[0006] An embodiment of the present invention also provides a network device, comprising: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the above-mentioned request monitoring method.
[0007] An embodiment of the present invention further provides a computer-readable storage medium storing a computer program, and the computer program implements the above-mentioned request monitoring method when executed by a processor.
[0008] Compared with the related art, the embodiment of the present invention monitors the process of the connection according to the previously embedded monitoring method by embedding a monitoring method in the method called by the iOS end to establish a WebSokect connection. Since the method called by the iOS end to establish a WebSokect connection has already embedded a monitoring method, when the iOS end initiates a WebSokect connection, the process of establishing the WebSokect connection on the iOS end can be monitored according to the embedded monitoring method, so that the speed of establishing the WebSokect connection on the iOS end, the speed of loading, and whether the connection is successful can be monitored. When the WebSokect connection is slow to be established or loaded slowly or the connection fails, targeted measures can be taken to make improvements.
[0009] In addition, the method of burying the monitoring method in the method called by the iOS end to establish the WebSocket connection includes: using the exchange function to add the monitoring method to the method called by the iOS end to establish the WebSocket connection. By adding the monitoring method to the method called by the iOS end to establish the WebSokect connection through the exchange function, the monitoring method can be buried in the method called by the iOS end to establish the WebSokect connection, so as to achieve the traceless burying of the monitoring method.
[0010] In addition, when a WebSocket connection is initiated on the iOS side, the indicator data of the WebSocket connection process is obtained according to the hosting time of the monitoring method to the hosting method, including: when the iOS side calls the method with the monitoring method to initiate the WebSocket connection, the monitoring method is called by the exchange function; and the indicator data of the WebSocket connection process is obtained according to the hosting time of the monitoring method to the hosting method. When the iOS side calls the method with the monitoring method to initiate the WebSokect connection, the monitoring method is called by the preset exchange function, and the process of monitoring the connection is monitored by the called monitoring method, so that the monitoring of the establishment of the WebSokect connection on the iOS side can be realized.
[0011] In addition, when the called methods include an interface calling method that is before the request start position, the indicator data obtained include: the time point when the request starts to connect; when the called methods include a connection completion method, the indicator data obtained include: the time point when the connection is completed; when the called methods include a connection establishment success method, the indicator data obtained include: the time point when the Http request starts to be sent, and the Http request is used to request an upgrade of the websokcet; when the called methods include a method for starting to receive response header information, the indicator data obtained include: the time point when the Http request is sent, the time when the Http request is sent, and the time point when the response starts to be received, wherein the time when the Http request is sent is the difference between the time point when the Http request is sent and the time point when the Http request starts to be sent; when the called methods include a method for completing receiving response header information, the indicator data obtained include: the time point when the response is received and the response time, wherein the response time is the difference between the time point when the response is received and the time point when the response starts to be received. In addition, when the WebSocket connection is a WSS connection, when the methods called include the connection completion method, the obtained indicator data also includes: the start time of SSL authentication, and the sum of the DNS resolution time and the TCP three-way handshake connection time, where the sum of the DNS resolution time and the TCP three-way handshake connection time is the difference between the time when the connection is completed and the time when the request starts; when the methods called include the connection establishment success method, the obtained indicator data also includes: the time when the SSL handshake is successful, and the SSL handshake time, where the SSL handshake time is the difference between the time when the SSL handshake is successful and the start time of SSL authentication. By adding the monitoring method to any one or any combination of the interface calling method, connection completion method, http request establishment method, start receiving response header information method and response header information completion method called by the iOS end to establish a WebSokect connection, various indicator data in the process of WebSocket connection can be obtained.
[0012] In addition, when the iOS side initiates a WebSocket connection based on the SRWebSocket-master version framework, the method also includes: when it is necessary to use a proxy to establish a WebSocket connection, the traffic is transferred to the proxy server to achieve traffic transfer, thereby speeding up the WebSokect connection on the iOS side.
[0013] In addition, before transferring traffic to the proxy server, in the method for setting up the proxy called by the iOS end to establish the WebSocket connection, the proxy transfer method is embedded; the proxy transfer method is used to host the method for setting up the proxy, and the proxy address and proxy port of the SRProxyConnect object are set to the address and port of the proxy server. The SRProxyConnect object is created before the method for setting up the proxy. In the case where a WebSocket connection needs to be established using a proxy, the proxy address and proxy port of the SRProxyConnect object can be modified to achieve traffic transfer and speed up the WebSokect connection. BRIEF DESCRIPTION OF THE DRAWINGS
[0014] One or more embodiments are exemplarily described by the pictures in the corresponding drawings, and these exemplary descriptions do not constitute limitations on the embodiments.
[0015] Figure 1 It is a flowchart of a request monitoring method provided by an embodiment of the present invention;
[0016] Figure 2 is a principle example diagram of a request monitoring method provided by an embodiment of the present invention;
[0017] Figure 3 is a schematic diagram of the module structure of a request monitoring device provided by an embodiment of the present invention;
[0018] Figure 4 It is a schematic diagram of the structure of a network device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0019] In order to make the purpose, technical scheme and advantages of the present invention clearer, the embodiments of the present invention will be described in detail below in conjunction with the accompanying drawings. However, it will be appreciated by those skilled in the art that in the embodiments of the present invention, many technical details are provided to enable the reader to better understand the present application. However, even without these technical details and various changes and modifications based on the following embodiments, the technical scheme claimed in the present application can be implemented.
[0020] In one embodiment, a request monitoring method is involved, which includes a monitoring method that is embedded in each method called by the iOS end to establish a WebSocket connection, wherein the monitoring method is used to host the called method; when the iOS end initiates a WebSocket connection, the indicator data of the WebSocke connection process is obtained according to the hosting time of the hosted method by the monitoring method, so as to monitor the speed of the iOS end establishing the WebSokect connection and whether the connection is successful, and take targeted measures to improve it when the WebSokect connection is slow or fails to be established.
[0021] It should be noted that the request monitoring method provided in the embodiment of the present invention can be applied to application performance management service (Application Performance Management, APM for short) products.
[0022] The specific process of the request monitoring method provided by the embodiment of the present invention is as follows: Figure 1 As shown, the following steps are included:
[0023] S101: A monitoring method is respectively embedded in each method called to establish a WebSocket connection on the iOS side.
[0024] The monitoring method can be set according to actual needs, and it only needs to implement the corresponding monitoring function in the process of establishing a WebSocket connection on the iOS side. The embodiment of the present invention does not impose any specific restrictions on this.
[0025] The method of embedding monitoring can be to add a preset monitoring method to the method called by the iOS end to establish a WebSokect connection. When the iOS end establishes a WebSokect connection and calls the corresponding method, the added monitoring method will also be called accordingly, so that the situation of establishing a WebSokect connection on the iOS end can be monitored accordingly. The specific embedding method of the monitoring method can be carried out according to the actual situation, and the embodiment of the present invention does not make specific restrictions on this.
[0026] S102: When a WebSocket connection is initiated on the iOS end, the index data in the process of the WebSocket connection is obtained according to the hosting time of the hosted method by the monitoring method, wherein the monitoring method is used to host the called method.
[0027] Among them, the indicator data obtained during the WebSocket connection process may include indicator data at any time point during the WebSocket connection process, so that the WebSokect connection speed, loading speed, and whether the connection is successful can be analyzed based on the obtained indicator data, and then targeted measures can be taken to make improvements, such as repairing abnormal network conditions.
[0028] Since the monitoring method has been added to the method called by the iOS end to initiate a WebSokect connection, the monitoring method is also triggered when the iOS end initiates a WebSokect connection, and the process of establishing the WebSokect connection can be monitored accordingly according to the triggered monitoring method.
[0029] The request monitoring method provided by the embodiment of the present invention monitors the process of the connection according to the previously buried monitoring method by embedding a monitoring method in the method called by the iOS end to establish a WebSokect connection. Since the method called by the iOS end to establish a WebSokect connection has already embedded a monitoring method, when the iOS end initiates a WebSokect connection, the process of establishing the WebSokect connection on the iOS end can be monitored according to the buried monitoring method, thereby monitoring the speed of establishing the WebSokect connection on the iOS end, the speed of loading, and whether the connection is successful. When the WebSokect connection is established slowly, loaded slowly, or the connection fails, targeted measures can be taken to make improvements.
[0030] In a specific example, S101 may include: using an exchange function to add a monitoring method to a method called by the iOS end to establish a WebSocket connection.
[0031] Among them, using the swap function to add the monitoring method to the method called for establishing the WebSocket connection refers to using the Method Swizzle technology to add the monitoring method to the method called for establishing the WebSocket connection.
[0032] By exchanging functions to add the monitoring method to the method called for establishing a WebSokect connection, the monitoring method can be embedded in the method called for establishing a WebSokect connection on the iOS side, thus achieving traceless embedding of the monitoring method.
[0033] In a specific example, when the methods called include an interface calling method before the request start position, such as an open method, the obtained indicator data include: the time point when the request starts to connect; when the methods called include a connection completion method, the obtained indicator data include: the time point when the connection is completed; when the methods called include a connection establishment success method, the obtained indicator data include: the time point when the Http request starts to be sent, and the Http request is used to request the upgrade of the websocket. Websocket is an upgraded protocol of the http protocol. Compared with the http protocol that requires a response for each message sent, the websocket protocol allows the client to send data at any time, and the server can also send data at any time without waiting for the response of the other end. Therefore, by adding a field for requesting an upgrade to websocket on the basis of the http protocol, after the server replies with a response supporting the websocket protocol, the websocket protocol can be used in subsequent communications.
[0034] When the methods called include a method for starting to receive response header information, the indicator data obtained include: the time point when the Http request is completed, the time when the Http request is sent, and the time point when the response starts to be received, wherein the time when the Http request is sent is the difference between the time point when the Http request is completed and the time point when the Http request starts to be sent; when the methods called include a method for completing receiving response header information, the indicator data obtained include: the time point when the response is completed and the response time, wherein the response time is the difference between the time point when the response is completed and the time point when the response starts to be received.
[0035] In addition, when the WebSocket connection is a WSS connection, when the methods called include a connection completion method, the obtained indicator data also includes: the start time of SSL authentication, and the sum of the DNS resolution time and the TCP three-way handshake connection time; wherein, the sum of the DNS resolution time and the TCP three-way handshake connection time is the difference between the time when the connection is completed and the time when the connection is requested to start. When the methods called include a connection establishment success method, the obtained indicator data also includes: the time when the SSL handshake is successful, and the SSL handshake time, wherein the SSL handshake time is the difference between the time when the SSL handshake is successful and the start time of SSL authentication. Since the WSS connection has an additional handshake interaction process compared to the WS connection, the SSL handshake time can also be obtained when the WebSocket connection is a WSS connection.
[0036] That is to say, the monitoring method can be added to any one or any combination of the interface calling method, connection completion method, http request establishment method, response header information start receiving method and response header information receiving completion method before the request start position called by the iOS end to establish the WebSokect connection by using the exchange function, so as to obtain various indicator data in the process of the WebSocket connection. In one example, the obtained indicator data is stored in the monitoring object corresponding to the WebSocket connection; wherein the monitoring object corresponding to the WebSocket connection is created according to the instance object of the WebSocket connection.
[0037] It can be understood that the more monitoring methods are added to the above methods called by the iOS end to establish a WebSokect connection, the clearer and more complete the monitoring of the situation of the iOS end establishing a WebSokect connection can be achieved.
[0038] By using the exchange function to add the monitoring method to at least one of the interface calling method, connection completion method, http request establishment method, response header information start receiving method and response header information receiving completion method called by the iOS side to establish the WebSokect connection before the request start position, the monitoring method can be embedded, thereby realizing the monitoring of the situation of establishing the WebSokect connection on the iOS side.
[0039] In a specific example, in S102, that is, when a WebSokect connection is initiated on the iOS side, the process of monitoring the connection is monitored according to a monitoring method, including: when a method with a monitoring method for a buried point is called on the iOS side to initiate a WebSokect connection, the monitoring method for the buried point is called using an exchange function, and the process of monitoring the connection is monitored using the monitoring method.
[0040] By initiating a WebSokect connection by calling a method with a monitoring method on the iOS side, using a preset exchange function to call the monitoring method, and using the called monitoring method to monitor the connection process, the monitoring of the establishment of a WebSokect connection on the iOS side can be achieved.
[0041] In a specific example, when the iOS side initiates a WebSocket connection based on the SRWebSocket-master version framework, the request monitoring method provided by the embodiment of the present invention also includes: when it is necessary to use a proxy to establish a WebSocket connection, the traffic is transferred to the proxy server, such as transferring the traffic to the CDN server. Thereby, when the establishment of the WebSokect connection on the iOS side is slow or fails, the traffic transfer is achieved, so that the speed of the WebSokect connection on the iOS side is accelerated. Among them, the decision on whether to use a proxy to establish a WebSocket connection can be implemented on the server side, and the server side notifies the client whether it needs to use a proxy to establish a WebSocket connection. The embodiment of the present invention provides a method for transferring traffic to a proxy server, and does not make specific restrictions on how to make decisions on how to transfer traffic based on indicator data during the WebSocket connection process.
[0042] In one example, before transferring traffic to the proxy server, the method for setting up the proxy called by establishing a WebSocket connection on the iOS side, such as the openConnection method, embeds the proxy transfer method; the proxy transfer method is used to host the method for setting up the proxy, such as the openConnection method, and sets the proxy address and proxy port of the SRProxyConnect object to the address and port of the proxy server. The SRProxyConnect object is created before the openConnection method. By embedding the proxy transfer method in the method called by establishing a WebSokect connection on the iOS side, when it is necessary to use a proxy to establish a WebSocket connection, traffic can be transferred and the speed of the WebSokect connection can be accelerated. In addition, in one example, the proxy transfer method can be added to the openConnection method through a swap function to achieve seamless embedding.
[0043] That is to say, the iOS end initiates a WebSokect connection based on the SRWebSocket-master version framework. After completing the call of the open method and before calling the connection completion method, the proxy transfer method can be embedded in the method of the SRProxyConnect class before establishing the connection (such as the openConnection method). For example, after creating the SRProxyConnect object, in the openConnection method called by the iOS end to establish the WebSokect connection, the proxy transfer method of the SRProxyConnect object corresponding to the request is used to embed the exchange function to realize that when the establishment of the WebSokect connection on the iOS end is slow or fails, the requested traffic is transferred to the proxy server such as the CDN server to realize the transfer of traffic, so as to speed up the WebSokect connection on the iOS end and improve the user experience.
[0044] In order to further illustrate the request monitoring method provided by the embodiment of the present invention, a specific example is used below for illustration. Figure 2 , which is a principle example diagram of the request monitoring method provided by an embodiment of the present invention. Specifically, in establishing a WebSokect connection on the iOS side, the open method, the connection completion method (connectDone), the method of sending an http request to establish a connection (didconnect), the method of starting to receive the response header information (readHTTPHeader), and the method of receiving the response header information completion (HTTPHeadersDidFinish) are used to embed corresponding monitoring methods to obtain indicator data during the WebSocket connection process, and in the openConnection method, the proxy transfer method is embedded to modify the proxy address and proxy port to achieve the transfer of the requested traffic to the proxy server. In this way, when establishing a WebSokect connection on the iOS side, the corresponding monitoring indicators can be obtained through the embedded monitoring method to monitor the process of establishing the WebSokect connection on the iOS side; and the traffic can be transferred through the set proxy transfer method to speed up the process of WebSokect connection and improve the user experience. The following is a description of the following. Figure 2 To explain in detail:
[0045] In step 210, a websocket request using the SRWebSocket framework is initiated through an application (app) on the device.
[0046] Then, enter step 211, call the open method of SRWebSocket, and manage the open method by using a swap function such as MethodSwizzle, collectively referred to as hook_open. Enter hook_open, first obtain the instance object of the SRWebSocket requested by the websocket, and create a custom monitoring object corresponding to the request. The URL of the request can be obtained through the SRWebSocket instance object of the request, as well as the time point when the request starts to connect through the hook_open mark. This time mark is startConnectTs. Through the monitoring instance object, set the key to SRWebSocket or set the key to the hash value of SRWebSocket to save it. Since the requests are concurrent, the monitoring instance of the current request can be distinguished by the saved key. Then the request is returned to the original open method for connection. In another example, it is not limited to the open method. Any method before SRWebSocket creates a data stream to open can be used for embedding.
[0047] If the SRWebSocket framework is the current SRWebSocket-master version, you can embed the proxy transfer method in the method before establishing the connection of the SRProxyConnect class, and host the methods before establishing the connection of the SRProxyConnect class, such as the openConnection method. After hosting, the two proxy addresses and proxy ports of httpProxyHost and _httpProxyPort are modified through the setValue:forKey method of the object, and httpProxyHost is set to the address of the proxy server such as the CDN server, and httpProxyPort is set to the port of the proxy server such as the CDN server. Then return to the original openConnection to continue execution to realize the transfer of traffic. As in step 212, create an SRProxyConnect object, and in step 213, host the openConnection method through the proxy transfer method after calling the openConnection method, and modify the proxy address and proxy port of the SRProxyConnect object after hosting.
[0048] In step 214, when the TCP three-way handshake connection succeeds or fails, it will also return to a method of the SRWebSocket library. Since the methods of different versions are different, they are collectively referred to as connectDone (connection completion method). Through the monitoring method hook_connectDone buried in connectDone, connectDone is hosted. By the moment when hook_connectDone currently hosts connectDone, the time point when the current connect connection is completed can be obtained. And by obtaining the current SRWebSocket instance object or the hash value of SRWebSocket to obtain the monitoring instance of the current request, the requested monitoring instance saves the time point when the current connect connection is completed. This time mark is endConnectTs. If it is a WSS request, the current time point also needs to be saved as the start time point of SSL authentication, and this time mark is startSSLTs. Get the DNS resolution time + TCP three-way handshake connection time and, specifically, endConnectTs-startConnectTs.
[0049] In step 215, after the request successfully establishes the connection, the request will enter the method of the SRWebSocket framework for successful connection establishment, collectively referred to as the didConnect method. Method Swizzle technology is also used to embed the monitoring method in didConnect to implement the hosting of the didConnect method. The monitoring methods embedded in didConnect are collectively referred to as hook_didConnect. The monitoring instance of the current request is obtained by obtaining the current SRWebSocket instance object or the hash value of SRWebSocket. If the request is a WSS request, the current hosting time needs to be marked as the time point when the SSL handshake of the monitoring instance is successful. This time mark is endSSLTs, and the current hosting time is also marked as the time point when the monitoring instance starts to send an Http request. The Http request is used to request an upgrade of the websokcet. This time mark is startSendRequestTs. If it is a WSS request, the SSL handshake time obtained is endSSLTs-startSSLTs. Then return to execute the original didConnect method and continue execution.
[0050] In step 216, after the request successfully establishes the connection, the request will enter the method of starting to receive the response header information of the SRWebSocket framework, collectively referred to as the readHTTPHeader method. Similarly, the Method Swizzle technology is used to embed the monitoring method in readHTTPHeader to implement the hosting of the readHTTPHeader method. The monitoring methods embedded in readHTTPHeader are collectively referred to as hook_readHTTPHeader. The monitoring instance of the current request is obtained by obtaining the current SRWebSocket instance object or the hash value of SRWebSocket, and the current hosting time needs to be marked as the time point when the Http request of the monitoring instance is sent. This time mark is endSendRequestTs, and the time to send the request is endSendRequestTs-startSendRequestTs. At the same time, the current hosting time is also marked as the time point when the response of the monitoring instance starts to be received. This time mark is startResposeTs. Then return to execute the original readHTTPHeader method and continue execution.
[0051] In step 217, when the weboskcet request response is completed, the SRWebSocket framework will enter the method for completing the reception of the response header information, which is collectively referred to as the HTTPHeadersDidFinish method. Similarly, the Method Swizzle technology is used to embed the monitoring method in HTTPHeadersDidFinish to implement the hosting of the HTTPHeadersDidFinish method. The monitoring methods embedded in HTTPHeadersDidFinish are collectively referred to as hook_HTTPHeadersDidFinish. The monitoring instance of the current request is obtained by obtaining the current SRWebSocket instance object or the hash value of SRWebSocket. The current hosting time needs to be marked as the time point when the Http request response of the monitoring instance is received. This time mark is endResposeTs. The time for responding to respose is endResposeTs-startResposeTs. Return to the original execution of _HTTPHeadersDidFinish method to continue execution.
[0052] In step 218, weboskcet data transmission / reception begins.
[0053] By embedding a monitoring method in the method called by the iOS end to establish a WebSokect connection, when the iOS end initiates a WebSokect connection, the process of the connection is monitored according to the pre-embedded monitoring method. Since the method called by the iOS end to establish a WebSokect connection has already embedded a monitoring method, when the iOS end initiates a WebSokect connection, the monitoring of the process of establishing a WebSokect connection on the iOS end can be realized according to the embedded monitoring method, so that the speed of establishing a WebSokect connection on the iOS end, the speed of loading, and whether the connection is successful can be monitored. When the establishment of a WebSokect connection is slow or the loading is slow or the connection fails, targeted measures can be taken to make improvements. For example, from the first time point monitored to the last time point monitored, the connection time of the entire WebSokect can be obtained, so that the speed of establishing a WebSokect connection on the iOS end can be monitored, and whether the connection is successful can be determined based on whether each time point can be monitored. Moreover, since each time point in the entire WebSokect connection process is monitored, the time of each stage or time point in the WebSokect connection process can be analyzed according to actual needs.
[0054] In one example, the indicator data during the WebSocket connection process can be fed back to the server, so that the server can obtain the speed of establishing the WebSokect connection, the speed of loading, and whether the connection is successful, and then take targeted measures to improve it when the WebSokect connection is slow to establish, load slowly, or fail to connect.
[0055] The step division of the above methods is only for the purpose of clear description. When implemented, they can be combined into one step or some steps can be split and decomposed into multiple steps. As long as they contain the same logical relationship, they are all within the scope of protection of this patent; adding insignificant modifications to the algorithm or process or introducing insignificant designs without changing the core design of the algorithm and process are all within the scope of protection of this patent.
[0056] In a specific example, a request monitoring device 200 is involved, such as Figure 3 As shown, it includes a tracking module 201 and a monitoring module 202. The functions of each module are described in detail as follows:
[0057] The tracking module 201 is used to track the monitoring method in each method called by the iOS end to establish the WebSocket connection; wherein the monitoring method is used to host the called method.
[0058] The monitoring module 202 is used to obtain the indicator data in the process of the WebSocket connection according to the hosting time of the hosting method of the monitoring method when the WebSocket connection is initiated on the iOS side. In one example, the obtained indicator data is stored in the monitoring object corresponding to the WebSocket connection; wherein the monitoring object corresponding to the WebSocket connection is created according to the instance object of the WebSocket connection.
[0059] Further, the tracking module 201 is also used to: use the exchange function to add the monitoring method to each method called by the iOS end to establish a WebSocket connection. In one example, when the methods called include the interface call method before the request start position, the obtained indicator data includes: the time point when the request starts to connect; when the methods called include the connection completion method, the obtained indicator data includes: the time point when the connection is completed; when the methods called include the connection establishment success method, the obtained indicator data includes: the time point when the Http request starts to be sent, and the Http request is used to request the upgrade of the websokcet; when the methods called include the method of starting to receive the response header information, the obtained indicator data includes: the time point when the Http request is sent, the time when the Http request is sent, and the time point when the response starts to be received, wherein the time when the Http request is sent is the difference between the time point when the Http request is sent and the time point when the Http request is sent; when the methods called include the method of receiving the response header information completion, the obtained indicator data includes: the time point when the response is received and the response time, wherein the response time is the difference between the time point when the response is received and the time point when the response starts to be received. In addition, when the WebSocket connection is a WSS connection, when the methods called include the connection completion method, the obtained indicator data also includes: the start time of SSL authentication, and the sum of the DNS resolution time and the TCP three-way handshake connection time, where the sum of the DNS resolution time and the TCP three-way handshake connection time is the difference between the time when the connection is completed and the time when the request starts; when the methods called include the connection establishment success method, the obtained indicator data also includes: the time when the SSL handshake is successful, and the SSL handshake time, where the SSL handshake time is the difference between the time when the SSL handshake is successful and the start time of SSL authentication. By adding the monitoring method to any one or any combination of the interface calling methods (such as the open method) called by the iOS end to establish a WebSokect connection before the request start position, the connection completion method, the method of sending an http request to establish a connection, the method of starting to receive the response header information, and the method of completing the receiving response header information, various indicator data in the process of WebSocket connection can be obtained.
[0060] Furthermore, the monitoring module 202 is also used to: when a method with a monitoring method is called on the iOS side to initiate a WebSocket connection, the monitoring method is called using an exchange function; and the indicator data during the WebSocket connection process is obtained according to the hosting time of the monitoring method for the hosting method.
[0061] Furthermore, the request monitoring device 200 provided in the embodiment of the present invention also includes a proxy module (not shown in the figure), wherein the proxy module is used to: when it is necessary to use a proxy to establish a WebSocket connection, transfer the traffic to the proxy server to achieve traffic transfer and speed up the WebSokect connection on the iOS side.
[0062] Furthermore, the tracking module 201 is also used to track the proxy transfer method in the method for setting up the proxy called by establishing a WebSocket connection on the iOS side before transferring the traffic to the proxy server; the proxy transfer method is used to host the method for setting up the proxy, and the proxy address and proxy port of the SRProxyConnect object are set to the address and port of the proxy server, wherein the SRProxyConnect object is created before the openConnection method. In one example, the proxy transfer method is added to the method for setting up the proxy using the exchange function to achieve traceless tracking.
[0063] It is not difficult to find that this embodiment is a device embodiment corresponding to the aforementioned method embodiment, and this embodiment can be implemented in conjunction with the aforementioned method embodiment. The relevant technical details mentioned in the aforementioned method embodiment are still valid in this embodiment, and in order to reduce repetition, they are not repeated here. Accordingly, the relevant technical details mentioned in this embodiment can also be applied in the aforementioned method embodiment.
[0064] It is worth mentioning that all modules involved in this embodiment are logic modules. In practical applications, a logic unit can be a physical unit, a part of a physical unit, or a combination of multiple physical units. In addition, in order to highlight the innovative part of the present invention, this embodiment does not introduce units that are not closely related to solving the technical problem proposed by the present invention, but this does not mean that there are no other units in this embodiment.
[0065] In one embodiment, a network device is provided, such as Figure 4 As shown, it includes at least one processor 301; and a memory 302 that is communicatively connected to the at least one processor 301; wherein the memory 302 stores instructions that can be executed by the at least one processor 301, and the instructions are executed by the at least one processor 301 so that the at least one processor 301 can execute the above-mentioned request monitoring method.
[0066] The memory 302 and the processor 301 are connected in a bus manner, and the bus may include any number of interconnected buses and bridges, and the bus connects various circuits of one or more processors 301 and the memory 302 together. The bus can also connect various other circuits such as peripheral devices, voltage regulators, and power management circuits, which are well known in the art and are therefore not further described herein. The bus interface provides an interface between the bus and the transceiver. The transceiver can be one element or multiple elements, such as multiple receivers and transmitters, providing a unit for communicating with various other devices on a transmission medium. The data processed by the processor 301 is transmitted on a wireless medium through an antenna, and further, the antenna also receives data and transmits the data to the processor 301.
[0067] The processor 301 is responsible for managing the bus and general processing, and can also provide various functions, including timing, peripheral interfaces, voltage regulation, power management and other control functions. The memory 302 can be used to store data used by the processor 301 when performing operations.
[0068] In one embodiment, a computer-readable storage medium is provided, which stores a computer program, and when the computer program is executed by a processor, the above method embodiment is implemented.
[0069] That is, those skilled in the art can understand that all or part of the steps in the above-mentioned embodiment method can be completed by instructing the relevant hardware through a program, and the program is stored in a storage medium, including a number of instructions to enable a device (which can be a single-chip microcomputer, chip, etc.) or a processor to execute all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk and other media that can store program codes.
[0070] Those skilled in the art will appreciate that the above embodiments are specific embodiments for implementing the present invention, and that in actual applications, various changes may be made in form and detail without departing from the spirit and scope of the present invention.
Claims
1. A request monitoring method, characterized in that: include: A monitoring method is respectively embedded in each method called by the iOS end to establish a WebSocket connection; wherein the monitoring method is used to host the called method; When the iOS terminal initiates a WebSocket connection, according to the hosting time of the hosting method by the monitoring method, the indicator data in the process of the WebSocket connection is obtained; The hosting time is the time during which the hosting method is running; When the methods called include an interface calling method before the request start position, the obtained indicator data include: the time point when the request starts to connect; When the methods called include a connection completion method, the obtained indicator data include: the time point when the connection is completed; When the methods called include a connection establishment success method, the obtained indicator data include: the time point when the Http request is started to be sent, and the Http request is used to request an upgrade of the websokcet; When the methods called include a method for starting to receive response header information, the obtained indicator data include: the time point when the Http request is completed, the time when the Http request is sent, and the time point when the response starts to be received, wherein the time when the Http request is sent is the difference between the time point when the Http request is completed and the time point when the Http request starts to be sent; When the called methods include a method for completing the reception of response header information, the acquired indicator data include: the time point when the response reception is completed, and the response time, wherein the response time is the difference between the time point when the response reception is completed and the time point when the response starts to be received.
2. The request monitoring method according to claim 1, characterized in that: The method for burying monitoring in the method called by establishing a WebSocket connection on the iOS side includes: The monitoring method is added to each method called by the iOS end to establish a WebSocket connection using an exchange function.
3. The request monitoring method according to claim 2, characterized in that: When the iOS terminal initiates a WebSocket connection, obtaining indicator data in the process of the WebSocket connection according to the hosting time of the hosting method by the monitoring method includes: When the iOS end calls the method having the monitoring method in the embedding point to initiate a WebSocket connection, the monitoring method is called using the exchange function; According to the hosting time of the hosting method by the monitoring method, the indicator data in the process of the WebSocket connection is obtained.
4. The request monitoring method according to claim 1, characterized in that: In the case where the WebSocket connection is a WSS connection, When the methods called include a connection completion method, the obtained indicator data also includes: the start time of SSL authentication, and the sum of DNS resolution time and TCP three-way handshake connection time, wherein the sum of DNS resolution time and TCP three-way handshake connection time is the difference between the time of connection completion and the time of requesting to start the connection; When the called methods include a successful connection establishment method, the acquired indicator data also includes: the time point when the SSL handshake is successful, and the SSL handshake time, wherein the SSL handshake time is the difference between the time point when the SSL handshake is successful and the start time point of the SSL authentication.
5. The request monitoring method according to any one of claims 1 to 4, characterized in that: In the case where the iOS terminal initiates a WebSocket connection based on the SRWebSocket-master version framework, the method further includes: When a proxy is needed to establish a WebSocket connection, the traffic is transferred to the proxy server.
6. The request monitoring method according to claim 5, characterized in that: Before transferring the traffic to the proxy server, the method further includes: In the method for setting up a proxy called by the iOS end to establish a WebSocket connection, a method for transferring a proxy is embedded; The proxy transfer method is used to host the method for setting a proxy, and sets the proxy address and proxy port of the SRProxyConnect object to the address and port of the proxy server, wherein the SRProxyConnect object is created before the method for setting a proxy.
7. The request monitoring method according to any one of claims 1 to 4, characterized in that: The acquired indicator data is stored in the monitoring object corresponding to the WebSocket connection; The monitoring object corresponding to the WebSocket connection is created according to the instance object of the WebSocket connection.
8. A network device, characterized in that: include: at least one processor; as well as, a memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the request monitoring method according to any one of claims 1 to 7.
9. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the request monitoring method according to any one of claims 1 to 7 is implemented.
