VPN connection management method, device, computer equipment and storage medium
By utilizing VPN child threads and message communication mechanisms in JavaScript applications, the problem of poor fluency in VPN management applications caused by single-threaded processing in JavaScript is solved, and more stable and smooth VPN management operations are achieved.
Patent Information
- Application Number
- CN202210907786.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-07-29
- Publication Date
- 2024-12-03
- Estimated Expiration
- 2042-07-29
AI Technical Summary
VPN management applications developed based on JavaScript have poor fluency, mainly because the JavaScript engine is single-threaded, which causes application lag during synchronization operations.
By obtaining the target operation request input by the user, we judge whether there is a VPN instance in the local cache, and call the VPN child thread for corresponding operations, and use the message communication mechanism to receive feedback information to ensure that the application performs VPN management in a multi-threaded environment.
Improves the fluency and stability of VPN management applications, and improves the user experience with multi-threaded processing.
Smart Images

Figure CN115242578B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of network communication technology, and in particular to a VPN connection management method, device, computer equipment and storage medium. Background Art
[0002] Virtual Private Network (VPN) is a remote access technology that provides secure data transmission tunnel services between enterprises or between individuals and enterprises by establishing a dedicated data communication network technology in the public network. However, VPN requires the corresponding VPN SDK tool to manage VPN connections.
[0003] When an application developed based on JavaScript manages VPN, it can only manage VPN through VPN tools developed based on JavaScript. In the prior art, since the JavaScript engine can only process JavaScript js code in a single thread, that is, all tasks need to be queued, and the subsequent tasks will not be executed until the previous task is completed. In order to utilize the computing power of multi-core CPUs, HTML5 has added Web Workers, which allow the js main thread to create child threads, but the child threads are completely controlled by the main thread and cannot operate the DOM. The JavaScript engine is still single-threaded. Therefore, in applications developed based on JavaScript, when VPN tools are used to operate VPN, such as synchronous operations, the application will be stuck, resulting in poor stability and fluency of the application when managing VPN. Summary of the invention
[0004] The embodiments of the present invention provide a VPN connection management method, device, computer equipment and storage medium to solve the problem that existing applications developed based on JavaScript have poor application fluency when managing VPN.
[0005] An embodiment of the present invention provides a VPN connection management method, including:
[0006] Acquire a target operation request input by a user, wherein the target operation request includes a VPN identifier and target request information;
[0007] According to the VPN identifier, determining whether there is a VPN instance corresponding to the VPN identifier in the local cache;
[0008] If the VPN instance exists in the local cache, calling the VPN subthread corresponding to the VPN instance to run;
[0009] Communicate with the VPN sub-thread through a message communication mechanism, and receive target result information related to the target request information returned by the VPN sub-thread.
[0010] The embodiment of the present invention further provides a VPN connection management device, including:
[0011] A target operation request acquisition module, used to acquire a target operation request input by a user, wherein the target operation request includes a VPN identifier and target request information;
[0012] A VPN instance detection module, used to determine whether there is a VPN instance corresponding to the VPN identifier in the local cache according to the VPN identifier;
[0013] A VPN sub-thread calling module, configured to call the VPN sub-thread corresponding to the VPN instance to run if the VPN instance exists in the local cache;
[0014] The target result information receiving module is used to communicate with the VPN sub-thread through a message communication mechanism, and receive the target result information related to the target request information returned by the VPN sub-thread.
[0015] An embodiment of the present invention further provides a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the above-mentioned VPN connection management method when executing the computer program.
[0016] The embodiment of the present invention further provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the above-mentioned VPN connection management method is implemented.
[0017] The above-mentioned VPN connection management method, device, computer equipment and storage medium obtain the target operation request input by the user, and determine whether there is a VPN instance corresponding to the VPN identifier in the local cache according to the VPN identifier in the target operation request. If the VPN instance exists in the local cache, the VPN subthread corresponding to the VPN instance is called to run, so as to use the VPN subthread to perform corresponding operations in the application; then communicate with the VPN subthread through a message communication mechanism, receive target result information related to the target request information returned by the VPN subthread, so as to obtain feedback information on the operation of the VPN connection, thereby completing the corresponding management operation of the VPN while ensuring the fluency of the application. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings required for use in the description of the embodiments of the present invention will be briefly introduced below. Obviously, the accompanying drawings in the following description are only some embodiments of the present invention. For ordinary technicians in this field, other accompanying drawings can be obtained based on these accompanying drawings without paying creative labor.
[0019] Figure 1 This is a schematic diagram of an application environment of a VPN connection management method according to an embodiment of the present invention;
[0020] Figure 2 is a flow chart of a VPN connection management method in one embodiment of the present invention;
[0021] Figure 3 is another flow chart of a VPN connection management method according to an embodiment of the present invention;
[0022] Figure 4 is another flow chart of a VPN connection management method according to an embodiment of the present invention;
[0023] Figure 5 is a flow chart of a VPN connection management method in another embodiment of the present invention;
[0024] Figure 6 is a flow chart of a VPN connection management method in another embodiment of the present invention;
[0025] Figure 7 is a flow chart of a VPN connection management method in another embodiment of the present invention;
[0026] Figure 8 is a schematic diagram of a VPN connection management device in one embodiment of the present invention;
[0027] Fig. 9 is a schematic diagram of a computer device in one embodiment of the present invention. DETAILED DESCRIPTION
[0028] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0029] The VPN connection management method provided by the embodiment of the present invention can be applied in Figure 1 In the application environment shown. Figure 1As shown, the client (computer device) communicates with the server through the network. The client, also known as the user end, refers to the program corresponding to the server that provides local services to the client. The client (computer device) includes but is not limited to various personal computers, laptops, smart phones, tablets, cameras and portable wearable devices. The server can be an independent server or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content delivery networks (CDNs), and big data and artificial intelligence platforms.
[0030] The VPN connection management method provided by the embodiment of the present invention can be applied as follows: Figure 1 Specifically, the VPN connection management method is applied in a VPN connection management system, which includes: Figure 1 The client and server shown communicate with each other through a network to manage the VPN tool of the client to manage the VPN connection, thereby improving the smoothness of the client operation.
[0031] In one embodiment, if Figure 2 As shown, a VPN connection management method is provided, which is applied in Figure 1 The server or client in the example is used as an example to illustrate, including the following steps executed by the js main thread corresponding to the server or client:
[0032] S201: Acquire a target operation request input by a user, where the target operation request includes a VPN identifier and target request information;
[0033] S202: judging whether there is a VPN instance corresponding to the VPN identifier in the local cache according to the VPN identifier;
[0034] S203: If the VPN instance exists in the local cache, call the VPN subthread corresponding to the VPN instance to run;
[0035] S204: Communicate with the VPN sub-thread through a message communication mechanism, and receive target result information related to the target request information returned by the VPN sub-thread.
[0036] Among them, JavaScript (abbreviated as js) is a lightweight, interpreted or just-in-time compiled programming language with function priority. It is famous for developing scripting languages for web pages and is also used in many non-browser environments. JavaScript is a dynamic scripting language based on prototype programming and multiple paradigms, and supports object-oriented, imperative, declarative and functional programming paradigms.
[0037] Among them, a thread is an independent execution unit within a process. The application must run on a thread of a process. When js runs based on a browser, the main purpose of js is to interact with users and operate DOM, which means that the js engine can only run in a single thread, otherwise it will cause very complex synchronization problems. The single-threaded feature makes JavaScript and UI rendering occupy the same main thread, which means that JavaScript cannot handle multiple tasks at the same time, and when JavaScript is processing high-load data, UI rendering is likely to be blocked, the browser will freeze, and the user experience will be reduced.
[0038] Since Node.js has the function of multi-threading (worker_threads), the JavaScript program has at least one child thread running outside the main thread. While the main thread is running, the child thread runs in the background without interfering with each other. When the child thread completes the calculation task, it returns the result to the main thread to ensure that the main thread continues to render the UI, thereby improving the fluency of the application.
[0039] As an example, in step S201, the js main thread may receive a target operation request input by the user, and based on the target operation request including the VPN identifier and the target request information, perform a corresponding operation on the VPN connection to complete the user's timely management of the VPN connection. In this example, the user may input a corresponding command or operate a button on the interface according to the needs, thereby triggering the target operation request, and sending the target operation request to the js main thread.
[0040] In this example, the VPN identifier is an identifier used to uniquely identify a VPN instance, which can be the instance address corresponding to the VPN instance, or the instance name corresponding to the VPN instance. The target request information includes a task identifier. Common task identifiers include the task identifier corresponding to the network node synchronization task and the task identifier corresponding to the connection node change task. The task identifier is used by the js main thread to call the VPN sub-thread corresponding to the VPN instance from the task pool corresponding to the task identifier. Among them, the task pool exists based on the thread pool. The thread pool is planned according to the task project corresponding to the task pool, and the corresponding task thread number and timeout parameters are formulated. The thread pool solves the problem of system or application freeze caused by frequent creation or destruction of task threads.
[0041] As an example, in step S202, the js main thread detects the local cache according to the VPN identifier in the received target operation request, thereby determining whether there is a VPN instance corresponding to the VPN identifier in the local cache, and performing corresponding operations according to the status of the VPN instance. In this example, the VPN connection is based on the VPN SDK developed in the C language for network connection. The VPN SDK developed in the C language is also a VPN instance. The VPN instance is run through the VPN subthread corresponding to the js main thread to ensure that the VPN connection can run permanently, that is, run as a background resident thread.
[0042] Among them, VPN SDK may exist according to different network manufacturers, and it is used to connect to different networks.
[0043] As an example, in step S203, after the js main thread determines whether there is a VPN instance in the local cache, if the VPN instance exists in the local cache, the VPN sub-thread corresponding to the VPN instance is called to run.
[0044] In this example, the js main thread starts the VPN sub-thread instance through the VPN instance, wherein the VPN instance is obtained by processing according to the entry file path corresponding to the VPN sub-thread.
[0045] As an example, in step S204, after calling the VPN subprocess to run, the js main thread communicates with the VPN subthread through a message communication mechanism, and receives the target result information related to the target request information returned by the VPN subthread to determine the execution result corresponding to the target request information input by the user. In this example, after the VPN subthread runs, it establishes a corresponding network connection according to actual business needs, thereby providing corresponding network services for the system.
[0046] In this example, the message communication mechanism is a multi-threaded communication module based on TCP encapsulation in the Node.js environment, which is a module that comes with Node.js after installation. Node.js is a JavaScript runtime environment based on the ChromeV8 engine and a development platform for JavaScript running on the server.
[0047] In this example, the VPN subthread is based on the message communication mechanism of Node.js, that is, the multi-thread communication module, and the message communication mechanism adopts asynchronous communication to improve resource utilization efficiency. Since the process resource isolation is strong, while the thread resource isolation is weak, by utilizing the conversion mechanism between threads and processes, a combination of the js main thread and the VPN subthread is set to improve the stability of VPN connection management.
[0048] In this example, by obtaining the target operation request input by the user, it is determined whether there is a VPN instance corresponding to the VPN identifier in the local cache according to the VPN identifier in the target operation request. If the VPN instance exists in the local cache, the VPN sub-thread corresponding to the VPN instance is called to run, so as to use the VPN sub-thread to perform corresponding operations in the application; then, the VPN sub-thread is communicated with through the message communication mechanism, and the target result information related to the target request information returned by the VPN sub-thread is received to obtain feedback information on the operation of the VPN connection, and the corresponding management operations are performed on the VPN while ensuring the smoothness of the application.
[0049] In one embodiment, if Figure 3 As shown, in step S203, if there is a VPN instance in the local cache, calling the VPN subthread corresponding to the VPN instance to run includes:
[0050] S301: If a VPN instance exists in the local cache, a status check is performed on the VPN subthread corresponding to the VPN instance;
[0051] S302: If the VPN sub-thread is in a normal state, call the VPN sub-thread to run;
[0052] S303: If the VPN sub-thread is in an abnormal state, restart the VPN sub-thread according to a preset time.
[0053] As an example, in step S301, after confirming that the VPN instance exists in the local cache, the js main thread performs a status check on the VPN subthread corresponding to the VPN instance to confirm whether the VPN subthread is abnormal, and then performs subsequent operations according to the status of the VPN subthread to ensure the stability of the VPN subthread. The abnormal status of the VPN subthread includes abnormal conditions such as entry error, code error, and operation crash; the normal state of the VPN subthread is that the VPN subthread has no abnormal conditions.
[0054] As an example, in step S302, when the state of the VPN sub-thread confirmed by the js main thread is normal, the VPN sub-thread is directly called to enable the VPN sub-thread to run normally.
[0055] As an example, in step S303, when the state of the VPN subthread confirmed by the js main thread is an abnormal state, the abnormal information of the abnormal state of the VPN subthread is identified, and the abnormal information can also be used to feedback to the user so that the user can make corresponding countermeasures. At the same time, the VPN subthread is restored according to the preset time, and when the waiting time reaches the preset time, the VPN subthread is restarted to avoid frequent calls in the abnormal state, so as to ensure the stability of the VPN subthread operation.
[0056] In this example, when the state of the VPN sub-thread is abnormal, the process of the VPN sub-thread is recovered through an initialization mechanism. The initialization mechanism detects the abnormal state of the thread by monitoring the error event (error) and exit event (exit) of the VPN sub-thread, thereby performing a delayed restart to recover the VPN sub-process.
[0057] In this example, before calling the VPN sub-thread corresponding to the VPN instance to run, the status of the VPN sub-thread corresponding to the VPN instance in the local cache is detected. When the VPN sub-thread is in a normal state, the VPN sub-thread is directly called to run; when the VPN sub-thread is in an abnormal state, an abnormal information is prompted, and the VPN sub-thread is restarted after a preset time to ensure the stability of the VPN sub-thread operation.
[0058] In one embodiment, if Figure 4 As shown, step S204, communicating with the VPN sub-thread through the message communication mechanism, receiving the target result information related to the target request information returned by the VPN sub-thread, including:
[0059] S401: Obtain a first message according to target request information, and send the first message to a VPN subthread, where the first message includes a request number, a method name, and request parameters;
[0060] S402: receiving a second message returned by the VPN subthread after processing the first message, wherein the VPN subthread performs parsing processing on the first message including: obtaining a method execution result according to a method name and a request parameter, and obtaining a second message according to a request number and the method execution result;
[0061] S403: Process the second message to obtain target result information corresponding to the target request information.
[0062] Among them, in the Node.js environment, the message communication mechanism is multi-threaded communication, and a dynamic proxy (Proxy) will be set up. Based on the Node.js environment, since the proxy role thread (Thread class) does not need to be created by itself, it only needs to determine the corresponding target, that is, the VPN sub-thread or js main thread in this example, and perform corresponding forwarding through the dynamic proxy to confirm the corresponding connection and establish a unified communication mechanism.
[0063] As an example, in step S401, after the js main thread communicates with the VPN sub-thread through the message communication mechanism, it generates a first message including a request number, a method name and request parameters according to the target request information input by the user, and sends it to the VPN sub-thread.
[0064] In this example, when the js main thread calls the VPN sub-thread to execute a certain function, it needs to generate a first message consisting of a unique request number, method name and request parameters as the corresponding request information, so as to be forwarded to the corresponding VPN sub-thread through the dynamic proxy.
[0065] As an example, in step S402, after sending the first message, the js main thread receives the second message returned by the VPN subthread after processing the first message. After receiving the first message sent by the js main thread, the VPN subthread processes the first message. During the processing, the VPN subthread first processes the method name and request parameters according to its own built-in events to obtain the method execution result; then the request number and the method execution result are combined into a second message and passed back to the main thread.
[0066] In this example, if the js main thread needs the VPN child thread to execute VPNInvoker.method1(arg1,arg2), where the method name is method1 and the request parameters are (arg1,arg2), it is sent to the dynamic proxy (Proxy) according to the generated request number. After confirming the target VPN child thread, the dynamic proxy (Proxy) forwards PNInvoker.method1(arg1,arg2) to the VPN child thread to process the corresponding method1(arg1,arg2) for the corresponding VPN network connection and obtain the method execution result; and sends the method execution result and the request number as the second message to the js main thread.
[0067] As an example, in step S403, after receiving the second message fed back by the VPN sub-thread, the js main thread parses and processes the second message, determines the target result information of the VPN sub-thread executing the target request information, and feeds it back to the user.
[0068] In this example, the js main thread generates a first message with a request number, method name and request parameters for the target request information, and sends the first message to the VPN sub-thread through a dynamic proxy; the VPN sub-thread processes the first message and returns a second message, thereby obtaining the target result information of the VPN sub-thread processing the target request information, and timely feeding back to the user, so as to keep other tasks of the main thread from interfering with the operation of the VPN sub-thread, thereby ensuring the smoothness of the application.
[0069] In another embodiment, if Figure 5 As shown, in step S201, before obtaining the target operation request input by the user, the VPN connection management method further includes:
[0070] S501: Obtain the entry file path corresponding to the VPN sub-thread;
[0071] S502: Instantiate according to the entry file path to obtain a VPN instance;
[0072] S503: Cache the VPN instance into the local cache, so that the VPN sub-thread corresponding to the VPN instance runs as a background resident thread.
[0073] Among them, instantiation is to apply for the allocation of memory space through an abstract class. According to the size of the space applied for by the class structure, an instance corresponding to the class is actually generated in the memory, in which the defined data can be stored and the methods can be called.
[0074] As an example, in step S501, when the js main thread initially sets up the VPN sub-thread, it first obtains the entry file path of the entry file corresponding to the VPN sub-thread, and instantiates it to call the corresponding VPN sub-thread.
[0075] In another example, the VPN subthread manages multiple SDKs in the VPN connection by setting an entry file for controlling subsequent VPN functions. The entry file path of the entry file is sent to the js main thread, so that the js main thread establishes a corresponding VPN instance according to the entry file path for calling the VPN subthread.
[0076] In this example, based on the InvokableThread (callable thread) abstract class, as the corresponding entry function, and the VPN connection inherits the entry function, VPNThread.js is obtained as the entry file. Among them, InvokableThread is used to implement the sub-thread function of JavaScript, and the entry function is the entry point of multiple functions used in the VPN sub-thread, that is, the corresponding other functions are started through the entry function; the file corresponding to the entry function is the entry file.
[0077] As an example, in step S502, after obtaining the entry file path corresponding to the entry file, the js main thread is instantiated according to the entry file path so that the VPN sub-thread can run.
[0078] In this example, the js main thread performs initialization, abnormal restart, recycling, and communication management with threads of worker_threads based on the WorkerInvoker class. That is, if the VPN sub-thread needs to be called, the VPNThread.js path of the entry file is obtained to instantiate it. In subsequent calls, only invoker.connect(arg1, arg2) needs to be executed, and invoker will enable the VPN sub-thread to control the dynamic proxy to call VPNThread.connect(arg1, arg2).
[0079] As an example, in step S503, after obtaining the VPN instance corresponding to the VPN sub-thread, the js main thread caches the VPN instance into the local cache, so that the VPN sub-thread runs as a background resident thread and can smoothly call the corresponding VPN sub-thread through the VPN instance.
[0080] In this example, the js main thread obtains the entry file corresponding to the VPN sub-thread by adopting the entry function, and instantiates the entry file path corresponding to the VPN sub-thread according to the entry file path corresponding to the entry file to obtain the VPN instance, thereby caching the VPN instance into the local cache, so that the VPN sub-thread corresponding to the VPN instance runs as a background resident thread, thereby maintaining the stability of the VPN connection.
[0081] In another embodiment, if Figure 6 As shown, in step S204, after communicating with the VPN sub-thread through the message communication mechanism and receiving the target result information related to the target request information returned by the VPN sub-thread, the VPN connection management method further includes:
[0082] S601: Monitor the status of the VPN sub-thread and obtain the idle state duration of the VPN sub-thread;
[0083] S602: If the idle state duration is longer than a preset duration threshold, the VPN sub-thread is closed, so that the VPN sub-thread enters a background running state.
[0084] As an example, in step S601, after calling the VPN sub-thread to run, the js main thread keeps monitoring the status of the VPN sub-thread, and monitors the duration of the idle state of the current VPN sub-thread to confirm the idle state duration of the VPN sub-thread.
[0085] As an example, in step S602, after confirming the idle state duration of the VPN subthread, the js main thread determines the idle state duration of the VPN subthread. If the idle state duration is greater than the preset duration threshold, the VPN subthread is closed, so that the VPN subthread enters the background running state, thereby reducing the memory occupied by the VPN subthread and improving the running speed of the application. Among them, the background running state is to maintain the VPN subthread, and reduce the memory occupied by the VPN subthread by retaining the necessary processes. Different from the background resident, after the VPN subthread enters the background, the state will change according to the actual business needs, such as being terminated or called out. Only by maintaining the background running state can the VPN subthread always maintain the background running state and will not be terminated, thereby improving the stability of the VPN subthread operation.
[0086] In this example, by keeping the status of the VPN sub-thread monitored and confirming the idle state duration of the VPN sub-thread, the idle state duration of the VPN sub-thread is judged. If the idle state duration is greater than the preset duration threshold, the VPN sub-thread is closed, thereby reducing the memory occupied by the VPN sub-thread and improving the running speed of the application.
[0087] In another embodiment, if Figure 7 As shown, in step S204, after communicating with the VPN sub-thread through the message communication mechanism and receiving the target result information related to the target request information returned by the VPN sub-thread, the VPN connection management method further includes:
[0088] S701: Monitor the status of each VPN sub-thread with the same task identifier and obtain a thread status summary, where the thread status summary includes the number of idle threads and the number of running threads;
[0089] S702: Control each VPN sub-thread corresponding to the same task identifier according to the number of idle threads and the number of running threads.
[0090] As an example, in step S701, after calling the VPN subthread to run, the js main thread monitors the status of each VPN subthread corresponding to the same task identifier, and summarizes the number of idle threads and the number of running threads monitored to obtain a thread status summary for resource regulation. The number of idle threads is the number of VPN subthreads corresponding to the same task identifier that are in an idle state. The number of running threads is the number of VPN subthreads corresponding to the same task identifier that are in a running state.
[0091] As an example, in step S702, after obtaining the thread status summary, the js main thread controls all VPN sub-threads corresponding to the same task identifier based on the number of idle threads and the number of running threads in the thread status summary. The control method includes maintaining each VPN sub-thread with the same task identifier when the occupied memory is small; and closing some VPN sub-threads according to business needs when the occupied memory is large.
[0092] In this example, the js main thread monitors the status of each VPN sub-thread with the same task identifier to obtain the thread status summary including the number of idle threads and the number of running threads, and then manages each VPN sub-thread corresponding to the same task identifier according to the number of idle threads and the number of running threads to regulate the system's memory resources and improve the stability of the js main thread.
[0093] In one embodiment, in step S702, each VPN sub-thread corresponding to the same task identifier is managed and controlled according to the number of idle threads and the number of running threads, including:
[0094] S7021: If the number of idle threads is greater than the number of running threads, obtain the target number of threads according to the thread status summary, and destroy the VPN sub-threads corresponding to the target number of threads;
[0095] S7022: If the number of idle threads is not greater than the number of running threads, the current state of each VPN sub-thread with the same task identifier is maintained.
[0096] As an example, in step S7021, the js main thread compares the number of idle threads and the number of running threads detected. When the number of idle threads is greater than the number of running threads, the target number of threads corresponding to the business demand is determined based on the number of idle threads and the number of running threads, and is used to destroy the VPN sub-threads corresponding to the target number of threads to save memory resources. The target number of threads here is the number of VPN sub-threads in an idle state that need to be destroyed.
[0097] In this example, the js main thread obtains the occupied memory corresponding to the current moment. When the occupied memory corresponding to the current moment is greater than the preset threshold, the number of idle threads detected is compared with the number of running threads. When the number of idle threads is greater than the number of running threads, the target number of threads is determined based on the number of idle threads and the number of running threads to destroy the VPN sub-threads corresponding to the target number of threads to save memory resources.
[0098] As an example, in step S7022, the js main thread compares the detected number of idle threads with the number of running threads. When the number of idle threads is not greater than the number of running threads, the current state of each VPN sub-thread with the same task identifier is maintained.
[0099] In this example, it is judged whether the number of idle threads is greater than the number of running threads. When the number of idle threads is greater than the number of running threads, the VPN sub-threads corresponding to the target number of threads corresponding to the thread status summary are destroyed to reduce the usage of memory resources and improve the stability of the js main thread.
[0100] It should be understood that the order of execution of the steps in the above embodiment does not necessarily mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiment of the present invention.
[0101] In one embodiment, a VPN connection management device is provided, and the VPN connection management device corresponds one-to-one with the VPN connection management method in the above embodiment. Figure 8 As shown, the VPN connection management device includes a target operation request acquisition module 801, a VPN instance detection module 802, a VPN subthread calling module 803 and a target result information receiving module 804. Each functional module is described in detail as follows:
[0102] The target operation request acquisition module 801 is used to acquire the target operation request input by the user, where the target operation request includes a VPN identifier and target request information;
[0103] A VPN instance detection module 802, configured to determine whether a VPN instance corresponding to the VPN identifier exists in the local cache according to the VPN identifier;
[0104] The VPN sub-thread calling module 803 is used to call the VPN sub-thread corresponding to the VPN instance to run if the VPN instance exists in the local cache;
[0105] The target result information receiving module 804 is used to communicate with the VPN sub-thread through a message communication mechanism, and receive the target result information related to the target request information returned by the VPN sub-thread.
[0106] In one embodiment, the VPN subthread calling module 803 includes:
[0107] A VPN sub-thread state detection unit, configured to detect the state of a VPN sub-thread corresponding to the VPN instance if a VPN instance exists in the local cache;
[0108] A VPN sub-thread calling unit, used to call the VPN sub-thread to run if the VPN sub-thread is in a normal state;
[0109] The VPN sub-thread restart unit is used to restart the VPN sub-thread according to a preset time if the VPN sub-thread is in an abnormal state.
[0110] In one embodiment, the target result information receiving module 804 includes:
[0111] A first message acquisition unit, configured to acquire a first message according to target request information, and send the first message to the VPN subthread, wherein the first message includes a request number, a method name, and request parameters;
[0112] A second message acquisition unit is used to receive a second message returned by the VPN subthread after processing the first message, wherein the VPN subthread performs parsing processing on the first message including: acquiring a method execution result according to a method name and request parameters, and acquiring a second message according to a request number and the method execution result;
[0113] The target result information acquisition unit is used to process the second message and acquire the target result information corresponding to the target request information.
[0114] In another embodiment, the VPN connection management device further includes:
[0115] An entry file path acquisition module is used to obtain the entry file path corresponding to the VPN sub-thread;
[0116] A VPN instance acquisition module is used to instantiate and acquire a VPN instance according to an entry file path;
[0117] The VPN instance cache module is used to cache the VPN instance into the local cache so that the VPN subthread corresponding to the VPN instance runs as a background resident thread.
[0118] In another embodiment, the VPN connection management device further includes:
[0119] An idle state duration acquisition module is used to monitor the state of the VPN sub-thread and obtain the idle state duration of the VPN sub-thread;
[0120] The VPN sub-thread closing module is used to close the VPN sub-thread if the idle state duration is longer than a preset duration threshold, so that the VPN sub-thread enters the background running state.
[0121] In another embodiment, the VPN connection management device further includes:
[0122] The thread status summary acquisition module is used to monitor the status of each VPN sub-thread with the same task identifier and obtain the thread status summary, which includes the number of idle threads and the number of running threads;
[0123] The VPN sub-thread management and control module is used to manage each VPN sub-thread corresponding to the same task identifier according to the number of idle threads and the number of running threads.
[0124] In one embodiment, the VPN sub-thread management module is further configured to:
[0125] A first VPN sub-thread control unit is used to obtain the target number of threads according to the thread state summary if the number of idle threads is greater than the number of running threads, and destroy the VPN sub-threads corresponding to the target number of threads;
[0126] The second VPN sub-thread control unit is used to maintain the current state of each VPN sub-thread with the same task identifier if the number of idle threads is not greater than the number of running threads.
[0127] For the specific definition of the VPN connection management device, please refer to the definition of the VPN connection management method above, which will not be repeated here. Each module in the above VPN connection management device can be implemented in whole or in part by software, hardware and a combination thereof. Each of the above modules can be embedded in or independent of the processor in the computer device in the form of hardware, or can be stored in the memory of the computer device in the form of software, so that the processor can call and execute the operations corresponding to each of the above modules.
[0128] In one embodiment, a computer device is provided. The computer device may be a server, and its internal structure diagram may be as follows: Fig. 9As shown. The computer device includes a processor, a memory, a network interface and a database connected through a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to execute the data used or generated in the process of the VPN connection management method. The network interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, a VPN connection management method is implemented.
[0129] In one embodiment, a computer device is provided, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the VPN connection management method in the above embodiment is implemented, for example Figure 2 S201-S204 as shown, or Figures 3 to 7 Alternatively, when the processor executes the computer program, the functions of each module / unit in the embodiment of the VPN connection management device are realized, for example Figure 8 The functions of the target operation request acquisition module 801, VPN instance detection module 802, VPN subthread calling module 803 and target result information receiving module 804 are not described here in detail to avoid repetition.
[0130] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the VPN connection management method in the above embodiment is implemented, for example Figure 2 S201-S204 as shown, or Figures 3 to 7 Alternatively, when the computer program is executed by a processor, the functions of each module / unit in the embodiment of the VPN connection management device are realized, for example Figure 8 The functions of the target operation request acquisition module 801, VPN instance detection module 802, VPN subthread calling module 803 and target result information receiving module 804 are not described here in detail to avoid repetition.
[0131] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided by the present invention can include non-volatile and / or volatile memory. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory can include random access memory (RAM) or external cache memory. As an illustration and not limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (RambuS) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM).
[0132] Those skilled in the art can clearly understand that for the convenience and simplicity of description, only the division of the above-mentioned functional units and modules is used as an example. In actual applications, the above-mentioned functions can be distributed and completed by different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above.
[0133] The above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit the same. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features may be replaced by equivalents. Such modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention, and should be included in the protection scope of the present invention.
Claims
1. A VPN connection management method, characterized in that: Including the following steps executed by the js main thread: Acquire a target operation request input by a user, wherein the target operation request includes a VPN identifier and target request information; According to the VPN identifier, determining whether there is a VPN instance corresponding to the VPN identifier in the local cache; If the VPN instance exists in the local cache, calling the VPN subthread corresponding to the VPN instance to run; Communicate with the VPN subthread through the dynamic proxy corresponding to the message communication mechanism; Acquire a first message according to the target request information; after the dynamic proxy confirms the VPN sub-thread, forward the first message to the VPN sub-thread through the dynamic proxy, wherein the first message includes a request number, a method name, and request parameters; Receiving a second message returned by the VPN subthread after processing the first message, wherein the VPN subthread processing the first message includes: obtaining a method execution result according to the method name and the request parameter, and obtaining a second message according to the request number and the method execution result; The second message is processed to obtain target result information corresponding to the target request information.
2. The VPN connection management method according to claim 1, wherein: If the VPN instance exists in the local cache, calling the VPN subthread corresponding to the VPN instance to run includes: If the VPN instance exists in the local cache, performing status detection on the VPN subthread corresponding to the VPN instance; If the VPN sub-thread is in a normal state, calling the VPN sub-thread to run; If the VPN sub-thread is in an abnormal state, the VPN sub-thread is restarted according to a preset time.
3. The VPN connection management method according to claim 1, wherein: Before obtaining the target operation request input by the user, the VPN connection management method further includes: Obtain the entry file path corresponding to the VPN subthread; Instantiate according to the entry file path to obtain a VPN instance; The VPN instance is cached in a local cache so that a VPN subthread corresponding to the VPN instance runs as a background resident thread.
4. The VPN connection management method according to claim 1, wherein: After processing the second message to obtain target result information corresponding to the target request information, the VPN connection management method further includes: Monitor the state of the VPN sub-thread to obtain the idle state duration of the VPN sub-thread; If the idle state duration is longer than a preset duration threshold, the VPN sub-thread is closed so that the VPN sub-thread enters a background running state.
5. The VPN connection management method according to claim 1, wherein: After the step of processing the second message to obtain target result information corresponding to the target request information, the VPN connection management method further includes: Monitor the status of each VPN subthread with the same task identifier and obtain a thread status summary, where the thread status summary includes the number of idle threads and the number of running threads; Each VPN sub-thread corresponding to the same task identifier is managed and controlled according to the number of idle threads and the number of running threads.
6. The VPN connection management method according to claim 5, characterized in that: The controlling each VPN sub-thread corresponding to the same task identifier according to the number of idle threads and the number of running threads includes: If the number of idle threads is greater than the number of running threads, the target number of threads is obtained according to the thread state summary, and the VPN sub-threads corresponding to the target number of threads are destroyed; If the number of idle threads is not greater than the number of running threads, the current state of each VPN sub-thread with the same task identifier is maintained.
7. A VPN connection management device, characterized in that: It includes multiple modules for running the js main thread, including: A target operation request acquisition module, used to acquire a target operation request input by a user, wherein the target operation request includes a VPN identifier and target request information; A VPN instance detection module, used to determine whether there is a VPN instance corresponding to the VPN identifier in the local cache according to the VPN identifier; A VPN sub-thread calling module, configured to call the VPN sub-thread corresponding to the VPN instance to run if the VPN instance exists in the local cache; A target result information receiving module is used to communicate with a VPN sub-thread through a dynamic proxy corresponding to a message communication mechanism; obtain a first message according to the target request information; after the dynamic proxy confirms the VPN sub-thread, forward the first message to the VPN sub-thread through the dynamic proxy, wherein the first message includes a request number, a method name, and request parameters; receive a second message returned by the VPN sub-thread after processing the first message, wherein the VPN sub-thread processes the first message including: obtaining a method execution result according to the method name and the request parameters, and obtaining a second message according to the request number and the method execution result; and processing the second message to obtain target result information corresponding to the target request information.
8. A computer device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the VPN connection management method according to any one of claims 1 to 6 is implemented.
9. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the VPN connection management method according to any one of claims 1 to 6 is implemented.
