Interface control request processing method and device
By using connection pooling and waiting queue mechanisms, pre-created browser connections are directly used to handle interface control requests, solving the problem of system resource limitations and achieving more efficient concurrent processing and improved stability.
Patent Information
- Application Number
- CN202110821091.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-07-20
- Publication Date
- 2026-11-24
- Estimated Expiration
- 2041-07-20
AI Technical Summary
In existing technologies, electronic devices have limited system resources, resulting in a limited number of interface control requests that can be processed concurrently in a short period of time. Furthermore, anomalies may occur during the browser creation process, affecting the stability of the service.
By maintaining a connection pool and utilizing pre-created browser connections, the connection processing interface can be directly invoked to control requests, avoiding the need to create browsers temporarily. This, combined with a waiting queue and temporary connection mechanism, optimizes the request processing flow.
This increases the number of interface control requests that electronic devices can process concurrently in a short period of time, reduces service interruptions caused by browser creation errors, and improves system stability and processing capabilities.
Smart Images

Figure CN113553525B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of intelligent analysis technology, and in particular to a method and apparatus for processing interface control requests. Background Technology
[0002] Some interface control services can provide services that control the interface according to specific control methods. For example, taking the Puppeteer service (a service for managing browser interfaces) as an example, users can open any webpage in a specific interface through the Puppeteer service, and they can also click any control in a specific interface through the Puppeteer service.
[0003] The implementation of the interface control service depends on the browser. In related technologies, the interface control service that provides the interface control service creates the browser required for the interface control service request after receiving the interface control service request, processes the interface control service request using the created resources, and releases the created browser after completing the processing of the interface control service request.
[0004] However, creating a browser consumes system resources, while the system resources of electronic devices providing interface control services are limited. Therefore, the number of interface control service requests that can be processed in a short period of time is limited. In other words, due to the system resources consumed in creating the browser, the number of interface control requests that electronic devices providing interface control services can concurrently process is limited. Therefore, how to effectively increase the number of interface control requests that can be processed concurrently has become an urgent technical problem to be solved. Summary of the Invention
[0005] The purpose of this invention is to provide a method and apparatus for processing interface control requests, so as to improve the ability of electronic devices to process requests concurrently. The specific technical solution is as follows:
[0006] In a first aspect of the present invention, a method for processing interface control requests is provided, the method comprising:
[0007] After receiving the target interface control request, an idle connection is selected from the connection pool as the target connection. The connection pool maintains multiple connections, and different connections are used to connect to pre-created browsers, and different connections connect to different browsers.
[0008] The target browser connected to the target connection is controlled to load the target interface for the target interface control request.
[0009] Through the target connection, the target browser is controlled to control the target interface according to the target interface control method, wherein the target interface control method is the interface control method requested by the target interface control request.
[0010] In one possible embodiment, before selecting an idle connection from the connection pool as the target connection, the method further includes:
[0011] Obtain the interface control request;
[0012] Determine whether the number of requested connections is less than the preset number of persistent connections, wherein the number of requested connections is the number of connections currently used to process interface control requests, and the number of connections initially maintained by the connection pool is equal to the number of persistent connections;
[0013] If the number of requested connections is less than the number of persistent connections, the obtained interface control request is taken as the target interface control request, and the step of selecting an idle connection from the connection pool as the target connection is executed.
[0014] In one possible embodiment, after determining whether the number of requested connections is less than a preset number of persistent connections, the method further includes:
[0015] If the number of requested connections is not less than the number of persistent connections, the obtained interface control requests will be added to the waiting queue.
[0016] Whenever the number of requested connections is less than the number of resident connections and the waiting queue contains requests, the interface control request in the waiting queue is taken as the target interface control request, and the step of selecting an idle connection from the connection pool as the target connection is executed.
[0017] In one possible embodiment, before adding the acquired interface control request to the waiting queue, the method further includes:
[0018] Determine whether the number of interface control requests included in the waiting queue has reached a preset threshold.
[0019] If the number of interface control requests included in the waiting queue does not reach the preset threshold, the step of adding the acquired interface control requests to the waiting queue is executed.
[0020] In one possible embodiment, after determining whether the number of interface control requests included in the waiting queue reaches a preset threshold, the method further includes:
[0021] If the number of interface control requests included in the waiting queue reaches the preset number threshold, the obtained interface control requests are processed according to the preset rejection policy.
[0022] In one possible embodiment, before processing the obtained interface control request according to a preset rejection policy, the method further includes:
[0023] Determine whether the number of requested connections is less than the maximum number of connections, wherein the maximum number of connections is greater than the number of persistent connections;
[0024] If the number of requested connections is not less than the maximum number of connections, the step of processing the obtained interface control requests according to the preset rejection policy is executed.
[0025] In one possible embodiment, after determining whether the number of requested connections is less than the maximum number of connections, the method further includes:
[0026] If the number of requested connections is less than the maximum number of connections, a temporary connection is created in the connection pool. The temporary connection is used to connect to the temporarily created browser.
[0027] The obtained interface control request is taken as the target interface control request, and the temporary connection is taken as the target connection. The steps of controlling the target browser connected to the target connection to load the target interface targeted by the target interface control request are executed.
[0028] After controlling the target browser to control the target interface according to the target interface control method through the target connection, the method further includes:
[0029] Cancel the temporary connection in the connection pool.
[0030] In a second aspect of the present invention, an interface control request processing apparatus is also provided, the apparatus comprising:
[0031] The connection selection module is used to select an idle connection from the connection pool as the target connection after obtaining the target interface control request. The connection pool maintains multiple connections, and different connections are used to connect to pre-created browsers, and different connections connect to different browsers.
[0032] The first control module is used to control the target browser connected to the target connection to load the target interface for which the target interface control request is directed.
[0033] The second control module is used to control the target browser to control the target interface according to the target interface control method through the target connection, wherein the target interface control method is the interface control method requested by the target interface control request.
[0034] In one possible embodiment, the apparatus further includes a request acquisition module for acquiring interface control requests;
[0035] The first judgment module is used to determine whether the number of requested connections is less than the preset number of resident connections, wherein the number of requested connections is the number of connections currently used to process interface control requests, and the number of connections maintained by the connection pool at the beginning is equal to the number of resident connections.
[0036] If the number of requested connections is less than the number of resident connections, the obtained interface control request is taken as the target interface control request, and the connection selection module is driven to perform the step of selecting an idle connection from the connection pool as the target connection.
[0037] In one possible embodiment, the first determining module is further configured to add the obtained interface control request to the waiting queue if the number of requested connections is not less than the number of persistent connections;
[0038] Whenever the number of requested connections is less than the number of resident connections and the waiting queue contains requests, the interface control request in the waiting queue is taken as the target interface control request, and the connection selection module is driven to perform the step of selecting an idle connection from the connection pool as the target connection.
[0039] In one possible embodiment, the device further includes a second judgment module for judging whether the number of interface control requests included in the waiting queue reaches a preset number threshold.
[0040] If the number of interface control requests included in the waiting queue does not reach the preset threshold, the first judgment module is driven to perform the step of adding the acquired interface control requests to the waiting queue.
[0041] In one possible embodiment, the second judgment module is further configured to process the obtained interface control requests according to a preset rejection policy if the number of interface control requests included in the waiting queue reaches the preset number threshold.
[0042] In one possible embodiment, the device further includes a third determining module, used to determine whether the number of requested connections is less than the maximum number of connections, wherein the maximum number of connections is greater than the number of resident connections;
[0043] If the number of requested connections is not less than the maximum number of connections, the second judgment module is driven to execute the step of processing the obtained interface control requests according to the preset rejection policy.
[0044] In one possible embodiment, the third determining module is further configured to create a temporary connection in the connection pool if the number of requested connections is less than the maximum number of connections, and the temporary connection is used to connect to the temporarily created browser;
[0045] The obtained interface control request is taken as the target interface control request, and the temporary connection is taken as the target connection. The first control module is driven to execute the step of controlling the target browser connected to the target connection to load the target interface targeted by the target interface control request.
[0046] The connection cancellation module is used to cancel the temporary connection in the connection pool after the target browser is controlled to control the target interface according to the target interface control method through the target connection.
[0047] In another aspect of the present invention, a computer-readable storage medium is also provided, wherein a computer program is stored therein, and when the computer program is executed by a processor, it implements any of the interface control request processing methods described above.
[0048] In another aspect of the present invention, a computer program product containing instructions is also provided, which, when run on a computer, causes the computer to execute any of the interface control request processing methods described above.
[0049] The interface control request processing method and apparatus provided in this invention can maintain multiple connections through a connection pool, with each connection connected to a pre-created browser. This allows the browser to be called directly when an interface control request needs to be processed, without the need to create a new browser temporarily. In other words, no browser needs to be created during the processing of interface control requests. Therefore, the number of interface control requests that can be processed concurrently is not limited by the number of browsers that can be created within a certain time period, which can effectively increase the number of interface control requests that can be processed concurrently. Attached Figure Description
[0050] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the accompanying drawings used in the description of the embodiments or the prior art will be briefly introduced below.
[0051] Figure 1 This is a flowchart illustrating a method for handling interface control requests in an embodiment of the present invention.
[0052] Figure 2 This is a schematic diagram of another interface control request processing method in an embodiment of the present invention;
[0053] Figure 3 This is a schematic diagram of another interface control request processing method in an embodiment of the present invention;
[0054] Figure 4 This is a schematic diagram of another interface control request processing method in an embodiment of the present invention;
[0055] Figure 5a This is a schematic diagram of a structure of the interface control request processing device in an embodiment of the present invention;
[0056] Figure 5b This is a schematic diagram of another structure of the interface control request processing device in an embodiment of the present invention;
[0057] Figure 5c This is a schematic diagram of another structure of the interface control request processing device in an embodiment of the present invention;
[0058] Figure 5d This is a schematic diagram of another structure of the interface control request processing device in an embodiment of the present invention;
[0059] Figure 6 This is a schematic diagram of the structure of an electronic device according to an embodiment of the present invention. Detailed Implementation
[0060] The technical solutions of the present invention will now be described with reference to the accompanying drawings in the embodiments of the present invention.
[0061] To more clearly illustrate the interface control request processing method provided in the embodiments of the present invention, a possible embodiment of the request method provided in the embodiments of the present invention will be described below by way of example. It should be understood that the following example is only one possible application scenario of the interface control request processing method provided in the embodiments of the present invention. In other possible embodiments, the interface control request processing method provided in the embodiments of the present invention can also be applied to other possible application scenarios. This embodiment does not impose any restrictions on this.
[0062] For practical needs, users may need to control the interface, such as drawing images or posters, adding or deleting text. In related technologies, users can achieve this control through the Puppeteer service. The Puppeteer service process can be summarized as follows:
[0063] Step 1: Create a browser and its tabs using the Puppeteer service.
[0064] Step 2: The Puppeteer service program calls the Puppeteer service to control the interface through the created browser and tabs.
[0065] Step 3: Log out of the browser and tabs you created.
[0066] On the one hand, creating browsers and tabs consumes system resources, and the system resources available for electronic devices providing Puppeteer services are limited. Therefore, the number of browsers and tabs that can be created within a certain time period is limited, resulting in a limited number of Puppeteer requests that the electronic device can process within that time period. In other words, due to the limitation of the number of browsers and tabs that can be created, the number of Puppeteer requests that an electronic device can process concurrently is limited.
[0067] On the other hand, exceptions may occur during the creation of browsers and tabs. Since the Puppeteer service is configured to terminate after all Puppeteer requests have been processed, an exception might cause the service to terminate before completion, preventing it from shutting down properly. In other words, an exception during browser and tab creation could prevent the Puppeteer service from functioning correctly.
[0068] Based on this, embodiments of the present invention provide an interface control request processing method, which can be applied to any electronic device with interface control request processing capabilities, and the method can be as follows: Figure 1 As shown, it includes:
[0069] S101, after obtaining the target interface control request, select an idle connection from the connection pool as the target connection.
[0070] S102, Control the target browser connected to the target connection to load the target interface control request for the target interface.
[0071] S103, through the target connection, controls the target browser to control the target interface according to the target interface control method.
[0072] By using this embodiment, multiple connections can be maintained through a connection pool, with each connection connected to a pre-created browser. This allows the browser to be invoked directly when a UI control request needs to be processed, without the need to create a new browser temporarily. In other words, no browser needs to be created during the processing of UI control requests. Therefore, the number of UI control requests that can be processed concurrently is not limited by the number of browsers that can be created within a certain time period, which can effectively increase the number of UI control requests that can be processed concurrently.
[0073] On the other hand, since this embodiment does not require creating a corresponding browser and tab for each interface control request, the interface control service will not malfunction due to abnormal browser and tab creation during the processing of interface control requests.
[0074] In S101, the type of target interface control request can vary depending on the application scenario. The Puppeteer request shown in the previous example is only one possible target interface control request. In other possible embodiments, the target interface control request can also be other types of interface control requests.
[0075] The connection pool maintains multiple connections, each used to connect to a pre-created browser. Different connections connect to different browsers. Since the types of UI control requests may differ in different application scenarios, and the resources required to implement different types of UI control requests may vary, connections can be used to connect to other resources, such as tabs, in addition to browsers.
[0076] An idle connection is a connection that is not being used to process any interface control requests. When there is only one idle connection in the connection pool, that idle connection can be used as the target connection. When there are multiple idle connections in the connection pool, one idle connection can be randomly selected from among the multiple idle connections as the target connection, or an idle connection can be selected from among the multiple idle connections according to a preset rule.
[0077] The preset rules can be set according to actual needs and / or user experience. For example, the highest priority connection can be selected as the target connection in ascending order (or descending order) of preset connection numbers, or the highest priority connection can be selected as the target connection in descending order of preset priority. This embodiment does not impose any restrictions on this.
[0078] In S102, the target interface for the target interface control request can be one interface or multiple interfaces; this embodiment of the invention does not impose any restrictions on this. The interface targeted by the interface control request can refer to the interface that the interface control request requests to control.
[0079] In S103, the target interface control method is the interface control method requested by the target interface control request. For example, it can be opening any page, clicking any control in the target interface, reading specified content in the target interface, etc. This embodiment of the invention does not impose any restrictions on this.
[0080] It can be achieved by sending control instructions, which indicate the target interface control method, to the target browser through the target connection, so that the target browser executes the control instructions and controls the target interface according to the target interface control method.
[0081] Since the target browser has the target interface loaded, the target interface can be indirectly controlled by controlling the target browser through the target connection, thereby realizing the target interface control request.
[0082] It is understandable that if there are no idle connections in the connection pool, the aforementioned S102 cannot be executed, resulting in the loss of the interface control request. Therefore, in one possible embodiment, it can be done as follows: Figure 2 As shown:
[0083] S201, Get UI control request.
[0084] S202, determine whether the number of requested connections is less than the preset number of resident connections. If the number of requested connections is less than the number of resident connections, execute S204. If the number of requested connections is not less than the number of resident connections, execute S203.
[0085] The number of requested connections is the number of connections currently used to process interface control requests. It can be a pre-maintained counter, which is initially 0. Whenever the control service program processes an interface control request through a connection, the counter is incremented by one, and whenever an interface control request is completed, the counter is decremented by one. In this embodiment, the count of the counter is the number of requested connections.
[0086] The number of persistent connections can be a value preset based on actual needs and / or user experience. The number of connections maintained by the connection pool at the beginning is equal to the number of persistent connections. If each connection is used to connect to one browser (in other possible embodiments, one connection can also be used to connect to multiple browsers), then correspondingly, several browsers with persistent connections can be created in advance, and each browser with persistent connections can be connected to the browsers with persistent connections. A connection pool is created based on the number of persistent connections to maintain the number of persistent connections.
[0087] S203, add the obtained interface control request to the waiting queue.
[0088] In theory, UI control requests added to the waiting queue will not be processed immediately. Instead, they will be processed only after the number of requesting connections decreases to less than the number of persistent connections.
[0089] For example, whenever the number of requested connections is less than the number of persistent connections and the waiting queue includes UI control requests, the UI control requests in the waiting queue are used as the target UI control requests, and processed in accordance with the aforementioned processing method for target UI control requests.
[0090] The selected interface control request can be any request in the waiting queue, or a request selected from the waiting queue according to preset rules. For example, the selected interface control request can be the earliest (or latest) interface control request added to the waiting queue, the interface control request with the highest (or lowest) priority in the waiting queue, or a randomly selected interface control request in the waiting queue.
[0091] Once the target interface control request has been processed, remove it from the service queue.
[0092] S204, Select an idle connection from the connection pool as the target connection.
[0093] This step is the same as S102, and can be found in the relevant description of S102 above, so it will not be repeated here. If the process enters S204 from S202, then when executing S204 and subsequent steps, the interface control request obtained in S201 above will be used as the target interface control request. If the process enters S204 from S203, then when executing S204 and subsequent steps, the interface control request in the waiting queue will be used as the target interface control request.
[0094] S205, Control the target browser connected to the target connection to load the target interface control request for the target interface.
[0095] This step is the same as S102, and can be found in the relevant description of S102 above, so it will not be repeated here.
[0096] S206, through the target connection, control the target browser to control the target interface according to the target interface control method.
[0097] This step is the same as S103, and you can refer to the relevant description of S103 above, so it will not be repeated here.
[0098] By using this embodiment, the possibility of interface control requests being lost due to the limited number of connections maintained by the connection pool can be reduced by setting up a waiting queue.
[0099] The maximum number of UI control requests that the waiting queue can hold can be set according to actual needs and / or user experience. The set value can vary depending on the application scenario. For example, the maximum value can be set according to the importance of the service implemented by the UI control request, or it can be set according to the frequency of received UI control requests, with the maximum value being positively correlated with the frequency. This frequency can be estimated or measured. When the number of requests in the waiting queue has reached its maximum, no more requests can be added to the waiting queue. In one possible embodiment, it can be as follows: Figure 3As shown, Figure 3 The diagram shown is another flowchart of the interface control request processing method provided in an embodiment of the present invention, which may include:
[0100] S301, Get interface control request.
[0101] S302, determine whether the number of requested connections is less than the preset number of resident connections. If the number of requested connections is less than the number of resident connections, execute S306. If the number of requested connections is not less than the number of resident connections, execute S303.
[0102] This step is the same as S202 mentioned above, and can be found in the relevant description of S202 mentioned above, so it will not be repeated here.
[0103] S303, determine whether the number of interface control requests included in the waiting queue has reached a preset threshold. If the number of interface control requests included in the waiting queue has reached the preset threshold, then execute S305. If the number of interface control requests included in the waiting queue has not reached the preset threshold, then execute S304.
[0104] The preset number threshold should be less than or equal to the maximum number of interface control requests that the waiting queue can accommodate.
[0105] S304, add the obtained interface control request to the waiting queue.
[0106] This step is the same as S203 above, and you can refer to the relevant description of S203 above, so it will not be repeated here.
[0107] S305, process the obtained interface control request according to the preset rejection policy.
[0108] Preset rejection policies include, but are not limited to, releasing the acquired UI control requests, saving the acquired UI control requests but refusing to execute them, etc.
[0109] Understandably, when the number of UI control requests in the waiting queue reaches a preset threshold, it can be assumed that no more UI control requests can be added to the waiting queue. Since there are no idle connections in the connection pool at this time, the UI control request cannot be processed immediately and can therefore be rejected.
[0110] S306, Select an idle connection from the connection pool as the target connection.
[0111] This step is the same as S102, and can be found in the relevant description of S102 above, so it will not be repeated here. If the process enters S306 from S302, then when executing S306 and subsequent steps, the interface control request obtained in S301 above will be used as the target interface control request. If the process enters S306 from S304, then when executing S306 and subsequent steps, the interface control request in the waiting queue will be used as the target interface control request.
[0112] S307, Control the target browser connected to the target connection to load the target interface control request for the target interface.
[0113] This step is the same as S102, and can be found in the relevant description of S102 above, so it will not be repeated here.
[0114] S308, through the target connection, controls the target browser to control the target interface according to the target interface control method.
[0115] This step is the same as S103, and you can refer to the relevant description of S103 above, so it will not be repeated here.
[0116] In another possible embodiment, to address the situation where the number of interface control requests in the waiting queue has reached its maximum value and no more interface control requests can be added to the waiting queue, it can also be done as follows: Figure 4 As shown, Figure 4 The diagram shown is another flowchart of the interface control request processing method provided in an embodiment of the present invention, which may include:
[0117] S401, Get UI control request.
[0118] S402, determine whether the number of requested connections is less than the preset number of resident connections. If the number of requested connections is less than the number of resident connections, execute S409. If the number of requested connections is not less than the number of resident connections, execute S403.
[0119] This step is the same as S202 mentioned above, and can be found in the relevant description of S202 mentioned above, so it will not be repeated here.
[0120] S403, determine whether the number of interface control requests included in the waiting queue has reached a preset threshold. If the number of interface control requests included in the waiting queue has reached the preset threshold, then execute S405. If the number of interface control requests included in the waiting queue has not reached the preset threshold, then execute S404.
[0121] This step is the same as S303, and you can refer to the relevant description of S303 above, so it will not be repeated here.
[0122] S404: Add the obtained interface control request to the waiting queue.
[0123] This step is the same as S203 above, and you can refer to the relevant description of S203 above, so it will not be repeated here.
[0124] S405, determine if the number of requested connections is less than the maximum number of connections. If the number of requested connections is less than the maximum number of connections, then execute S407. If the number of requested connections is not less than the maximum number of connections, then execute S406.
[0125] The maximum number of connections can be a value preset based on actual needs and / or user experience, and the maximum number of connections should be greater than the number of persistent connections.
[0126] S406, process the obtained interface control request according to the preset rejection policy.
[0127] Understandably, if the number of requested connections is not less than the maximum number of connections, it can be assumed that the connection pool not only has no idle connections, but also that the connection pool's load has reached or is close to its maximum capacity due to the large number of temporary connections created. In this case, it is impossible to create new temporary connections in the connection pool. Therefore, in this situation, the obtained UI control requests can be rejected.
[0128] S407, Create a temporary connection in the connection pool.
[0129] Temporary connections are used to connect service programs and temporarily created resources. Once a temporary connection is created, it will be deregistered from the connection pool after processing the received UI control request.
[0130] S408: Select an idle connection from the connection pool as the target connection.
[0131] This step is the same as S102, and can be found in the relevant description of S102 above, so it will not be repeated here. If entering S408 from S402, the interface control request obtained in S401 will be used as the target interface control request when executing S408 and subsequent steps. If entering S408 from S404, the interface control request in the waiting queue will be used as the target interface control request when executing S408 and subsequent steps. If entering S408 from S407, the interface control request obtained in S401 will be used as the target interface control request when executing S408 and subsequent steps, and the temporary connection created in S407 will be used as the target connection.
[0132] It's understandable that if the number of requested connections is not less than the number of persistent connections and is less than the maximum number of connections, then even though there are no idle connections in the current connection pool, the connection pool can maintain more connections in a short period of time. Therefore, temporary connections can be created and used to process the obtained UI control requests. Since temporary connections will be cancelled after the target request is processed, this will only increase the load on the connection pool in a short period of time and will not affect the normal operation of the connection pool.
[0133] S409, Control the target browser connected to the target connection to load the target interface control request for the target interface.
[0134] This step is the same as S102, and can be found in the relevant description of S102 above, so it will not be repeated here.
[0135] S410, through the target connection, controls the target browser to control the target interface according to the target interface control method.
[0136] This step is the same as S103, and you can refer to the relevant description of S103 above, so it will not be repeated here.
[0137] By using this embodiment, the load on the connection pool can be temporarily increased when the waiting queue can no longer add interface control requests, so as to avoid the obtained interface control requests being unable to be fulfilled.
[0138] See Figure 5a , Figure 5a The diagram shown is a structural schematic of an interface control request processing device provided in an embodiment of the present invention, which may include:
[0139] The connection selection module 501 is used to select an idle connection from the connection pool as the target connection after obtaining the target interface control request. The connection pool maintains multiple connections, and different connections are used to connect to pre-created browsers, and different connections connect to different browsers.
[0140] The first control module 502 is used to control the target browser connected to the target connection to load the target interface targeted by the target interface control request.
[0141] The second control module 503 is used to control the target browser to control the target interface according to the target interface control method through the target connection, wherein the target interface control method is the interface control method requested by the target interface control request.
[0142] In one possible embodiment, such as Figure 5b As shown, the device further includes a request acquisition module 504, used to acquire interface control requests;
[0143] The first judgment module 505 is used to determine whether the number of requested connections is less than the preset number of resident connections, wherein the number of requested connections is the number of connections currently used to process interface control requests, and the number of connections maintained by the connection pool at the beginning is equal to the number of resident connections.
[0144] If the number of requested connections is less than the number of resident connections, the obtained interface control request is taken as the target interface control request, and the connection selection module 501 is driven to perform the step of selecting an idle connection from the connection pool as the target connection.
[0145] In one possible embodiment, the first determining module 505 is further configured to add the obtained interface control request to the waiting queue if the number of requested connections is not less than the number of persistent connections.
[0146] Whenever the number of requested connections is less than the number of resident connections and the waiting queue contains requests, the connection selection module 501 is driven to perform the step of selecting an idle connection from the connection pool as the target connection, with the interface control request in the waiting queue as the target interface control request.
[0147] In one possible embodiment, such as Figure 5c As shown, the device also includes a second judgment module 506, used to judge whether the number of interface control requests included in the waiting queue has reached a preset number threshold.
[0148] If the number of interface control requests included in the waiting queue does not reach the preset number threshold, the first judgment module 505 is driven to perform the step of adding the acquired interface control requests to the waiting queue.
[0149] In one possible embodiment, the second judgment module 506 is further configured to process the obtained interface control requests according to a preset rejection policy if the number of interface control requests included in the waiting queue reaches the preset number threshold.
[0150] In one possible embodiment, such as Figure 5d As shown, the device further includes a third judgment module 507, used to determine whether the number of requested connections is less than the maximum number of connections, wherein the maximum number of connections is greater than the number of resident connections;
[0151] If the number of requested connections is not less than the maximum number of connections, the second judgment module 506 is driven to execute the step of processing the obtained interface control requests according to the preset rejection policy.
[0152] In one possible embodiment, the third determination module 507 is further configured to create a temporary connection in the connection pool if the number of requested connections is less than the maximum number of connections, and the temporary connection is used to connect to the temporarily created browser;
[0153] The obtained interface control request is taken as the target interface control request, and the temporary connection is taken as the target connection. The first control module 502 is driven to execute the step of controlling the target browser connected to the target connection to load the target interface targeted by the target interface control request.
[0154] The connection cancellation module 508 is used to cancel the temporary connection in the connection pool after the target browser is controlled to control the target interface according to the target interface control method through the target connection.
[0155] This invention also provides an electronic device, such as... Figure 6 As shown, it includes a processor 601, a communication interface 602, a memory 603, and a communication bus 604, wherein the processor 601, the communication interface 602, and the memory 603 communicate with each other through the communication bus 604.
[0156] Memory 603 is used to store computer programs;
[0157] When processor 601 executes a program stored in memory 603, it performs the following steps:
[0158] After receiving the target interface control request, an idle connection is selected from the connection pool as the target connection. The connection pool maintains multiple connections, and different connections are used to connect to pre-created browsers, and different connections connect to different browsers.
[0159] The target browser connected to the target connection is controlled to load the target interface for the target interface control request.
[0160] Through the target connection, the target browser is controlled to control the target interface according to the target interface control method, wherein the target interface control method is the interface control method requested by the target interface control request.
[0161] In one possible embodiment, before selecting an idle connection from the connection pool as the target connection, the method further includes:
[0162] Obtain the interface control request;
[0163] Determine whether the number of requested connections is less than the preset number of persistent connections, wherein the number of requested connections is the number of connections currently used to process interface control requests, and the number of connections initially maintained by the connection pool is equal to the number of persistent connections;
[0164] If the number of requested connections is less than the number of persistent connections, the obtained interface control request is taken as the target interface control request, and the step of selecting an idle connection from the connection pool as the target connection is executed.
[0165] In one possible embodiment, after determining whether the number of requested connections is less than a preset number of persistent connections, the method further includes:
[0166] If the number of requested connections is not less than the number of persistent connections, the obtained interface control requests will be added to the waiting queue.
[0167] Whenever the number of requested connections is less than the number of resident connections and the waiting queue contains requests, the interface control request in the waiting queue is taken as the target interface control request, and the step of selecting an idle connection from the connection pool as the target connection is executed.
[0168] In one possible embodiment, before adding the acquired interface control request to the waiting queue, the method further includes:
[0169] Determine whether the number of interface control requests included in the waiting queue has reached a preset threshold.
[0170] If the number of interface control requests included in the waiting queue does not reach the preset threshold, the step of adding the acquired interface control requests to the waiting queue is executed.
[0171] In one possible embodiment, after determining whether the number of interface control requests included in the waiting queue reaches a preset threshold, the method further includes:
[0172] If the number of interface control requests included in the waiting queue reaches the preset number threshold, the obtained interface control requests are processed according to the preset rejection policy.
[0173] In one possible embodiment, before processing the obtained interface control request according to a preset rejection policy, the method further includes:
[0174] Determine whether the number of requested connections is less than the maximum number of connections, wherein the maximum number of connections is greater than the number of persistent connections;
[0175] If the number of requested connections is not less than the maximum number of connections, the step of processing the obtained interface control requests according to the preset rejection policy is executed.
[0176] In one possible embodiment, after determining whether the number of requested connections is less than the maximum number of connections, the method further includes:
[0177] If the number of requested connections is less than the maximum number of connections, a temporary connection is created in the connection pool. The temporary connection is used to connect to the temporarily created browser.
[0178] The obtained interface control request is taken as the target interface control request, and the temporary connection is taken as the target connection. The steps of controlling the target browser connected to the target connection to load the target interface targeted by the target interface control request are executed.
[0179] After controlling the target browser to control the target interface according to the target interface control method through the target connection, the method further includes:
[0180] Cancel the temporary connection in the connection pool.
[0181] The communication bus mentioned above can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. This communication bus can be divided into address bus, data bus, control bus, etc. For ease of illustration, only one thick line is used to represent it in the diagram, but this does not mean that there is only one bus or one type of bus.
[0182] The communication interface is used for communication between the aforementioned terminal and other devices.
[0183] The memory may include random access memory (RAM) or non-volatile memory, such as at least one disk storage device. Optionally, the memory may also be at least one storage device located remotely from the aforementioned processor.
[0184] The processors mentioned above can be general-purpose processors, including central processing units (CPUs), network processors (NPs), etc.; they can also be digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components.
[0185] In another embodiment of the present invention, a computer-readable storage medium is also provided, wherein a computer program is stored therein, and when the computer program is executed by a processor, it implements the interface control request processing method described in any of the above embodiments.
[0186] In another embodiment of the present invention, a computer program product containing instructions is also provided, which, when run on a computer, causes the computer to execute any of the interface control request processing methods described in the above embodiments.
[0187] In the above embodiments, implementation can be achieved entirely or partially through software, hardware, firmware, or any combination thereof. When implemented using software, it can be implemented entirely or partially in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, all or part of the processes or functions described in the embodiments of the present invention are generated. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, the computer instructions can be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via wired (e.g., coaxial cable, fiber optic, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that integrates one or more available media. The available medium can be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., solid state disk (SSD)).
[0188] It should be noted that, in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0189] The various embodiments in this specification are described in a related manner. Similar or identical parts between embodiments can be referred to mutually. Each embodiment focuses on describing the differences from other embodiments. In particular, embodiments of devices, electronic devices, computer-readable storage media, and computer program products are basically similar to the method embodiments, and therefore the descriptions are relatively simple; relevant parts can be referred to the descriptions of the method embodiments.
[0190] The above description is merely a preferred embodiment of the present invention and is not intended to limit the scope of protection of the present invention. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention are included within the scope of protection of the present invention.
Claims
1. A method for handling interface control requests, characterized in that, The method includes: After receiving a target interface control request, an idle connection is selected from the connection pool as the target connection. The connection pool maintains multiple connections, and different connections are used to connect to pre-created browsers, and different connections connect to different browsers. The target interface control request is for multiple interfaces. The target interface control request is a Puppeteer request, which is used to control the interface through the Puppeteer service. The target browser connected to the target connection is controlled to load the target interface for the target interface control request. Through the target connection, the target browser is controlled to control the target interface according to the target interface control method, wherein the target interface control method is the interface control method requested by the target interface control request; Before selecting an idle connection from the connection pool as the target connection, the method further includes: Obtain the interface control request; Determine whether the number of requested connections is less than the preset number of persistent connections, wherein the number of requested connections is the number of connections currently used to process interface control requests, and the number of connections initially maintained by the connection pool is equal to the number of persistent connections; If the number of requested connections is less than the number of persistent connections, the obtained interface control request is taken as the target interface control request, and the step of selecting an idle connection from the connection pool as the target connection is executed. After determining whether the number of requested connections is less than the preset number of persistent connections, the method further includes: If the number of requested connections is not less than the number of persistent connections, the obtained interface control requests will be added to the waiting queue. Whenever the number of requested connections is less than the number of persistent connections and the waiting queue contains requests, the interface control request in the waiting queue is taken as the target interface control request, and the step of selecting an idle connection from the connection pool as the target connection is executed. Before adding the acquired interface control request to the waiting queue, the method further includes: The system determines whether the number of UI control requests in the waiting queue reaches a preset threshold. If the number of UI control requests in the waiting queue does not reach the preset threshold, it adds the obtained UI control requests to the waiting queue. If the number of UI control requests in the waiting queue reaches the preset threshold, it determines whether the number of request connections is less than the maximum number of connections, where the maximum number of connections is greater than the number of persistent connections. If the number of request connections is not less than the maximum number of connections, it processes the obtained UI control requests according to a preset rejection policy. If the number of request connections is less than the maximum number of connections, it creates a temporary connection in the connection pool, which is used to connect to a temporarily created browser. The obtained UI control request is taken as the target UI control request, and the temporary connection is taken as the target connection. The system then controls the target browser connected to the target connection to load the target UI control request. After controlling the target browser to control the target interface according to the target interface control method through the target connection, the method further includes: Cancel the temporary connection in the connection pool.
2. A request processing apparatus, characterized in that, The device includes: The connection selection module is used to select an idle connection from the connection pool as the target connection after receiving a target interface control request. The connection pool maintains multiple connections, and different connections are used to connect to pre-created browsers, and different connections connect to different browsers. The target interface control request is for multiple interfaces. The target interface control request is a Puppeteer request, which is used to control the interface through the Puppeteer service. The first control module is used to control the target browser connected to the target connection to load the target interface for which the target interface control request is directed. The second control module is used to control the target browser to control the target interface according to the target interface control method through the target connection, wherein the target interface control method is the interface control method requested by the target interface control request; The device further includes: The request retrieval module is used to retrieve interface control requests; The first judgment module is used to determine whether the number of requested connections is less than the preset number of resident connections, wherein the number of requested connections is the number of connections currently used to process interface control requests, and the number of connections maintained by the connection pool at the beginning is equal to the number of resident connections. If the number of requested connections is less than the number of persistent connections, the obtained interface control request is taken as the target interface control request, and the connection selection module is driven to perform the step of selecting an idle connection from the connection pool as the target connection. The first judgment module is further configured to add the obtained interface control request to the waiting queue if the number of requested connections is not less than the number of persistent connections; Whenever the number of requested connections is less than the number of persistent connections and the waiting queue contains requests, the interface control request in the waiting queue is taken as the target interface control request, and the connection selection module is driven to perform the step of selecting an idle connection from the connection pool as the target connection. The device also includes a module that performs the following operations: Determine whether the number of interface control requests included in the waiting queue reaches a preset threshold; if the number of interface control requests included in the waiting queue does not reach the preset threshold, execute the step of adding the obtained interface control requests to the waiting queue; if the number of interface control requests included in the waiting queue reaches the preset threshold, process the obtained interface control requests according to a preset rejection policy. The device also includes a module that performs the following operations: Determine whether the number of requested connections is less than the maximum number of connections, where the maximum number of connections is greater than the number of persistent connections; if the number of requested connections is not less than the maximum number of connections, execute the step of processing the obtained interface control request according to a preset rejection policy; if the number of requested connections is less than the maximum number of connections, create a temporary connection in the connection pool, where the temporary connection is used to connect to a temporarily created browser; take the obtained interface control request as the target interface control request, and use the temporary connection as the target connection, execute the step of controlling the target browser connected to the target connection to load the target interface targeted by the target interface control request; The device also includes a module that performs the following operations: Cancel the temporary connection in the connection pool.
3. An electronic device, characterized in that, It includes a processor, a communication interface, a memory, and a communication bus, wherein the processor, the communication interface, and the memory communicate with each other through the communication bus; Memory, used to store computer programs; A processor, when executing a program stored in memory, implements the steps of the method of claim 1.
4. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, implements the steps of the method described in claim 1.
Citation Information
Patent Citations
Page loading method, device and equipment and storage medium
CN112364275A
