A network optimization method and related equipment
By acquiring and comparing the execution time of functional functions in the communication network, and increasing the execution time threshold in weak network conditions, the problem of cumbersome code modification in different network libraries is solved, and efficient communication network optimization is achieved.
Patent Information
- Application Number
- CN202110244113.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-03-05
- Publication Date
- 2025-10-31
- Estimated Expiration
- 2041-03-05
AI Technical Summary
In existing technologies, optimizing communication networks requires modifying code in different network libraries, which makes the process cumbersome and reduces the efficiency of communication network optimization.
By determining the target communication network currently in use, the execution time of multiple communication function functions is obtained and compared with a preset execution time threshold. If the time exceeds the threshold, the network is determined to be in a weak state, and the corresponding execution time threshold is increased to optimize the same set of communication function functions.
It enables communication network optimization without code modification in any network library, simplifying the operation process and improving optimization efficiency.
Smart Images

Figure CN115022895B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of communication technology, and in particular to a network optimization method and related equipment. Background Technology
[0002] Mobile terminals have been widely used due to their portability. Mobile terminals can use various types of communication networks, such as Wi-Fi, 3G, and 4G wireless communication technologies.
[0003] However, different companies have their own network library code, and even different projects within the same company may correspond to different network library codes. Optimizing a communication network requires modifying the code in each of these different network libraries. For example, Company A might use network library A, and Company B might use network library B. If Company A wants to optimize its communication network, it needs to modify the code in network library A; similarly, if Company B wants to optimize its communication network, it needs to modify the code in network library B. Therefore, in existing technologies, optimizing a communication network requires modifying the code in different network libraries, a cumbersome process that results in low optimization efficiency. Summary of the Invention
[0004] This invention provides a network optimization method and related equipment to solve the problem that in the prior art, optimizing a communication network requires modifying code in different network libraries, which is a cumbersome process and results in low efficiency.
[0005] In a first aspect, the present invention provides a network optimization method, comprising:
[0006] Determine the target communication network currently in use;
[0007] Obtain the execution time of the target communication function among multiple communication function functions, wherein each of the multiple communication function functions is applicable to any network library;
[0008] The execution time of the target communication function is compared with a preset first execution time threshold, wherein the preset first execution time threshold is the execution time threshold corresponding to the target communication function under the target communication network;
[0009] If the execution time of the target communication function is greater than or equal to the preset first execution time threshold, the target communication network is determined to be in a weak network state, and the execution time threshold corresponding to the target communication function under the target communication network is increased from the preset first execution time threshold to the preset second execution time threshold.
[0010] Optionally, obtaining the execution time of the target communication function among multiple communication function functions includes:
[0011] The execution time of the target communication function among the multiple communication function functions is obtained using the hook function.
[0012] Optionally, before the step of comparing the execution time of the target communication function with a preset first execution time threshold, the method further includes:
[0013] The execution time of the target communication function among the acquired multiple communication function functions is stored in a Collect container;
[0014] The step of comparing the execution time of the target communication function with a preset first execution time threshold includes:
[0015] Read the execution time of the target communication function from the Collect container;
[0016] The execution time of the target communication function is compared with the preset first execution time threshold.
[0017] Optionally, before the step of determining the target communication network currently in use, the method further includes:
[0018] Set an execution time threshold for each of the multiple communication function functions under each of the multiple communication networks, wherein the target communication network is one of the multiple communication networks.
[0019] Optionally, the execution time threshold for each of the plurality of communication function functions is a template type: Template<typename T> .
[0020] Optionally, the plurality of communication function functions include a communication function function for connecting to the server, a communication function function for reading data from the server, a communication function function for writing data to the server, and a communication function function for sending data to the server.
[0021] Optionally, comparing the execution time of the target communication function with a preset first execution time threshold includes:
[0022] The connection time for establishing a connection between the communication function used to connect to the server and the server is compared with a preset first connection time threshold, wherein the preset first connection time threshold is the connection time threshold corresponding to the communication function used to connect to the server under the target communication network.
[0023] And / or, compare the reading time of the communication function for reading data from the server with a preset first reading time threshold, wherein the preset first reading time threshold is the reading time threshold corresponding to the communication function for reading data from the server under the target communication network;
[0024] And / or, compare the write time of the communication function for writing data to the server with a preset first write time threshold, wherein the preset first write time threshold is the write time threshold corresponding to the communication function for writing data to the server under the target communication network;
[0025] And / or, compare the sending time of the communication function for sending data to the server with a preset first sending time threshold, wherein the preset first sending time threshold is the sending time threshold corresponding to the communication function for sending data to the server under the target communication network.
[0026] Secondly, the present invention also provides a network optimization device, comprising:
[0027] The determination module is used to determine the target communication network currently in use;
[0028] The acquisition module is used to acquire the execution time of the target communication function among multiple communication function functions, wherein each of the multiple communication function functions is applicable to any network library;
[0029] The comparison module is used to compare the execution time of the target communication function with a preset first execution time threshold, wherein the preset first execution time threshold is the execution time threshold corresponding to the target communication function under the target communication network;
[0030] The adjustment module is used to determine that the target communication network is in a weak network state when the execution time of the target communication function is greater than or equal to the preset first execution time threshold, and to increase the execution time threshold corresponding to the target communication function under the target communication network from the preset first execution time threshold to the preset second execution time threshold.
[0031] Thirdly, the present invention also provides an electronic device, including a memory and a processor, wherein the processor is configured to implement the steps of the network optimization method described in the first aspect when executing a computer program stored in the memory.
[0032] Fourthly, the present invention also provides a computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the steps of the network optimization method described in the first aspect.
[0033] As can be seen from the above technical solutions, the network optimization method provided by this invention determines the target communication network currently in use; obtains the execution time of a target communication function among multiple communication function functions, wherein each of the multiple communication function functions is applicable to any network library; compares the execution time of the target communication function function with a preset first execution time threshold, wherein the preset first execution time threshold is the execution time threshold corresponding to the target communication function function under the target communication network; if the execution time of the target communication function function is greater than or equal to the preset first execution time threshold, it is determined that the target communication network is in a weak network state, and the execution time threshold corresponding to the target communication function under the target communication network is increased from the preset first execution time threshold to a preset second execution time threshold. Thus, since each of the multiple communication function functions is applicable to any network library, the communication network can be optimized at the same set of communication function levels that can be called from any network library. The network optimization method of this application can be adapted to any network library, and when optimizing the communication network, there is no need to modify the code in different network libraries, the operation process is simple, and the communication network optimization efficiency is high. Attached Figure Description
[0034] Figure 1 A flowchart illustrating a network optimization method provided in this application embodiment;
[0035] Figure 2 A structural diagram of a network optimization device provided in an embodiment of this application;
[0036] Figure 3 A schematic diagram illustrating an embodiment of an electronic device provided in this application;
[0037] Figure 4 This is a schematic diagram illustrating an embodiment of a computer-readable storage medium provided in this application. Detailed Implementation
[0038] To better understand the technical solutions provided in the embodiments of this specification, the technical solutions of the embodiments of this specification will be described in detail below with reference to the accompanying drawings and specific embodiments. It should be understood that the embodiments of this specification and the specific features in the embodiments are detailed descriptions of the technical solutions of the embodiments of this specification, rather than limitations on the technical solutions of this specification. In the absence of conflict, the embodiments of this specification and the technical features in the embodiments can be combined with each other.
[0039] In this document, relational terms such as "first" and "second" are used merely to distinguish one entity or operation from another, without necessarily requiring or implying any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element. The term "two or more" includes two or more cases.
[0040] See Figure 1 , Figure 1 This is a flowchart of a network optimization method provided by the present invention. Figure 1 As shown, it includes the following steps:
[0041] S101. Determine the target communication network currently in use.
[0042] In step S101, the target communication network currently being used can be determined. For example, the mobile terminal can determine the type of communication network currently being used, such as Wi-Fi, 3G, or 4G.
[0043] S102. Obtain the execution time of the target communication function among multiple communication function functions, wherein each of the multiple communication function functions is applicable to any network library.
[0044] In S102, the execution time of the target communication function among multiple communication function functions can be obtained. Each of these communication function functions is applicable to any network library.
[0045] It should be noted that since each of the multiple communication function functions is applicable to any network library, the communication network can be optimized at the same level of communication function functions that can be called from any network library. The network optimization method of this application is adaptable to any network library, and when optimizing the communication network, there is no need to modify the code in different network libraries. The operation process is simple, and the communication network optimization efficiency is high.
[0046] S103. Compare the execution time of the target communication function with a preset first execution time threshold, wherein the preset first execution time threshold is the execution time threshold corresponding to the target communication function under the target communication network.
[0047] In S103, the execution time of the target communication function can be compared with a preset first execution time threshold. The preset first execution time threshold is the execution time threshold corresponding to the target communication function under the target communication network.
[0048] It should be noted that the execution time threshold for the same communication function differs across different communication networks. For example, in 3G, the execution time threshold for a certain communication function is 3000 milliseconds; in 4G, it might be 2500 milliseconds; and in Wi-Fi, it might be 2000 milliseconds, and so on. Setting different execution time thresholds for the same communication function across different communication networks ensures the stability of the response acquisition for each communication function under each network.
[0049] Optionally, before the step of determining the target communication network currently in use, the method further includes:
[0050] Set an execution time threshold for each of the multiple communication function functions under each of the multiple communication networks, wherein the target communication network is one of the multiple communication networks.
[0051] It should be noted that execution time thresholds can be set for each communication function within multiple communication networks, covering various communication networks. The target communication network is one of the multiple communication networks. This means that the execution time thresholds for the same communication function can be set differently for different communication networks, thus ensuring the stability of response acquisition for communication functions across each network.
[0052] Optionally, the execution time threshold for each of the plurality of communication function functions is a template type: Template<typename T> .
[0053] Furthermore, the execution time threshold for each of the multiple communication function functions can be a template type: Template.<typename T> .
[0054] You can use the Template class.<typename T> It can easily meet the needs of customizing time parameters and can easily use time with various precisions, such as milliseconds, microseconds, or seconds.
[0055] class NetType{
[0056] Virtual string type() = 0; This interface is a pure virtual interface and needs to be implemented by various different communication network types.
[0057] Virtual T getConnectTimeout() = 0; This interface requires the timeout data for connecting to the server under the current communication network type.
[0058] Virtual T weakConnect() = 0; This interface is designed so that the connection timeout is the time for a weak network connection.
[0059] Virtual T getWriteTimeout() = 0; sets the timeout for sending data on the current communication network.
[0060] Virtual T weakWrite() = 0; This interface is designed so that the timeout for sending data is the time of the weak network.
[0061] Virtual T getReadTimeout() = 0; sets the timeout for reading data from the current communication network.
[0062] Virtual T weakRead() = 0; Sets the timeout for writing data to the current communication network.
[0063] Virtual T getInterval() = 0; sets the retry interval for the current communication network.
[0064] }
[0065] Specifically, `getConnectTimeout` represents the timeout period for connecting to the server; `weakConnect` represents the connection timeout period due to weak network conditions; `getWriteTimeout` represents the timeout period for sending data; `weakWrite` represents the timeout period for sending data due to weak network conditions; `getReadTimeout` represents the timeout period for reading data; `weakRead` represents the timeout period for writing data; and `getInterval` represents the retry interval. All time data are template types, allowing for the use of different time precisions later.
[0066] Optionally, the plurality of communication function functions include a communication function function for connecting to the server, a communication function function for reading data from the server, a communication function function for writing data to the server, and a communication function function for sending data to the server.
[0067] Furthermore, the multiple communication function sets can include functions for connecting to the server, reading data from the server, writing data to the server, and sending data to the server. Since all four types of functions are involved in data interaction between the mobile terminal and the server, the network status determined by the execution time of these functions is relatively realistic and accurate.
[0068] Optionally, comparing the execution time of the target communication function with a preset first execution time threshold includes:
[0069] The connection time for establishing a connection between the communication function used to connect to the server and the server is compared with a preset first connection time threshold, wherein the preset first connection time threshold is the connection time threshold corresponding to the communication function used to connect to the server under the target communication network.
[0070] And / or, compare the reading time of the communication function for reading data from the server with a preset first reading time threshold, wherein the preset first reading time threshold is the reading time threshold corresponding to the communication function for reading data from the server under the target communication network;
[0071] And / or, compare the write time of the communication function for writing data to the server with a preset first write time threshold, wherein the preset first write time threshold is the write time threshold corresponding to the communication function for writing data to the server under the target communication network;
[0072] And / or, compare the sending time of the communication function for sending data to the server with a preset first sending time threshold, wherein the preset first sending time threshold is the sending time threshold corresponding to the communication function for sending data to the server under the target communication network.
[0073] Furthermore, the connection time between the communication function used to connect to the server and the server can be obtained from multiple communication function functions. This connection time can then be compared with a preset first connection time threshold. The preset first connection time threshold is the connection time threshold corresponding to the communication function used to connect to the server under the target communication network. If the connection time between the communication function used to connect to the server and the server is greater than or equal to the preset first connection time threshold, it can be determined that the target communication network is in a weak network state, and the connection time threshold corresponding to the communication function used to connect to the server under the target communication network can be increased from the preset first connection time threshold to a preset second connection time threshold.
[0074] For example, class 4GType:public class NetType <std::chrono::seconds>{Template parameter uses milliseconds}
[0075] string type(){return "4g";}
[0076] std::chrono::seconds getConnectTimeout(){return 3000ms;} The connection time threshold of 3000 milliseconds is used here, which is data derived from historical experience.
[0077] std::chrono::seconds weakConnect(){return 2000ms;} If the current connection time exceeds 2000 milliseconds, it indicates that the current connection is under weak network conditions.
[0078] The chrono library can implement timer functions in different systems. `getConnectTimeout(){return 3000ms;}` indicates a connection time threshold of 3000 milliseconds; `weakConnect(){return 2000ms;}` indicates a connection time threshold of 2000 milliseconds for weak network conditions.
[0079] Furthermore, the read time of the communication function used to read data from the server can be obtained from multiple communication function functions. This read time can then be compared with a preset first read time threshold. The preset first read time threshold is the read time threshold corresponding to the communication function used to read data from the server under the target communication network. If the read time of the communication function used to read data from the server is greater than or equal to the preset first read time threshold, it can be determined that the target communication network is in a weak network state, and the read time threshold corresponding to the communication function used to read data from the server under the target communication network can be increased from the preset first read time threshold to a preset second read time threshold.
[0080] For example, `std::chrono::seconds getReadTimeout(){return 3000ms;}` indicates the timeout period for reading data from the server.
[0081] std::chrono::seconds weakRead(){return 2000ms;} If the time taken to read data is greater than 2000 milliseconds, it indicates that the current network is weak.
[0082] In this code, `getReadTimeout(){return 3000ms;}` indicates that the data reading time threshold from the server is 3000ms; `weakRead(){return 2000ms;}` indicates that the data reading time threshold for determining weak network conditions is 2000ms.
[0083] Furthermore, the write time of the communication function used to write data to the server can be obtained from multiple communication function functions. This write time can then be compared with a preset first write time threshold. The preset first write time threshold is the write time threshold corresponding to the communication function used to write data to the server under the target communication network. If the write time of the communication function used to write data to the server is greater than or equal to the preset first write time threshold, it can be determined that the target communication network is in a weak network state, and the write time threshold corresponding to the communication function used to write data to the server under the target communication network can be increased from the preset first write time threshold to a preset second write time threshold.
[0084] Furthermore, the transmission time of the communication function used to send data to the server can be obtained from multiple communication function functions. This transmission time can then be compared with a preset first transmission time threshold. The preset first transmission time threshold is the transmission time threshold corresponding to the communication function used to send data to the server under the target communication network. If the transmission time of the communication function used to send data to the server is greater than or equal to the preset first transmission time threshold, it can be determined that the target communication network is in a weak network state, and the transmission time threshold corresponding to the communication function used to send data to the server under the target communication network can be increased from the preset first transmission time threshold to a preset second transmission time threshold.
[0085] For example, when sending data, if it takes more than 4000 milliseconds, it indicates a timeout.
[0086] `std::chrono::seconds weakWrite(){return 3000ms;}` indicates that if the data transmission time exceeds 3000 milliseconds, the network is in a weak state when the data is transmitted.
[0087] Additionally, `std::chrono::seconds getInterval(){return 5000ms;}` indicates the retry interval for the task, which must be greater than the timeout for reading or sending data.
[0088] In this code, `getWriteTimeout(){return 4000ms;}` indicates that the sending time threshold is 4000 milliseconds; `weakWrite(){return 3000ms;}` indicates that the sending time threshold for weak network conditions is 3000ms.
[0089] S104. If the execution time of the target communication function is greater than or equal to the preset first execution time threshold, determine that the target communication network is in a weak network state, and raise the execution time threshold corresponding to the target communication function under the target communication network from the preset first execution time threshold to the preset second execution time threshold.
[0090] In S104, if the execution time of the target communication function is greater than or equal to the preset first execution time threshold, it can be determined that the target communication network is in a weak network state, and the execution time threshold corresponding to the target communication function under the target communication network can be increased from the preset first execution time threshold to the preset second execution time threshold.
[0091] For example, suppose that in the target communication network, the preset first read time threshold for the communication function used to read data from the server is 2000 milliseconds. If the read time of the communication function used to read data from the server is greater than or equal to the preset first read time threshold of 2000 milliseconds, it can be determined that the target communication network is in a weak network state. Because the target communication network is currently in a weak network state, the actual read time of the communication function used to read data from the server may be relatively slow, exceeding the preset first read time threshold of 2000 milliseconds. If the preset read time threshold for the communication function used to read data from the server is not adjusted and remains at 2000 milliseconds, a read request may not receive a response even after 2000 milliseconds. In this case, the read task will be directly judged as failed, and the read request will be sent again. This cycle continues, resulting in multiple read requests being directly considered as read task failures, thus wasting all the waiting time consumed by these multiple read requests.
[0092] Therefore, when it is determined that the target communication network is currently in a weak state, the preset reading time threshold for the communication function used to read data from the server under the target communication network can be increased from the first preset reading time threshold (2000 milliseconds) to the second preset reading time threshold (3000 milliseconds). This allows more response time for the communication function used to read data from the server. Since the target communication network is currently in a weak state, the communication function used to read data from the server may only receive a response to the read request after 2600 milliseconds. Because the preset reading time threshold has been increased from 2000 milliseconds to 3000 milliseconds, the response to this read request can be obtained, preventing a vicious cycle of continuously reporting read task failures.
[0093] In this way, when it is determined that the target communication network is in a weak network state, the execution time threshold corresponding to the target communication function under the target communication network can be increased from the preset first execution time threshold to the preset second execution time threshold, so as to ensure the stability of the communication function in obtaining the response when the target communication network is in a weak network state.
[0094] In this application embodiment, the network optimization method can be adapted to various network libraries and different system platforms, including Windows, Linux, Android, or iOS. For example, to make the network optimization method of this application applicable to different system platforms, it can be implemented using the following code:
[0095] The `PlatformNetwork` class encapsulates the functionality for obtaining network status information for different platforms.
[0096] String curtype;
[0097] Virtual string networkType()=0;
[0098] Virtual void networkchange(Std::string type)=0;
[0099] function<void(Std::string)> notify; is used to notify the network of changes via a callback.
[0100] Here, String curtype represents the current network status; string networkType() represents the interface provided to obtain the network status; and networkchange(Std::string type) represents the corresponding interface for the network status.
[0101] Therefore, different platforms need to implement the function of obtaining the current network status and triggering network change notifications. For example, this can be achieved using the following code:
[0102]
[0103]
[0104] GetNetworkStatus() retrieves the network status. It returns the current network type and stores it in Curtype. networkchange(Std::string type) represents the corresponding interface for network status.
[0105] This interface requires a separate thread to continuously retrieve the network status and check if the saved status matches the current status. If they don't match, a callback should be sent to notify the user. For example, this can be implemented using the following code:
[0106] Thread t; t.create(); creates a thread.
[0107] String n = networkType(); Get network status and compare
[0108] If (n != Curtype) { notify(n);} If they are inconsistent, notify the upper layer that the current network has changed.
[0109] }
[0110] Here, Thread t; t.create() means creating a thread; String n = networkType() means getting the network status and comparing it; If(n!=Curtype){notify(n);} means notifying the upper layer that the current network has changed if they are inconsistent.
[0111] In this embodiment, data can be collected at various stages within each network, and the data storage requires the design of data storage functionality. For example, this can be implemented using the following code: Template<typename T>
[0112] Class Data{
[0113] `int type;` is used to record the type of data acquisition. For example, whether it is a connection event, a send event, or a read data event.
[0114] T_time; used to record the acquisition time, therefore a template is used to facilitate the use of different time precisions.
[0115] Then, a base class can be written for collecting data: `class Collect{`
[0116] List<Data*> listData; used to store data from all the collected points.
[0117] Virtual addData(Data*pData) { Write the small data provided by the storage.
[0118] listData.push_back(pData); stores the data in a member variable.
[0119] }
[0120] List<Data*> *getData(){return&listData;} provides an interface for retrieving collected data.
[0121] Void switch(List<Data*> &d){This interface provides a way to exchange data, converting the data currently stored in the linked list to the parameter, so that the data stored in this class is empty.
[0122] d.swap(listData); swaps data.
[0123] }
[0124] In this way, a data storage class Template can be designed.<typename T> It is used to store the data of each small point collected.
[0125] In this application embodiment, the design of the network status data collector needs to be compatible with existing, fully open network libraries and support network libraries developed in different languages. It also aims to be functionally independent of the network library, thereby achieving transparency to the network library and allowing the weak network optimization function to operate independently, thus decoupling logic and facilitating subsequent functional iterations. More importantly, network functions should not be integrated with network services; therefore, the focus should be on the network connection and transmission status itself.
[0126] Optionally, obtaining the execution time of the target communication function among multiple communication function functions includes:
[0127] The execution time of the target communication function among the multiple communication function functions is obtained using the hook function.
[0128] Furthermore, the hook function can be used to obtain the execution time of the target communication function among multiple communication function functions.
[0129] By hooking system functions, we can detect changes in the current network state, ensuring that no network status is missed, and also decoupling it from network services. Specifically, we need to hook the following network APIs to obtain network status.
[0130] The specific APIs include the following:
[0131] The Socket class provides functions for creating network sockets, enabling the class to be aware of the network sockets currently being created.
[0132] The Connect function connects to the server. Hooking this function is mainly to monitor the time consumption of the current connection.
[0133] The Read function retrieves data from the server. This function is used to determine the time elapsed during the current data retrieval process.
[0134] The `Write` function sends data to the server. This function is used to determine the time elapsed since the data was sent.
[0135] By writing a Hook function, you can obtain all network-related data in the current app. For example, this can be achieved using the following code:
[0136] `hook_register("net_so_name","socket",my_socket);` hooks the `socket` function.
[0137] hook_register("net_so_name","Connect",my_Connect); hooks the Connect function.
[0138] `hook_register("net_so_name","Read",my_Read);` hooks the `Read` function.
[0139] `hook_register("net_so_name","Write",my_Write);` hooks the `Write` function.
[0140] The above describes the hooking of system functions.
[0141] Then, in the function written by the hook, my_xx will get the current time consumed.
[0142] my_read(){
[0143] Time t = Time::CurrentTime(); Get the current time.
[0144] Read(): Calls the system's read function to read data.
[0145] Time elapse = Time::CurrentTime() - t; After the read is complete, retrieve the time again to get the time data consumed by the system function read.
[0146] Data d("read", elapse); Constructs a Data object and populates it with data.
[0147] Then use the Collect interface to store the created objects.
[0148] Collect.addData(d);
[0149] }
[0150] It can collect data on the time spent on connection and data transmission related to sockets in the network and store it in the collection container Collect.
[0151] Optionally, before the step of comparing the execution time of the target communication function with a preset first execution time threshold, the method further includes:
[0152] The execution time of the target communication function among the acquired multiple communication function functions is stored in a Collect container;
[0153] The step of comparing the execution time of the target communication function with a preset first execution time threshold includes:
[0154] Read the execution time of the target communication function from the Collect container;
[0155] The execution time of the target communication function is compared with the preset first execution time threshold.
[0156] Furthermore, the execution time of the target communication function among the acquired multiple communication function functions can be stored in a Collection container. Then, the execution time of the target communication function can be read from the Collection container, and then compared with a preset first execution time threshold. The Collection container is convenient for traversing large amounts of data, so reading the execution time of the target communication function from the Collection container is highly efficient.
[0157] Thus, the current time is obtained by using `Time t = Time::CurrentTime()`, and data is read by calling `Read()`, which is the system's `read` function. Next, the time consumed by the system function `read` can be obtained by using `Time elapse = Time::CurrentTime() - t`, which means using the time obtained again after the read is complete.
[0158] In this embodiment, the diagnosis of weak network conditions is achieved by transparently collecting network socket-related data, focusing on network transmission itself rather than network services. Furthermore, this application uses a hook-based approach to track the status of all network requests within the app. This includes monitoring the current network status even if the app includes other network libraries, providing a more accurate reflection of the app's network condition. This avoids misjudgments caused by functional or usage issues with a single network library. The diagnostic engine is designed as follows:
[0159] This application designs a class to encapsulate the functionality of the diagnostic engine and supports subsequent expansion with new data. For example, it can be implemented using the following code:
[0160] Class CheckEngine{
[0161] First, define the member variables.
[0162] NetType*type; Network type data
[0163] PlatformNetwork*network; Network status
[0164] Collect*col; Data collection
[0165] The constructor takes these interfaces as input, using the base class, which allows for the creation of different subclasses for different platforms.
[0166] CheckEngine(NetType*n, PlatformNetwork*p,Collect*c):type(n),network(p),col(c){
[0167] The constructor assigns values to member variables.
[0168] Void switch(Collect*c){This application needs to provide an interface for replacing newly collected network data, so that the current network environment can be determined in real time.}
[0169] `col.switch(c)`: Swaps the member variables with the parameter.
[0170] NetType*creteNet(string type){ This interface needs to be extracted separately so that different network type pointers can be created based on different network types.
[0171] If (type == wifi) it is a wifi network, then create a wifi instance.
[0172] NetType*pNet = wifiType <std::chrono::seconds>A pointer to a network type needs to be created to retrieve the relevant data. Return pNet;
[0173] If (type == 4G), then create an instance of 4G.
[0174] NetType*pNet=4GType <std::chrono::seconds>;
[0175] Return pNet;
[0176] Other network types can be created using the same method.
[0177] In CheckEngine(NetType*n, PlatformNetwork*p, Collect*c):type(n),network(p),col(c), NetType represents the network type; PlatformNetwork*p represents the network instance of a specific platform, which encapsulates network-related system API interfaces; and Collect represents the collected data.
[0178] The next step is to write code to adjust the parameters of the current network based on weak network detection. For example, this can be achieved using the following code:
[0179] The `Void SetSocket(string type, T time)` method takes two parameters: the network type and the time data to be set. It uses a template parameter, which allows for easy setting of time data with different precision.
[0180] If (type == connect) { Set the socket's connect timeout to the specified time.}
[0181] If (type == send) { If the type is send, then set the time for sending data to the specified time.}
[0182] If (type == send) { If the type is send, then set the time for receiving data to the specified time.}
[0183] Specifically, for sockets, to set various time parameters for the sockets used in the network library, the socket creation function was hooked during the socket creation process in this application, thus obtaining all socket handles. Based on these handles, system functions can be called to set various time parameters.
[0184] The `void detect()` function then executes the engine's decision logic. This logic determines the current network state based on the time taken for the current network data to be processed, and then adjusts the network settings accordingly.
[0185] For(auto it=c.listData.cbegin();it !=c.listData.cend();++it){ loop iterates through the currently stored network time consumption data.
[0186] String type = network->networkType(); First, get the current network status.
[0187] After obtaining the network status, the parameters need to be adjusted for each network status.
[0188] First, different pointer instance objects pNet need to be created based on the network type.
[0189] NetType*pNet=creteNet(type);
[0190] Case: kwifi
[0191] If the current network is Wi-Fi:
[0192] If (it.type == connect) { if (it.data > pNet->weakConnect()); If the current connection event data is greater than the connection event data under the current weak network condition of the Wi-Fi, then the current Wi-Fi is considered to be a weak network. If the current network is weak, then the network connection timeout needs to be adjusted to improve the efficiency and stability of the connection under weak network conditions. SetSocket(connect, pNet.getConnectTimeout());}
[0193] For other connection states such as write or read, set them in the same way as described above.
[0194] In the `Void SetSocket(string type, T time)` method, `string type` represents the network type, and `T time` represents the time data to be set. It uses a template parameter, allowing for easy setting of time data with different precision.
[0195] In other network conditions, such as 3G, 4G, and 5G, the setup method is the same as for Wi-Fi. Different network types encapsulate their related data within pNet instances, which are created based on the network type. Therefore, using a pNet allows for convenient access to all data for the corresponding network.
[0196] In this embodiment, the network status is determined in the aforementioned steps, allowing for logging of each determination. Once a weak network condition is identified, a network timeout can be easily determined based on the previously added weak network logs, indicating that the timeout is due to a weak network. This greatly facilitates troubleshooting.
[0197] It should be noted that in the existing technology, optimizing a communication network requires modifying code in different network libraries, which is a cumbersome process and results in low efficiency in optimizing the communication network.
[0198] In this application, since each of the multiple communication function functions is applicable to any network library, the communication network can be optimized at the same level of communication function functions that can be called from any network library. The network optimization method of this application is adaptable to any network library, and when optimizing the communication network, there is no need to modify the code in different network libraries. The operation process is simple, and the communication network optimization efficiency is high.
[0199] As can be seen from the above technical solutions, the network optimization method provided by this invention determines the target communication network currently in use; obtains the execution time of a target communication function among multiple communication function functions, wherein each of the multiple communication function functions is applicable to any network library; compares the execution time of the target communication function function with a preset first execution time threshold, wherein the preset first execution time threshold is the execution time threshold corresponding to the target communication function function under the target communication network; if the execution time of the target communication function function is greater than or equal to the preset first execution time threshold, it is determined that the target communication network is in a weak network state, and the execution time threshold corresponding to the target communication function under the target communication network is increased from the preset first execution time threshold to a preset second execution time threshold. Thus, since each of the multiple communication function functions is applicable to any network library, the communication network can be optimized at the same set of communication function levels that can be called from any network library. The network optimization method of this application can be adapted to any network library, and when optimizing the communication network, there is no need to modify the code in different network libraries, the operation process is simple, and the communication network optimization efficiency is high.
[0200] See Figure 2 , Figure 2 This is a structural diagram of a network optimization device provided by the present invention. Figure 2 As shown, the network optimization device 200 includes a determining module 201, an acquiring module 202, a comparing module 203, and an adjusting module 204, wherein:
[0201] Module 201 is used to determine the target communication network currently in use;
[0202] The acquisition module 202 is used to acquire the execution time of the target communication function among a plurality of communication function functions, wherein each of the plurality of communication function functions is applicable to any network library;
[0203] The comparison module 203 is used to compare the execution time of the target communication function with a preset first execution time threshold, wherein the preset first execution time threshold is the execution time threshold corresponding to the target communication function under the target communication network;
[0204] The adjustment module 204 is used to determine that the target communication network is in a weak network state when the execution time of the target communication function is greater than or equal to the preset first execution time threshold, and to increase the execution time threshold corresponding to the target communication function under the target communication network from the preset first execution time threshold to the preset second execution time threshold.
[0205] Network optimization device 200 can achieve Figure 1 The various processes implemented by the network optimization device in the method embodiment are not described in detail here to avoid repetition. Furthermore, the network optimization device 200 can optimize the communication network at the same set of communication function levels that can be called from any network library, since each of the multiple communication function functions is applicable to any network library. The network optimization method of this application is adaptable to any network library, and when optimizing the communication network, there is no need to modify the code in different network libraries. The operation process is simple, and the communication network optimization efficiency is high.
[0206] Please see Figure 3 , Figure 3 A schematic diagram illustrating an embodiment of the electronic device provided in this application.
[0207] like Figure 3 As shown, this application provides an electronic device 300, including a memory 310, a processor 320, and a computer program 311 stored in the memory 310 and executable on the processor 320. When the processor 320 executes the computer program 311, it performs the following steps:
[0208] Determine the target communication network currently in use;
[0209] Obtain the execution time of the target communication function among multiple communication function functions, wherein each of the multiple communication function functions is applicable to any network library;
[0210] The execution time of the target communication function is compared with a preset first execution time threshold, wherein the preset first execution time threshold is the execution time threshold corresponding to the target communication function under the target communication network;
[0211] If the execution time of the target communication function is greater than or equal to the preset first execution time threshold, the target communication network is determined to be in a weak network state, and the execution time threshold corresponding to the target communication function under the target communication network is increased from the preset first execution time threshold to the preset second execution time threshold.
[0212] In practical implementation, when the processor 320 executes the computer program 311, it can achieve... Figure 1 Any of the corresponding implementation methods in the embodiments.
[0213] Since the electronic device described in this embodiment is the device used to implement a network optimization device in the embodiments of this application, those skilled in the art can understand the specific implementation method and various variations of the electronic device in this embodiment based on the method described in the embodiments of this application. Therefore, how the electronic device implements the method in the embodiments of this application will not be described in detail here. Any device used by those skilled in the art to implement the method in the embodiments of this application falls within the scope of protection of this application.
[0214] Please see Figure 4 , Figure 4 This is a schematic diagram illustrating an embodiment of a computer-readable storage medium provided in this application.
[0215] like Figure 4 As shown, this embodiment provides a computer-readable storage medium 400 on which a computer program 411 is stored. When the computer program 411 is executed by a processor, it performs the following steps:
[0216] Determine the target communication network currently in use;
[0217] Obtain the execution time of the target communication function among multiple communication function functions, wherein each of the multiple communication function functions is applicable to any network library;
[0218] The execution time of the target communication function is compared with a preset first execution time threshold, wherein the preset first execution time threshold is the execution time threshold corresponding to the target communication function under the target communication network;
[0219] If the execution time of the target communication function is greater than or equal to the preset first execution time threshold, the target communication network is determined to be in a weak network state, and the execution time threshold corresponding to the target communication function under the target communication network is increased from the preset first execution time threshold to the preset second execution time threshold.
[0220] In practical implementation, when the computer program 411 is executed by the processor, it can achieve the following: Figure 1 Any of the corresponding implementation methods in the embodiments.
[0221] It should be noted that the descriptions of each embodiment in the above embodiments have different focuses. For parts that are not described in detail in a certain embodiment, please refer to the relevant descriptions in other embodiments.
[0222] Those skilled in the art will understand that embodiments of this application can be provided as methods, systems, or computer program products. Therefore, this application can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, this application can take the form of a computer program product embodied on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0223] This application is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of this application. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded computer, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create a machine for implementing the flowchart illustrations. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0224] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.
[0225] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0226] This application also provides a computer program product, which includes computer software instructions that, when executed on a processing device, cause the processing device to perform actions such as... Figure 1 The process of the network optimization method in the corresponding embodiment.
[0227] The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, all or part of the processes or functions described in the embodiments of this application are generated. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions may be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, the computer instructions may be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via wired (e.g., coaxial cable, fiber optic, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium may be any available medium that a computer can store or a data storage device such as a server or data center that integrates one or more available media. The available medium may be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., solid-state disk (SSD)).
[0228] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working processes of the systems, devices, and units described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here.
[0229] In the several embodiments provided in this application, it should be understood that the disclosed systems, apparatuses, and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be an indirect coupling or communication connection between apparatuses or units through some interfaces, and may be electrical, mechanical, or other forms.
[0230] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0231] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.
[0232] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0233] The above-described embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of this application.< / std::chrono::seconds> < / std::chrono::seconds> < / std::chrono::seconds>
Claims
1. A network optimization method, characterized in that, include: Determine the target communication network currently in use; Obtain the execution time of the target communication function among multiple communication function functions, wherein each of the multiple communication function functions is applicable to any network library; The execution time of the target communication function is compared with a preset first execution time threshold, wherein the preset first execution time threshold is the execution time threshold corresponding to the target communication function under the target communication network; If the execution time of the target communication function is greater than or equal to the preset first execution time threshold, the target communication network is determined to be in a weak network state, and the execution time threshold corresponding to the target communication function under the target communication network is increased from the preset first execution time threshold to the preset second execution time threshold. The step of obtaining the execution time of the target communication function among multiple communication function functions includes: The execution time of the target communication function among the multiple communication function functions is obtained using the hook function; Before the step of comparing the execution time of the target communication function with a preset first execution time threshold, the method further includes: The execution time of the target communication function among the acquired multiple communication function functions is stored in a Collect container; The step of comparing the execution time of the target communication function with a preset first execution time threshold includes: Read the execution time of the target communication function from the Collect container; The execution time of the target communication function is compared with the preset first execution time threshold. Prior to the step of determining the target communication network currently in use, the method further includes: Set an execution time threshold for each of the multiple communication function functions under each of the multiple communication networks, wherein the target communication network is one of the multiple communication networks; The execution time threshold for each of the multiple communication function functions is of template type: Template<typename T> ; The plurality of communication function functions include communication function functions for connecting to the server, communication function functions for reading data from the server, communication function functions for writing data to the server, and communication function functions for sending data to the server.
2. The method as described in claim 1, characterized in that, The step of comparing the execution time of the target communication function with a preset first execution time threshold includes: The connection time for establishing a connection between the communication function used to connect to the server and the server is compared with a preset first connection time threshold, wherein the preset first connection time threshold is the connection time threshold corresponding to the communication function used to connect to the server under the target communication network. And / or, compare the reading time of the communication function for reading data from the server with a preset first reading time threshold, wherein the preset first reading time threshold is the reading time threshold corresponding to the communication function for reading data from the server under the target communication network; And / or, compare the write time of the communication function for writing data to the server with a preset first write time threshold, wherein the preset first write time threshold is the write time threshold corresponding to the communication function for writing data to the server under the target communication network; And / or, compare the sending time of the communication function for sending data to the server with a preset first sending time threshold, wherein the preset first sending time threshold is the sending time threshold corresponding to the communication function for sending data to the server under the target communication network.
3. An electronic device, comprising a memory and a processor, characterized in that, When the processor executes a computer program stored in the memory, it implements the steps of the network optimization method as described in claim 1.
4. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by the processor, it implements the steps of the network optimization method as described in claim 1.
Citation Information
Patent Citations
Weak network environment monitoring and communication session reconnection method and device
CN112134758A
System, method, and computer program for automatic reconfiguration of a communication network
US10756970B1