Network request processing method and device
By inserting network requests into the request pool queue and judging the requests based on the concurrency amount, the problem of low network request processing efficiency in the prior art is solved, effective concurrency control and resource utilization are achieved, and response speed and processing fluency are improved.
Patent Information
- Application Number
- CN202510027050.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-07
- Publication Date
- 2025-04-22
AI Technical Summary
In the case of a large number of network requests, the prior art controls the front-end network request frequency through throttling, but it may cause the request completion time and the throttling frequency interval time, resulting in congestion in requests or waste of idle resources.
By acquiring the network request and inserting it into the request pool queue, it is determined whether the number of network requests in the execution stage is less than the preset maximum request concurrency, and delisting processing is performed based on the judgment results or waiting for execution to be completed, and the number of concurrent requests is updated to ensure resource utilization and the fluency of request processing.
Effectively control the number of concurrent requests, avoid requests being blocked, maximize resource utilization, prevent resources from being idle, and ensure smooth operation and response speed of network request processing.
Smart Images

Figure CN119865469A_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present application relate to the field of Internet technology, and specifically to a method and device for processing a network request. Background Art
[0002] When there are a large number of network requests, the current common solution is to control the frequency of front-end network requests through throttling, thereby reducing the browser concurrency pressure. However, the time it takes to complete a network request may not be consistent with the throttling interval. If the network request completion time is greater than the throttling interval, it will cause the request to gradually become congested; if the network request completion time is less than the throttling interval, it will cause the browser request memory resources to be idle and wasted. Therefore, there is an urgent need for a solution that can effectively process network requests. Summary of the invention
[0003] In view of the above problems, the present application is proposed to provide a network request processing method, apparatus, computing device, computer storage medium and computer program product that overcome the above problems or at least partially solve the above problems.
[0004] According to one aspect of an embodiment of the present application, a network request processing method is provided, including:
[0005] S1, obtains the network request, inserts the network request into the request pool queue, and jumps to execute S2;
[0006] S2, determine whether the number of network requests in the execution phase is less than the preset maximum concurrent request amount and whether there are unexecuted network requests in the request pool queue; if so, execute S3; if the number of network requests in the execution phase is greater than or equal to the preset maximum concurrent request amount, execute S4; if there are no unexecuted network requests in the request pool queue, the method ends;
[0007] S3, dequeue and execute the network requests in the request pool queue, and update the number of network requests in the execution phase according to the number of dequeued network requests;
[0008] S4, wait for the network request to be executed, update the number of network requests in the execution phase according to the number of completed network requests, and jump to execute S2.
[0009] Further, waiting for the network request to be executed to be completed, and updating the number of network requests in the execution phase according to the number of network requests that have been executed further includes:
[0010] If any network request in the execution phase is completed, the number of network requests in the execution phase will be reduced by 1.
[0011] Further, dequeuing the network request in the request pool queue and executing further comprises:
[0012] In a first-in-first-out manner, the network request that is first inserted into the request pool queue is dequeued and executed each time.
[0013] Further, updating the number of network requests in the execution phase according to the number of dequeued network requests further includes: increasing the number of network requests in the execution phase by 1.
[0014] Furthermore, the method also includes: determining the maximum number of concurrent requests according to the browser kernel information.
[0015] Furthermore, inserting the network request into the request pool queue further includes:
[0016] Sort network requests based on request time, insert network requests into the request pool queue in sequence according to the sorting results, and record the request insertion time.
[0017] According to another aspect of an embodiment of the present application, a network request processing device is provided, including:
[0018] The insertion module is adapted to obtain a network request, insert the network request into a request pool queue, and trigger the execution of the judgment module;
[0019] A judgment module is adapted to judge whether the number of network requests in the execution phase is less than the preset maximum concurrent request amount and whether there are unexecuted network requests in the request pool queue; if so, the processing module is triggered to execute; if the number of network requests in the execution phase is greater than or equal to the preset maximum concurrent request amount, the update module is triggered to execute; if there are no unexecuted network requests in the request pool queue, the process ends;
[0020] A processing module, adapted to dequeue and execute network requests in the request pool queue, and update the number of network requests in the execution phase according to the number of dequeued network requests;
[0021] The updating module is adapted to wait for the network requests to be executed, update the number of network requests in the execution phase according to the number of network requests that have been executed, and trigger the execution of the judging module.
[0022] According to another aspect of the embodiment of the present application, there is provided a computing device, including: a processor, a memory, a communication interface and a communication bus, wherein the processor, the memory and the communication interface communicate with each other via the communication bus;
[0023] The memory is used to store at least one executable instruction, and the executable instruction enables the processor to execute operations corresponding to the above-mentioned network request processing method.
[0024] According to another aspect of the embodiments of the present application, a computer storage medium is provided, in which at least one executable instruction is stored, and the executable instruction enables a processor to perform operations corresponding to the above-mentioned network request processing method.
[0025] According to another aspect of the embodiments of the present application, a computer program product is provided, comprising at least one executable instruction, wherein the executable instruction enables a processor to perform operations corresponding to the above-mentioned network request processing method.
[0026] According to the network request processing method and device provided by the embodiment of the present application, by comparing the network request data in the execution stage with the preset maximum concurrent request amount, the number of concurrent requests can be effectively controlled to avoid exceeding the browser limit, thereby avoiding request blocking, and also ensuring maximum resource utilization and avoiding idle resources. The network requests in the execution stage are not in order, and the asynchronous callback is performed according to the first completed first. Even if some network requests are initiated earlier but completed later, the start execution of other network requests will not be blocked. In addition, after each network request is completed, the next network request is processed immediately if the above judgment conditions are met, which can effectively prevent the backlog of network requests, thereby improving the overall response speed and ensuring the smooth operation of network request processing.
[0027] The above description is only an overview of the technical solution of the embodiment of the present application. In order to more clearly understand the technical means of the embodiment of the present application, it can be implemented in accordance with the contents of the specification. In order to make the above and other purposes, features and advantages of the embodiment of the present application more obvious and easy to understand, the specific implementation method of the embodiment of the present application is listed below. BRIEF DESCRIPTION OF THE DRAWINGS
[0028] Various other advantages and benefits will become apparent to those of ordinary skill in the art by reading the detailed description of the preferred embodiments below. The accompanying drawings are only used for the purpose of illustrating the preferred embodiments and are not to be considered as limiting the embodiments of the present application. Moreover, the same reference symbols are used throughout the accompanying drawings to represent the same components. In the accompanying drawings:
[0029] Figure 1 A schematic diagram of a process of a network request processing method according to an embodiment of the present application is shown;
[0030] Figure 2 A schematic diagram showing a flow chart of a network request processing method according to another embodiment of the present application is shown;
[0031] Figure 3 Flowchart designed for high concurrent request pool JSSDK;
[0032] Figure 4 A schematic diagram showing a flow chart of a network request processing method according to another embodiment of the present application is shown;
[0033] Figure 5A-5D This is a schematic diagram of the effect of network request processing;
[0034] Figure 6 A structural block diagram of a network request processing device according to an embodiment of the present application is shown;
[0035] Figure 7 A schematic diagram of the structure of a computing device according to an embodiment of the present application is shown. DETAILED DESCRIPTION
[0036] The exemplary embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. Although the exemplary embodiments of the present disclosure are shown in the accompanying drawings, it should be understood that the present disclosure can be implemented in various forms and should not be limited by the embodiments set forth herein. On the contrary, these embodiments are provided to enable a more thorough understanding of the present disclosure and to fully convey the scope of the present disclosure to those skilled in the art.
[0037] First, the terms involved in one or more embodiments of the present application are explained.
[0038] axios: is a promise-based network request library that works in node.js and browsers.
[0039] shift(): The method removes the first element from an array and returns the value of that element. This method changes the length of the array.
[0040] then(): Promise instance method, callback function for Promise fulfillment and rejection.
[0041] catch(): Promise instance method used to register a function to be called when the promise is rejected.
[0042] finally(): Promise instance method used to register a function to be called when the promise is finalized (fulfilled or rejected).
[0043] Figure 1 A schematic diagram of a network request processing method according to an embodiment of the present application is shown. Figure 1 As shown, the method comprises the following steps:
[0044] Step S101, obtain a network request, insert the network request into a request pool queue, and jump to step S102.
[0045] Specifically, one or more network requests are received, and the network request may be input by a user, or triggered by a scheduled task, or triggered by a specific event, wherein each request is usually a function or a Promise, representing an asynchronous operation to be performed (such as an HTTP request). Then, the network request is inserted into the request pool queue, and then the execution jumps to step S102.
[0046] Step S102, determine whether the number of network requests in the execution stage is less than the preset maximum concurrent request amount and whether there are unexecuted network requests in the request pool queue; if so, execute step S103; if the number of network requests in the execution stage is greater than or equal to the preset maximum concurrent request amount, execute step S104; if there are no unexecuted network requests in the request pool queue, the method ends.
[0047] In order to maximize resource utilization and avoid request congestion, the acquired network requests are not executed immediately. The following judgment is required: whether the number of network requests in the execution phase is less than the preset maximum request concurrency and whether there are unexecuted network requests in the request pool queue. The preset maximum request concurrency is the maximum allowed request concurrency, that is, the maximum number of network requests allowed to be executed.
[0048] The number of network requests in the execution stage is less than the preset maximum concurrent request amount, which means that the number of network requests in execution is less than the maximum concurrent request amount and there are idle resources; the number of network requests in the execution stage is greater than or equal to the preset maximum concurrent request amount, which means that the number of network requests in execution has reached the maximum concurrent request amount and there are no idle resources; there are no unexecuted network requests in the request pool queue, which means that the request pool queue is empty and all network requests have been executed; there are unexecuted network requests in the request pool queue, which means that the request pool queue is not empty and there are network requests that have not been executed.
[0049] Therefore, when it is determined that the number of network requests in the execution stage is less than the preset maximum request concurrency and there are still unexecuted network requests in the request pool queue, you can jump to step S103; when it is determined that the number of network requests in the execution stage is greater than or equal to the preset maximum request concurrency, you can jump to step S104; if there are no unexecuted network requests in the request pool queue, it means that all network requests in the request pool queue have been executed, and there are no new network requests, and the method ends. Here, we take the example of inserting at least one network request into the request pool queue at a time and executing all network requests in the request pool queue. After all network requests in the request pool queue have been executed, the method ends.
[0050] Step S103, dequeueing and executing the network requests in the request pool queue, and updating the number of network requests in the execution phase according to the number of dequeued network requests.
[0051] When it is determined that the number of network requests in the execution phase is less than the preset maximum request concurrency and there are still unexecuted network requests in the request pool queue, the network request can be taken out of the request pool queue and removed, that is, the network request is dequeued, and then the network request is executed. After the network request is executed, the number of network requests in the execution phase changes. Therefore, it is also necessary to update the number of network requests in the execution phase according to the number of dequeued network requests. After the network request is dequeued and executed, the number of network requests in the execution phase is updated in time, so that it is possible to accurately know how many network requests are currently being executed, so as to strictly control the number of concurrent requests and ensure that it does not exceed the preset maximum concurrency.
[0052] Step S104, waiting for the network request to be executed, updating the number of network requests in the execution phase according to the number of network requests that have been executed, and jumping to step S102.
[0053] When it is determined that the number of network requests in the execution phase is greater than or equal to the preset maximum concurrent request amount, it is necessary to wait for the network requests to be executed; in addition, after the network requests are dequeued and executed, it is also necessary to wait for the network requests to be executed. When a network request has been executed, the number of network requests in the execution phase can be updated according to the number of completed network requests, and the execution of step S102 can be jumped, so that the idle concurrent slots can be quickly filled after each network request is completed, thereby maximizing the concurrent utilization rate.
[0054] It should be noted that there is no order in the network requests in the execution phase. After any network request is executed, the number of network requests in the execution phase will be updated. The one that is executed first will be updated first, and then the process will jump to step S102 to check whether there are any unexecuted network requests in the request pool queue. If the conditions of step S102 are met, a new network request will be started to ensure that the completion order of the network requests will not affect the start of the new network request.
[0055] According to the method provided in the embodiment of the present application, by comparing the network request data in the execution stage with the preset maximum concurrent request amount, the number of concurrent requests can be effectively controlled to avoid exceeding the browser limit, thereby avoiding request blocking and ensuring maximum resource utilization.
[0056] Figure 2 A schematic diagram of a network request processing method according to another embodiment of the present application is shown. Figure 2As shown, the method comprises the following steps:
[0057] Step S201, determining the maximum number of concurrent requests according to browser kernel information.
[0058] For example, you can first obtain the kernel information of the browser, and query the concurrency configuration file based on the kernel information. The concurrency configuration file records the mapping relationship between the kernel information and the maximum concurrent requests, so as to determine the maximum concurrent requests allowed by the browser. Among them, the maximum concurrent requests of Chrome browser, Edge browser, and Firefox browser are 6, the maximum concurrent requests of Safari browser is 4, and the maximum concurrent requests of Opera browser is 8.
[0059] Step S202, obtain network requests, sort the network requests based on request time, insert the network requests into the request pool queue in sequence according to the sorting result, record the request insertion time, and jump to execute step S203.
[0060] Specifically, one or more network requests are received. The network request can be input by the user, triggered by a scheduled task, or triggered by a specific event. Each request is usually a function or Promise, which represents an asynchronous operation to be performed (such as an HTTP request).
[0061] Each network request can be encapsulated as an object or function, which contains the necessary information of the request (such as URL, method, parameters, etc.). These request objects will be stored in the request pool queue for subsequent processing.
[0062] For each network request, the request time of the network request is recorded, and then the network requests are sorted according to the request time, from small to large or from large to small, and the network requests are inserted into the request pool queue in sequence according to the sorting results. The request time is inserted first. Since there may be multiple network requests with the same request time, for network requests with the same request time, these network requests can be randomly inserted into the request pool queue. In order to facilitate the subsequent dequeuing of requests, the request insertion time can be recorded, and the subsequent dequeuing can be based on the request insertion time. The request pool queue is a first-in-first-out (FIFO) data structure used to store network requests that have not yet been executed. Each time a new network request arrives, the network request will be inserted at the end of the queue.
[0063] Step S203: Determine whether the number of network requests in the execution stage is less than the preset maximum request concurrency and whether there are unexecuted network requests in the request pool queue; if so, execute Step S204; if the number of network requests in the execution stage is greater than or equal to the preset maximum request concurrency, execute Step S205; if there are no unexecuted network requests in the request pool queue, the method ends.
[0064] To ensure the maximization of resource utilization and avoid request congestion, the obtained network requests are not immediately executed. The following judgments are also required: Determine whether the number of network requests in the execution stage is less than the preset maximum request concurrency and whether there are unexecuted network requests in the request pool queue. The preset maximum request concurrency is the maximum allowable request concurrency, that is, the maximum number of network requests allowed to be executed, which can be represented by maxConcurrentRequests.
[0065] Specifically, a request count counter requestIng (type: number) in the execution stage can be maintained to record the number of network requests currently in the execution stage. Each time a new network request enters the execution stage, requestIng increases; each time a network request is completed, requestIng decreases. Among them, the network requests in the request pool queue share this variable. Therefore, the count value of this execution stage request count counter can be read to determine whether the following Condition 1 is satisfied: requestIng < maxConcurrentRequests, that is, whether the number of network requests in the execution stage is less than the preset maximum request concurrency.
[0066] In addition, it is also necessary to determine whether there are still unexecuted network requests in the request pool queue. If the request pool queue is empty, it means that all network requests have been processed. Here, determining whether there are unexecuted network requests in the request pool queue can be achieved through the following method: Determine whether the length of the request pool queue is greater than 0 (that is, Condition 2: queue.length > 0)
[0067] If both conditions are satisfied (that is, requestIng < maxConcurrentRequests and queue.length > 0), execute Step S204, dequeue and execute the new network request.
[0068] If requestIng >= maxConcurrentRequests, execute Step S205 and wait for the currently executing network requests to complete.
[0069] If queue.length === 0, it means that all network requests in the request pool queue have been executed and the method ends.
[0070] Step S204: In a first-in-first-out manner, the network request first inserted into the request pool queue is dequeued and executed each time, and the number of network requests in the execution phase is increased by 1.
[0071] When it is determined that the number of network requests in the execution phase is less than the preset maximum concurrent request amount and there are still unexecuted network requests in the request pool queue, the network request first inserted into the request pool queue is dequeued in a first-in-first-out manner. Since each dequeue removes the network request from the request pool queue, the network request at the head of the request pool queue is the first to be inserted into the request pool queue relative to other network requests in the request pool queue. Therefore, the first network request in the request pool queue can be dequeued and executed. The network request taken out is a function that returns a Promise, which is called to execute the request. For example, the shift() method can be used to dequeue the first network request from the request pool queue and delete the first network request. The shift() method changes the number of network requests stored in the request pool queue.
[0072] After the network request is executed, the number of network requests in the execution phase changes. Therefore, the number of network requests in the execution phase needs to be updated, for example, the number of network requests in the execution phase is increased by 1 (i.e., requestIng+1). After the network request is dequeued for execution, the number of network requests in the execution phase is updated in a timely manner, so that it is possible to accurately know how many network requests are currently being executed, so as to strictly control the number of concurrent requests and ensure that it does not exceed the preset maximum concurrency.
[0073] In addition, all network requests are queued in order in the request pool queue, and are dequeued and entered into the execution phase according to the first-in-first-out principle, ensuring that network requests with earlier request times can be executed first, thus avoiding long waiting times.
[0074] Step S205, waiting for the network request to be executed. If any network request in the execution phase is executed, the number of network requests in the execution phase is reduced by 1, and the execution jumps to step S203.
[0075] When it is determined that the number of network requests in the execution phase is greater than or equal to the preset maximum concurrent request amount, it is necessary to wait for the network request to be executed; in addition, after the network request is dequeued and executed, it is also necessary to wait for the network request to be executed, and then() and catch() are used to handle the success and failure of the network request. If any network request in the execution phase is executed, the asynchronous callback executes finally() to ensure that the requestIng counter is updated after the request is completed, and the number of network requests in the execution phase is reduced by 1, and the execution step S203 is jumped. Here, outQueue() is called again to check whether there are more network requests that can be executed. It should be noted that the specific execution result does not matter here. Whether the execution fails or succeeds, it is considered to be completed. Therefore, the number of network requests in the execution phase will be reduced by 1, and the execution step S203 will be jumped, so that the idle concurrent slots can be quickly filled after each network request is completed, maximizing the concurrent utilization rate.
[0076] There is no order difference in the network requests in the execution stage. The number of network requests in the execution stage can be reduced by 1 immediately after each network request is executed. Then, the execution jumps to step S203 to check the request pool queue and start executing a new network request, ensuring that the completion order of the network requests will not affect the start of the new network request execution, and realizing "first completed, first asynchronous callback", so that even if some network requests are initiated earlier but completed later, they will not block the start of other network requests. In addition, processing the next network request immediately after each network request is completed can effectively prevent the backlog of network requests, thereby improving the overall response speed and ensuring the smooth operation of network request processing.
[0077] According to the network request processing method provided by the embodiment of the present application, by comparing the network request data in the execution phase with the preset maximum concurrent request amount, the number of concurrent requests can be effectively controlled to avoid exceeding the browser limit, thereby avoiding request blocking, and also ensuring maximum resource utilization and avoiding idle resources. The network requests in the execution phase are not in order, and the asynchronous callback is performed according to the first completed first. Even if some network requests are initiated earlier but completed later, the start execution of other network requests will not be blocked. In addition, after each network request is completed, the next network request is processed immediately if the above judgment conditions are met, which can effectively prevent the backlog of network requests, thereby improving the overall response speed and ensuring the smooth operation of network request processing.
[0078] Figure 3 Flowchart designed for high concurrent request pool JSSDK. Figure 4 A schematic diagram of a network request processing method according to another embodiment of the present application is shown. Figure 3 and Figure 4 Provide explanation.
[0079] like Figure 3 As shown, define the request pool initialization function handleQueue(), and use the handleQueue() method to initialize the request queue. Initialize two variables: Variable 1 (type: array): request pool queue queue, used to store the network requests to be executed. Variable 2 (type: number): requesting, a counter of the number of network requests in the execution phase, used to record the number of network requests currently being executed.
[0080] The outQueue() function is used to execute the request. It is necessary to make a conditional judgment: whether the number of network requests in the execution phase is less than the maximum concurrent request amount and whether there are pending network requests in the request pool. If the judgment is satisfied, the queue element of the request pool queue is dequeued and requestPromise is executed to process the request. After the request is executed, requesting is decremented by 1 and outQueue() is executed.
[0081] The request is enqueued and the closure mechanism is used to ensure that outQueue() is executed each time a request is enqueued. Variables 1 and 2 are shared between elements in the request pool queue.
[0082] like Figure 4As shown in the figure, first, determine the maximum request concurrency based on the browser kernel information. For example, you can first obtain the kernel information of the browser and query the concurrency configuration file according to the kernel information. The concurrency configuration file records the mapping relationship between the kernel information and the maximum request concurrency, so as to determine the maximum request concurrency allowed by the browser. Among them, the maximum request concurrency of Chrome browser, Edge browser, and Firefox browser is 6, the maximum request concurrency of Safari browser is 4, and the maximum request concurrency of Opera browser is 8. Pass this maximum concurrency as a parameter to the initQueue() function. The initQueue() function is responsible for setting and managing the initial state of the request pool queue, including configuring the maximum request concurrency, initializing the counter, etc. By setting the maximum request concurrency, it is possible to avoid exceeding the request processing limit of the browser, prevent requests from being blocked, and maximize resource utilization. Here, mainly 2 event processes are used for processing. The first is the js synchronous process for loop, and the second is the js asynchronous process requestPromise execution end callback. Among them, when executing the for loop (looping and executing the closure function), it is judged whether the loop counter i is less than the total number of network requests. If so, network request elements are inserted into the request pool queue queue in sequence, and outqueue() is executed. The main purpose is to judge whether the number of network requests in the execution stage is less than the preset maximum request concurrency and whether there are unexecuted network requests in the request pool queue. If so, dequeueing is performed. In the first-in, first-out manner, the first request element in the request pool queue queue is removed from the queue and enters the execution stage, that is, this network request is executed, and requestIng is incremented by 1. Then() and catch() are used to handle the success and failure of network requests. After any network request in the execution stage is completed (whether it is successful or failed), finally() will be asynchronously called back. It should be noted that the one that finishes the request first will asynchronously call back finally() first. The code in finally() will execute: requestIng is decremented by 1, indicating that a network request has been completed. In the finally block, the outQueue function will be recursively called to recheck the current request quantity and the request pool queue status. If there are idle concurrency slots at this time (that is, requestIng < maxConcurrentRequests), and there are still unexecuted network requests in the request pool queue, then outQueue will continue to start and execute new network requests.
[0083] If the number of network requests in the execution phase has reached or exceeded the preset maximum concurrent request amount (requestIng>=maxConcurrentRequests), new requests cannot be started immediately. At this time, the network request execution will be completed.
[0084] This recursive calling mechanism ensures that the queue is checked immediately after each network request is completed, and new network requests are started as much as possible. The whole process is asynchronous and will not block the main thread.
[0085] Specifically, it can be achieved through the following code:
[0086]
[0087]
[0088]
[0089] Figure 5A-5D This is a schematic diagram of the effect of network request processing, where Figure 5A In the example, it indicates that there is no network request processing. Figure 5B It shows that there are 6 network requests in progress. Figure 5C In the figure, 6 network requests have been completed and 6 network requests are in progress. Figure 5D It shows that 12 network requests have been executed and 6 network requests are being executed. It can be seen that the maximum concurrent request volume is 6, and the maximum number of network requests being executed at the same time is 6.
[0090] In this way, the code can effectively manage concurrent requests and ensure that at most 6 network requests are being executed at the same time. Whenever a network request is completed, it will immediately try to start a new network request, thereby maximizing the use of concurrency and improving overall performance and response speed. This mechanism not only ensures efficient processing of network requests, but also avoids exceeding the maximum concurrency limit of the browser.
[0091] Figure 6 A structural block diagram of a network request processing device according to an embodiment of the present application is shown. Figure 6 As shown, the device comprises:
[0092] Insertion module 601, adapted to obtain a network request, insert the network request into a request pool queue, and trigger the execution of a judgment module;
[0093] The judgment module 602 is adapted to judge whether the number of network requests in the execution phase is less than the preset maximum concurrent request amount and whether there are unexecuted network requests in the request pool queue; if so, the processing module is triggered to execute; if the number of network requests in the execution phase is greater than or equal to the preset maximum concurrent request amount, the update module is triggered to execute; if there are no unexecuted network requests in the request pool queue, the process ends;
[0094] The processing module 603 is adapted to dequeue and execute the network requests in the request pool queue, and update the number of network requests in the execution phase according to the number of dequeued network requests;
[0095] The updating module 604 is adapted to wait for the network requests to be executed, update the number of network requests in the execution phase according to the number of network requests that have been executed, and trigger the execution of the judgment module.
[0096] Optionally, the update module is further adapted to: if any network request in the execution phase is completed, then the number of network requests in the execution phase is reduced by 1.
[0097] Optionally, the processing module is further adapted to: dequeue and execute the network request first inserted into the request pool queue each time in a first-in-first-out manner.
[0098] Optionally, the processing module is further adapted to: increase the number of network requests in the execution phase by 1.
[0099] Optionally, the device further comprises: a determination module adapted to determine the maximum number of concurrent requests according to browser kernel information.
[0100] Optionally, the insertion module is further adapted to: sort the network requests based on request time, insert the network requests into the request pool queue in sequence according to the sorting result, and record the request insertion time.
[0101] The description of each module above refers to the corresponding description in the method embodiment and will not be repeated here.
[0102] According to the network request processing device provided by the embodiment of the present application, by comparing the network request data in the execution stage with the preset maximum concurrent request amount, it is possible to effectively control the number of concurrent requests to avoid exceeding the browser limit, thereby avoiding the request being blocked, and also ensuring maximum resource utilization and avoiding idle resources. The network requests in the execution stage are not in order, and the asynchronous callback is made according to the first completed first. Even if some network requests are initiated earlier but completed later, the start execution of other network requests will not be blocked. In addition, after each network request is completed, the next network request is processed immediately if the above judgment conditions are met, which can effectively prevent the backlog of network requests, thereby improving the overall response speed and ensuring the smooth operation of network request processing.
[0103] An embodiment of the present application provides a non-volatile computer storage medium, which stores at least one executable instruction or computer program, and the executable instruction or computer program can enable a processor to perform operations corresponding to the network request processing method in any of the above method embodiments.
[0104] An embodiment of the present application provides a computer program product, which includes at least one executable instruction or computer program, and the executable instruction or computer program can enable a processor to perform operations corresponding to the network request processing method in any of the above method embodiments.
[0105] Figure 7 A schematic diagram of the structure of an embodiment of a computing device of the present application is shown. The specific embodiment of the present application does not limit the specific implementation of the computing device.
[0106] like Figure 7 As shown, the computing device may include: a processor (processor) 702 , a communication interface (Communications Interface) 704 , a memory (memory) 706 , and a communication bus 708 .
[0107] The processor 702, the communication interface 704, and the memory 706 communicate with each other via a communication bus 708. The communication interface 704 is used to communicate with other devices such as a client or other server network elements. The processor 702 is used to execute a program 710, which can specifically execute the relevant steps in the above-mentioned network request processing method embodiment for a computing device.
[0108] Specifically, the program 710 may include program codes, which include computer operation instructions.
[0109] The processor 702 may be a central processing unit (CPU), or an application-specific integrated circuit (ASIC), or one or more integrated circuits configured to implement the embodiments of the present application. The one or more processors included in the computing device may be processors of the same type, such as one or more CPUs; or may be processors of different types, such as one or more CPUs and one or more ASICs.
[0110] The memory 706 is used to store the program 710. The memory 706 may include a high-speed RAM memory, and may also include a non-volatile memory (non-volatile memory), such as at least one disk memory.
[0111] The program 710 can be specifically used to enable the processor 702 to execute the network request processing method in any of the above-mentioned method embodiments. The specific implementation of each step in the program 710 can refer to the corresponding descriptions in the corresponding steps and units in the above-mentioned network request processing embodiment, which will not be repeated here. Those skilled in the art can clearly understand that for the convenience and simplicity of description, the specific working process of the above-described devices and modules can refer to the corresponding process description in the above-mentioned method embodiment, which will not be repeated here.
[0112] The algorithm and display provided herein are not inherently related to any specific computer, virtual system or other equipment. Various general purpose systems can also be used together with the teachings based on this. According to the above description, it is obvious to construct the structure required for this type of system. In addition, the present application embodiment is not directed to any specific programming language yet. It should be understood that various programming languages can be utilized to realize the content of the present application embodiment described herein, and the above description of specific languages is to disclose the best mode of implementation of the present application embodiment.
[0113] In the description provided herein, a large number of specific details are described. However, it is understood that the embodiments of the present application can be practiced without these specific details. In some instances, well-known methods, structures and techniques are not shown in detail so as not to obscure the understanding of this description.
[0114] Similarly, it should be understood that in order to streamline the present disclosure and help understand one or more of the various inventive aspects, in the above description of the exemplary embodiments of the present application, the various features of the embodiments of the present application are sometimes grouped together into a single embodiment, figure, or description thereof. However, the disclosed method should not be interpreted as reflecting the following intention: the claimed embodiments of the present application require more features than the features clearly stated in each claim. More specifically, as reflected in the claims below, the inventive aspects are less than all the features of the single embodiment disclosed above. Therefore, the claims following the specific embodiment are hereby explicitly incorporated into the specific embodiment, wherein each claim itself serves as a separate embodiment of the embodiment of the present application.
[0115] Those skilled in the art will appreciate that the modules in the devices in the embodiments may be adaptively changed and arranged in one or more devices different from the embodiments. The modules or units or components in the embodiments may be combined into one module or unit or component, and in addition they may be divided into a plurality of submodules or subunits or subcomponents. Except that at least some of such features and / or processes or units are mutually exclusive, all features disclosed in this specification (including the accompanying claims, abstracts and drawings) and all processes or units of any method or device disclosed in this manner may be combined in any combination. Unless otherwise expressly stated, each feature disclosed in this specification (including the accompanying claims, abstracts and drawings) may be replaced by an alternative feature providing the same, equivalent or similar purpose.
[0116] In addition, those skilled in the art will appreciate that, although some embodiments described herein include certain features included in other embodiments but not other features, the combination of features of different embodiments is meant to be within the scope of the embodiments of the present application and to form different embodiments. For example, in the claims below, any one of the claimed embodiments may be used in any combination.
[0117] The various component embodiments of the embodiments of the present application can be implemented in hardware, or in software modules running on one or more processors, or in a combination thereof. It should be understood by those skilled in the art that a microprocessor or digital signal processor (DSP) can be used in practice to implement some or all functions of some or all components according to the embodiments of the present application. The embodiments of the present application can also be implemented as a device or apparatus program (e.g., computer program and computer program product) for executing part or all of the methods described herein. Such a program implementing the embodiments of the present application can be stored on a computer-readable medium, or can have the form of one or more signals. Such a signal can be downloaded from an Internet website, or provided on a carrier signal, or provided in any other form.
[0118] It should be noted that the above embodiments illustrate rather than limit the embodiments of the present application, and that those skilled in the art may design alternative embodiments without departing from the scope of the appended claims. In the claims, any reference symbol between brackets should not be constructed as a limitation to the claims. The word "comprising" does not exclude the presence of elements or steps not listed in the claims. The word "one" or "an" preceding an element does not exclude the presence of multiple such elements. The embodiments of the present application may be implemented by means of hardware including several different elements and by means of appropriately programmed computers. In a unit claim that lists several devices, several of these devices may be embodied by the same hardware item. The use of the words first, second, and third, etc. does not indicate any order. These words may be interpreted as names.
Claims
1. A network request processing method, comprising: S1, obtain a network request, insert the network request into the request pool queue, and jump to execute S2; S2, determining whether the number of network requests in the execution phase is less than the preset maximum concurrent request amount and whether there are unexecuted network requests in the request pool queue; If yes, execute S3; If the number of network requests in the execution phase is greater than or equal to the preset maximum concurrent request amount, S4 is executed; if there are no unexecuted network requests in the request pool queue, the method ends; S3, dequeueing and executing the network requests in the request pool queue, and updating the number of network requests in the execution phase according to the number of dequeued network requests; S4, wait for the network request to be executed, update the number of network requests in the execution phase according to the number of completed network requests, and jump to execute S2.
2. The method according to claim 1, wherein: The step of waiting for the network requests to be executed and updating the number of network requests in the execution phase according to the number of network requests that have been executed further includes: If any network request in the execution phase is completed, the number of network requests in the execution phase will be reduced by 1.
3. The method according to claim 1 or 2, wherein: The dequeuing and executing of the network request in the request pool queue further comprises: In a first-in-first-out manner, the network request that is first inserted into the request pool queue is dequeued and executed each time.
4. The method according to claim 3, wherein: The updating of the number of network requests in the execution phase according to the number of dequeued network requests further includes: increasing the number of network requests in the execution phase by 1.
5. The method according to any one of claims 1 to 4, wherein: The method also includes: determining a maximum number of concurrent requests according to browser kernel information.
6. The method according to any one of claims 1 to 5, wherein: The inserting the network request into the request pool queue further comprises: Sort network requests based on request time, insert network requests into the request pool queue in sequence according to the sorting results, and record the request insertion time.
7. A network request processing device, comprising: An insertion module, adapted to obtain a network request, insert the network request into a request pool queue, and trigger the execution of a judgment module; A judgment module is adapted to judge whether the number of network requests in the execution phase is less than a preset maximum concurrent request amount and whether there are unexecuted network requests in the request pool queue; if so, triggering the processing module to execute; If the number of network requests in the execution phase is greater than or equal to the preset maximum concurrent request amount, the update module is triggered to execute; if there are no unexecuted network requests in the request pool queue, the process ends; A processing module, adapted to dequeue and execute network requests in the request pool queue, and update the number of network requests in the execution phase according to the number of dequeued network requests; The updating module is adapted to wait for the network requests to be executed, update the number of network requests in the execution phase according to the number of network requests that have been executed, and trigger the execution of the judging module.
8. A computing device comprising: A processor, a memory, a communication interface and a communication bus, wherein the processor, the memory and the communication interface communicate with each other via the communication bus; The memory is used to store at least one executable instruction, and the executable instruction enables the processor to perform an operation corresponding to the network request processing method according to any one of claims 1-6.
9. A computer storage medium, wherein at least one executable instruction is stored in the storage medium, and the executable instruction enables a processor to execute an operation corresponding to the network request processing method as described in any one of claims 1-6.
10. A computer program product, comprising at least one executable instruction, wherein the executable instruction enables a processor to execute operations corresponding to the network request processing method according to any one of claims 1 to 6.