Detailed Description
The present application will be described in further detail with reference to the following drawings and examples. It is to be understood that the specific embodiments described herein are merely illustrative of the relevant invention and not restrictive of the invention. It should be noted that, for convenience of description, only the portions related to the related invention are shown in the drawings.
It should be noted that the embodiments and features of the embodiments in the present application may be combined with each other without conflict. The present application will be described in detail below with reference to the embodiments with reference to the attached drawings.
Fig. 1 illustrates an exemplary system architecture 100 to which the asynchronous request processing method of the embodiments of the present application may be applied.
As shown in fig. 1, system architecture 100 may include terminal device 101, network 102, and server 103. Network 102 is the medium used to provide communication links between terminal devices 101 and server 103. Network 102 may include various connection types, such as wired, wireless communication links, or fiber optic cables, to name a few.
A user may use terminal device 101 to interact with server 103 over network 102 to receive or send messages and the like. The terminal device 101 may have various communication client applications installed thereon, such as a web browser application, a search-type application, a shopping-type application, an instant messaging tool, and the like.
The terminal device 101 may be various electronic devices including, but not limited to, a mobile terminal such as a mobile phone, a notebook computer, a digital broadcast receiver, a PDA (personal digital assistant), a PAD (tablet computer), a PMP (portable multimedia player), a vehicle-mounted terminal (e.g., a car navigation terminal), etc., and a fixed terminal such as a digital TV, a desktop computer, etc.
The server 103 may be a server that provides various services, such as a background web server that provides support for web pages displayed on the terminal device 101. The background web server may respond to the request sent by the terminal device 101 and feed back a response result (e.g., image, text, video, etc.) to the terminal device 101.
It should be noted that the asynchronous request processing method provided in the embodiment of the present application is generally executed by the terminal device 101, and accordingly, the asynchronous request processing apparatus is generally disposed in the terminal device 101.
It should be understood that the number of terminal devices, networks, servers in fig. 1 is merely illustrative. There may be any number of terminal devices, networks, and servers, as desired for implementation.
With continued reference to FIG. 2, a flow 200 of one embodiment of an asynchronous request handling method according to the present application is shown. The method comprises the following steps:
at step 201, at least one asynchronous request message generated by a current page is received.
In this embodiment, an execution subject (e.g., a terminal device shown in fig. 1) of the asynchronous request processing method may receive at least one piece of asynchronous request information generated from the current page. The current page may be triggered by a user through an operation manner such as clicking or touching, or generated by automatic triggering of the execution main body, and the page may be displayed on a browser. The current page may include a variety of content therein, such as images, text, video, audio, animation, and the like. The content needs to be sent to the server shown in fig. 1 by the browser, and then the server feeds back the corresponding content to the execution main body for display according to each asynchronous request message.
Generally, the Asynchronous request information is generated by Ajax technology, which is "Asynchronous JavaScript and XML" (Asynchronous JavaScript and XML), and is a web page development technology for creating interactive, fast and dynamic web page applications. By exchanging a small amount of data with the server in the background, Ajax can enable the webpage to be updated asynchronously. This means that certain parts of the web page can be updated without reloading the entire web page.
Step 202, storing at least one asynchronous request message into a preset memory queue pool.
In this embodiment, the execution agent may store at least one asynchronous request message into a predetermined memory queue pool. The memory queue pool is used for storing a plurality of asynchronous request messages, and the asynchronous request messages are arranged in a certain sequence. The browser can extract the asynchronous request information from the memory queue pool in sequence for processing.
After the execution of step 202, the execution agent performs the following request extraction steps (including steps 203 to 205).
Step 203, sequentially extracting asynchronous request information from the memory queue pool, and executing the extracted asynchronous request information through the browser.
In this embodiment, the execution body may sequentially extract the asynchronous request information from the memory queue pool, and execute the extracted asynchronous request information through the browser. The browser is arranged on the execution body, and the browser can send asynchronous request information to the server shown in fig. 1, and then receive various contents sent by the server for the asynchronous request information. The browser can sequentially extract the asynchronous request information according to the arrangement sequence of the asynchronous request information in the memory queue pool. The browser can simultaneously extract at least one asynchronous request message for processing.
In some optional implementation manners of this embodiment, the execution main body may extract the asynchronous request information from the memory queue pool based on a preset number of parallel request processing threads. As an example, assuming that the preset number is N, the N parallel request processing threads may extract the asynchronous request information from the memory queue pool in parallel in sequence. And after a certain thread finishes executing an asynchronous request message, continuously extracting the asynchronous request message from the memory queue pool according to the sequence. The realization mode can enable the browser to process a plurality of asynchronous request messages in parallel by setting a preset number of parallel request processing threads, thereby accelerating the speed of processing the asynchronous request messages.
Optionally, the preset number may be smaller than the maximum parallel connection number of the single server of the browser, so that the maximum parallel connection number of the single server of the browser is always free, and is sufficient for executing operations such as picture loading and page jumping in real time.
Step 204, determining whether the asynchronous request information extracted by the browser meets the request ending condition.
In this embodiment, the execution body may determine whether the asynchronous request information extracted by the browser meets a request ending condition. If yes, go to step 205, otherwise go to step 206.
In some optional implementations of this embodiment, the request ending condition may include, but is not limited to, at least one of the following:
and under the condition one, the quantity of the asynchronous request information in the memory queue pool is zero.
When the number of the asynchronous request information in the memory queue pool is zero, the asynchronous request information indicates that all the requests corresponding to the current page are responded by the server, and the requests of the current page are finished.
And secondly, jumping to a target page from the current page by the browser.
The target page may be a page to be skipped to, for example, the user may skip the current page to the target page by manually clicking, touching, or the execution subject may automatically skip the current page to the target page. When the target page is jumped to, a new asynchronous request is generated aiming at the target page, and the asynchronous request operation of the original page is finished.
The request ending condition provided by the implementation mode can accurately represent whether the asynchronous request is ended or not, is beneficial to ending the asynchronous request in time, and improves the efficiency of large-scale asynchronous requests.
Step 205, the request for the current page is ended.
In this embodiment, after the browser executes the extracted asynchronous request information, if the request termination condition is met, the execution body may terminate the request for the current page.
Step 206, based on the non-extracted asynchronous request information in the memory queue pool, the request extraction step is continuously executed.
In this embodiment, if the request end condition is not met after the browser executes the extracted asynchronous request information, the execution body may continue to execute the request extraction step (including steps 203 to 205) based on the non-extracted asynchronous request information in the memory queue pool.
In some optional implementations of this embodiment, as shown in fig. 3, after the step 202, the executing main body may execute the following steps:
step 301, setting priority weights corresponding to the asynchronous request messages in the memory queue pool.
Wherein the priority weight is used for representing the priority degree of the asynchronous request information processed by the browser. As an example, the priority weight may be a number, with smaller numbers indicating higher priority. The priority weight may be manually set in advance, or may be automatically set by the execution agent according to the type of the asynchronous request.
Step 302, based on the priority weight, the asynchronous request information in the memory queue pool is sorted.
Generally, asynchronous request information with high priority is ranked first (i.e., priority processing), and asynchronous request information with low priority is ranked later.
According to the implementation mode, the asynchronous request information with high priority can be adjusted to the front end of the queue by setting the priority weight, namely the asynchronous request information with high priority is preferentially delivered to the browser to be executed, so that some important asynchronous request information can be preferentially executed, and the pertinence of the execution request is improved.
In some optional implementations of this embodiment, the execution body may set a priority weight to the asynchronous request information in the memory queue pool according to a preset sorting period. That is, each time, the execution main body resets the priority weight of the asynchronous request information in the memory queue pool, and further sequences the asynchronous request information in the memory queue pool according to the reset priority weight, so that the priority of the asynchronous request information is adjusted in real time, and the pertinence of the browser for dynamically executing the asynchronous request is improved.
In the method provided by the above embodiment of the application, at least one piece of asynchronous request information generated by the current page is stored in the preset memory queue pool, and then the browser sequentially extracts the asynchronous request information from the memory queue pool for processing, so that when large-scale asynchronous request information exists, the phenomenon that the browser is falsely dead or rushed due to the simultaneous occurrence of a large amount of asynchronous request information in a short time is avoided.
With further reference to FIG. 4, a flow 400 of yet another embodiment of an asynchronous request processing method in accordance with the present application is illustrated. In this embodiment, when the execution main body stores at least one piece of asynchronous request information into a preset memory queue pool, an event flag (eventstamp) corresponding to a current page is set for each piece of asynchronous request information. And the event mark corresponding to the current page is generated when jumping to the current page. That is, each page on the browser corresponds to a different event marker.
Based on this, the method comprises the following steps:
step 401, in response to the browser jumping from the current page to the target page, generating an event marker of the target page.
In this embodiment, the execution body may generate an event flag of the target page in response to the browser jumping from the current page to the target page. The target page may be a page to be skipped to, for example, the user may skip the current page to the target page by manually clicking, touching, or the execution subject may automatically skip the current page to the target page.
Step 402, matching the event mark of the asynchronous request information in the current memory queue pool with the event mark of the target page, and matching the event mark of the asynchronous request information currently executed by the browser with the event mark of the target page.
In this embodiment, the execution body may match an event flag of the asynchronous request information in the current memory queue pool with an event flag of the target page, and match an event flag of the asynchronous request information currently executed by the browser with an event flag of the target page.
Specifically, for a certain asynchronous request message, it may be determined whether the event flag of the asynchronous request message is the same as the event flag of the target page, and if so, it indicates that the two match, otherwise, they do not match.
Step 403, destroying the unmatched asynchronous request information.
In this embodiment, the execution subject may destroy the unmatched asynchronous request information. And if the unmatched asynchronous request information is overdue compared with the target page after the jump, destroying the overdue asynchronous request information in the queue and the executed asynchronous request information, and stopping the request of the original page.
In the method in the embodiment corresponding to fig. 4, by checking the consistency between the event flag of the skipped page and the event flags of the asynchronous request information in the memory queue pool and the asynchronous request information being executed, the unmatched asynchronous request information is destroyed, so that the resource occupied by the request in the memory queue can be released in the context of a large-scale asynchronous request of the browser, the initiated but not completed request can also be destroyed in time and the browser resource is released, and the resource utilization rate is improved.
With further reference to fig. 5, as an implementation of the methods shown in the above-mentioned figures, the present application provides an embodiment of an asynchronous request processing apparatus, which corresponds to the embodiment of the method shown in fig. 2, and which can be applied in various electronic devices.
As shown in fig. 5, the asynchronous request processing apparatus 500 of the present embodiment includes: a receiving module 501, configured to receive at least one asynchronous request message generated by a current page; a storage module 502, configured to store at least one asynchronous request message into a preset memory queue pool; an extracting module 503, configured to perform the following request extracting steps: sequentially extracting asynchronous request information from the memory queue pool, and executing the extracted asynchronous request information through a browser; determining whether the asynchronous request information extracted by the browser is in accordance with a request ending condition or not; if yes, ending the request aiming at the current page; an executing module 504, configured to continue executing the request extracting step based on the non-extracted asynchronous request information in the memory queue pool if the asynchronous request information does not match the asynchronous request information.
In this embodiment, the receiving module 501 may receive at least one asynchronous request message generated by the current page. The current page may be triggered by a user through clicking, touching, or the like, or may be automatically triggered by the apparatus 500 to generate a page, and the page may be displayed on a browser. The current page may include a variety of content therein, such as images, text, video, audio, animation, and the like. The browser sends the at least one asynchronous request message to the server shown in fig. 1, and the server feeds back corresponding content to the device 500 for display according to each asynchronous request message.
Generally, the Asynchronous request information is generated by Ajax technology, which is "Asynchronous JavaScript and XML" (Asynchronous JavaScript and XML), and is a web page development technology for creating interactive, fast and dynamic web page applications. By exchanging a small amount of data with the server in the background, Ajax can enable the webpage to be updated asynchronously. This means that certain parts of the web page can be updated without reloading the entire web page. .
In this embodiment, the storage module 502 may store at least one asynchronous request message into a predetermined memory queue pool. The memory queue pool is used for storing a plurality of asynchronous request messages, and the asynchronous request messages are arranged in a certain sequence. The browser can extract the asynchronous request information from the memory queue pool in sequence for processing.
In this embodiment, the extracting module 503 may sequentially extract the asynchronous request information from the memory queue pool, and execute the extracted asynchronous request information through the browser. The browser is provided on the apparatus 500, and the browser may send asynchronous request information to the server shown in fig. 1, and then receive various contents sent by the server for the asynchronous request information. The browser can sequentially extract the asynchronous request information according to the arrangement sequence of the asynchronous request information in the memory queue pool. The browser can simultaneously extract at least one asynchronous request message for processing.
In this embodiment, the extracting module 503 may further determine whether the asynchronous request information extracted by the browser meets the request ending condition.
In this embodiment, after the browser executes the extracted asynchronous request information, if the request termination condition is met, the extracting module 503 may terminate the request for the current page.
In this embodiment, after the browser executes the extracted asynchronous request information, if the request end condition is not met, the execution module 504 may continue to execute the request extraction step based on the non-extracted asynchronous request information in the memory queue pool.
In some optional implementations of this embodiment, the extracting module 503 may be further configured to: and extracting asynchronous request information from the memory queue pool based on a preset number of parallel request processing threads.
In some optional implementations of this embodiment, the preset number is smaller than the maximum number of parallel connections of a single server of the browser.
In some optional implementations of this embodiment, the apparatus 500 may further include: a setting module (not shown in the figure) configured to set priority weights corresponding to the asynchronous request messages in the memory queue pool; and a sorting module (not shown in the figure) for sorting the asynchronous request information in the memory queue pool based on the priority weight.
In some optional implementations of this embodiment, the setting module may be further configured to: and setting priority weights for the asynchronous request information in the memory queue pool according to a preset sorting period.
In some optional implementations of this embodiment, the request ending condition includes at least one of: the number of the asynchronous request information in the memory queue pool is zero; the browser jumps from the current page to the target page.
In some optional implementations of this embodiment, the storage module 502 may be further configured to: storing at least one piece of asynchronous request information into a preset memory queue pool, and setting an event mark corresponding to a current page for each piece of asynchronous request information, wherein the event mark corresponding to the current page is generated when the current page is jumped to; the apparatus 500 may further include: a generating module (not shown in the figure) for generating an event mark of the target page in response to the browser jumping from the current page to the target page; a matching module (not shown in the figure), configured to match an event flag of the asynchronous request information in the current memory queue pool with an event flag of the target page, and match an event flag of the asynchronous request information currently executed by the browser with an event flag of the target page; and a destroying module (not shown in the figure) for destroying the unmatched asynchronous request information.
The device provided by the above embodiment of the present application stores at least one asynchronous request message generated by a current page into a preset memory queue pool, and then the browser sequentially extracts the asynchronous request messages from the memory queue pool for processing, thereby avoiding a phenomenon that the browser is falsely dead or rushed due to a large amount of asynchronous request messages appearing simultaneously in a short time when a large-scale asynchronous request message exists.
Referring now to FIG. 6, shown is a block diagram of a computer system 600 suitable for use in implementing the electronic device of an embodiment of the present application. The electronic device shown in fig. 6 is only an example, and should not bring any limitation to the functions and the scope of use of the embodiments of the present application.
As shown in fig. 6, the computer system 600 includes a Central Processing Unit (CPU)601 that can perform various appropriate actions and processes according to a program stored in a Read Only Memory (ROM)602 or a program loaded from a storage section 608 into a Random Access Memory (RAM) 603. In the RAM 603, various programs and data necessary for the operation of the system 600 are also stored. The CPU601, ROM 602, and RAM 603 are connected to each other via a bus 604. An input/output (I/O) interface 605 is also connected to bus 604.
The following components are connected to the I/O interface 605: an input portion 606 including a keyboard, a mouse, and the like; an output portion 607 including a display such as a Liquid Crystal Display (LCD) and a speaker; a storage section 608 including a hard disk and the like; and a communication section 609 including a network interface card such as a LAN card, a modem, or the like. The communication section 609 performs communication processing via a network such as the internet. The driver 610 is also connected to the I/O interface 605 as needed. A removable medium 611 such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, or the like is mounted on the drive 610 as necessary, so that a computer program read out therefrom is mounted in the storage section 608 as necessary.
In particular, according to an embodiment of the present disclosure, the processes described above with reference to the flowcharts may be implemented as computer software programs. For example, embodiments of the present disclosure include a computer program product comprising a computer program embodied on a computer readable medium, the computer program comprising program code for performing the method illustrated in the flow chart. In such an embodiment, the computer program may be downloaded and installed from a network through the communication section 609, and/or installed from the removable medium 611. The computer program performs the above-described functions defined in the method of the present application when executed by a Central Processing Unit (CPU) 601.
It should be noted that the computer readable storage medium described herein can be a computer readable signal medium or a computer readable storage medium or any combination of the two. A computer readable storage medium may be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the foregoing. More specific examples of the computer readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the present application, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. In this application, however, a computer readable signal medium may include a propagated data signal with computer readable program code embodied therein, for example, in baseband or as part of a carrier wave. Such a propagated data signal may take many forms, including, but not limited to, electro-magnetic, optical, or any suitable combination thereof. A computer readable signal medium may also be any computer readable storage medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device. Program code embodied on a computer readable storage medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, fiber optic cable, RF, etc., or any suitable combination of the foregoing.
Computer program code for carrying out operations for aspects of the present application may be written in any combination of one or more programming languages, including an object oriented programming language such as Java, Smalltalk, C + + or the like and conventional procedural programming languages, such as the "C" programming language or similar programming languages. The program code may execute entirely on the user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer or entirely on the remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a Local Area Network (LAN) or a Wide Area Network (WAN), or the connection may be made to an external computer (for example, through the Internet using an Internet service provider).
The flowchart and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present application. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams and/or flowchart illustration, and combinations of blocks in the block diagrams and/or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
The modules described in the embodiments of the present application may be implemented by software or hardware. The described modules may also be provided in a processor, which may be described as: a processor includes a receiving module, a storage module, an extraction module, and an execution module. Where the names of these modules do not in some cases constitute a limitation of the unit itself, for example, the receiving module may also be described as a "module for receiving at least one asynchronous request message generated by the current page".
As another aspect, the present application also provides a computer-readable storage medium, which may be included in the electronic device described in the above embodiments; or may exist separately without being assembled into the electronic device. The computer readable storage medium carries one or more programs which, when executed by the electronic device, cause the electronic device to: receiving at least one asynchronous request message generated by a current page; storing at least one asynchronous request message into a preset memory queue pool; the following request extraction steps are performed: sequentially extracting asynchronous request information from the memory queue pool, and executing the extracted asynchronous request information through a browser; determining whether the asynchronous request information extracted by the browser is in accordance with a request ending condition or not; if yes, ending the request aiming at the current page; and if the asynchronous request information does not meet the requirement, continuing to execute the request extraction step based on the non-extracted asynchronous request information in the memory queue pool.
The above description is only a preferred embodiment of the application and is illustrative of the principles of the technology employed. It will be appreciated by those skilled in the art that the scope of the invention herein disclosed is not limited to the particular combination of features described above, but also encompasses other arrangements formed by any combination of the above features or their equivalents without departing from the spirit of the invention. For example, the above features may be replaced with (but not limited to) features having similar functions disclosed in the present application.