Electronic device and request processing method
By adopting lightweight HTTP protocol and caching strategies in edge micro servers, the problem of large overhead of web server resolution is solved, and efficient resource management and dynamic content generation is achieved.
Patent Information
- Application Number
- CN202510884369.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-27
- Publication Date
- 2025-07-29
- Estimated Expiration
- 2045-06-27
AI Technical Summary
In the prior art, the web server parsing overhead of edge microservers is relatively large, resulting in memory overflow and excessive processor load, making it difficult to effectively deploy on microprocessors with limited resources.
The lightweight HTTP protocol is used to process resource requests, and by cache static resources and generate dynamic resources on demand, reducing parsing overhead, and using the simplified HTTP protocol for data transmission.
Reduces processor load, shortens response time, improves dynamic content generation efficiency, and reduces latency and memory footprint.
Smart Images

Figure CN120389993A_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present application relate to the field of embedded technology, and particularly to an electronic device and a request processing method. Background Art
[0002] Edge computing provides support for iterative optimization of 5G (5th Generation Mobile Networks), Internet of Things, or artificial intelligence. The proportion of edge servers for providing edge computing in the server market is also increasing continuously. In the field of edge servers, there are edge micro-servers. Edge micro-servers have a smaller product volume and lower cost, and are more flexible in development and deployment, and are widely used.
[0003] In order to further reduce the cost of edge micro-servers, the method of replacing the baseboard management controller with a microprocessor can be adopted, that is, the microprocessor is used to implement some functions of the baseboard management controller. Since the development and use of the microprocessor are black boxes, in order to better control the microprocessor, a Web (i.e., World Wide Web) server can be developed based on the network interface, so as to realize controlling the microprocessor through a Web page and displaying the information obtained by the microprocessor.
[0004] There is a problem of relatively large parsing overhead for requests when developing a Web server based on a network interface. Summary of the Invention
[0005] In view of the above problems, the embodiments of the present application provide an electronic device and a request processing method for reducing parsing overhead.
[0006] According to a first aspect of the embodiments of the present application, there is provided an electronic device, which may include: a first memory configured to cache a plurality of static resources; a processor configured to: in response to a resource request sent based on the lightweight hypertext transfer protocol, when the resource type indicated by the resource request is a static resource, obtain a first target static resource from the plurality of static resources cached in the first memory according to the resource path indicated by the resource request, and send a first response message including the first target static resource to a client, where the lightweight hypertext transfer protocol is obtained by simplifying the hypertext transfer protocol; when the resource type indicated by the resource request is a dynamic resource, execute a dynamic processing flow to obtain a dynamic resource, and send a second response message including the dynamic resource to the client, where the dynamic processing flow is used to generate the dynamic resource based on the resource request.
[0007] According to a second aspect of the embodiments of the present application, a request processing method is provided, which can be applied to the electronic device described in the embodiments of the present application. The method may include: in response to a resource request sent based on the lightweight HyperText Transfer Protocol, when the resource type indicated by the resource request is a static resource, according to the resource path indicated by the resource request, obtain a first target static resource from multiple static resources cached in a first memory, and send first response information including the first target static resource to a client, where the lightweight HyperText Transfer Protocol is obtained by simplifying the HyperText Transfer Protocol; when the resource type indicated by the resource request is a dynamic resource, execute a dynamic processing flow to obtain a dynamic resource, and send second response information including the dynamic resource to the client, where the dynamic processing flow is used to generate the dynamic resource based on the resource request.
[0008] According to a third aspect of the embodiments of the present application, a computer-readable storage medium is further provided, on which a computer program or instruction is stored. When the computer program or instruction is executed by a processor, the steps of the above method are implemented.
[0009] According to a fourth aspect of the embodiments of the present application, a computer program product is further provided, including a computer program or instruction. When the computer program or instruction is executed by a processor, the steps of the above method are implemented. Description of the Drawings
[0010] Through the following description of the embodiments of the present application with reference to the drawings, the above content and other objects, features, and advantages of the present application will become clearer. In the drawings:
[0011] Figure 1 A block diagram of a request processing system according to an embodiment of the present application is shown;
[0012] Figure 2 A flowchart of a request method applied to an electronic device according to an embodiment of the present application is shown;
[0013] Figure 3 A flowchart of a request method applied to a client according to an embodiment of the present application is shown;
[0014] Figure 4 A block diagram of an electronic device for processing requests according to an embodiment of the present application is shown. Detailed Embodiments
[0015] Hereinafter, embodiments of the present application will be described with reference to the accompanying drawings. However, it should be understood that these descriptions are merely exemplary and are not intended to limit the scope of the present application. In the following detailed description, for the sake of explanation, numerous specific details are set forth in order to provide a thorough understanding of the embodiments of the present application. However, it is obvious that one or more embodiments can be implemented without these specific details. In addition, in the following description, descriptions of well-known structures and technologies are omitted to avoid unnecessarily confusing the concepts of the present application.
[0016] The terms used herein are merely for describing specific embodiments and are not intended to limit the present application. The terms "including", "comprising", etc. used herein indicate the presence of the described features, steps, operations, and / or components, but do not exclude the presence or addition of one or more other features, steps, operations, or components.
[0017] All terms used herein (including technical and scientific terms) have the meanings commonly understood by those of ordinary skill in the art, unless otherwise defined. It should be noted that the terms used herein should be interpreted as having a meaning consistent with the context of this specification and should not be interpreted in an idealized or overly rigid manner.
[0018] In the case of using expressions such as "at least one of A, B, or C", generally, it should be interpreted according to the meaning commonly understood by those of ordinary skill in the art (for example, "a system having at least one of A, B, or C" should include, but is not limited to, a system having only A, only B, only C, having A and B, having A and C, having B and C, having A, B, and C, etc.).
[0019] In the embodiments of the present application, "indicating" may include direct indication, indirect indication, explicit indication, or implicit indication. When it is described that a certain indication information is used to indicate A, it can be understood that the indication information carries A, directly indicates A, or indirectly indicates A.
[0020] In the embodiments of the present application, the various numerical numbers involved are only for the convenience of description and are not used to limit the protection scope of the present application. The magnitude of the serial numbers involved in the embodiments of the present application does not mean the order of execution. The execution order of each process should be determined by its function and internal logic. For example, terms such as "first", "second", "third", "fourth", and other various term numbers in the specification, claims, and drawings of the embodiments of the present application (if any) can be used to distinguish similar objects and do not have to be used to describe a specific order or sequence. Among them, such terms can be interchanged under appropriate circumstances.
[0021] Unless otherwise specified or logically conflicting, the terms and / or descriptions among different embodiments of the present application are consistent and can be cross-referenced. The technical features in different embodiments can be combined to form new embodiments according to their inherent logical relationships.
[0022] To clearly describe the technical solutions of the embodiments of the present application, some terms related to the embodiments of the present application are described below.
[0023] 1. TCP / IP (Transmission Control Protocol / Internet Protocol), link layer, network layer, transport layer, application layer
[0024] The TCP / IP protocol is a protocol suite that interconnects various systems on the Internet. The TCP / IP protocol can include the link layer (or data link layer or network interface layer), network layer (or internet layer), transport layer, and application layer. The link layer can include device drivers in the operating system and the physical interface of the computer. The physical interface realizes the mutual conversion between digital signals and analog signals. The Ethernet driver is a software interface for the interaction between the physical interface of the link layer and the network layer. Network layer data needs to pass through the Ethernet driver first. The Ethernet driver packs the network layer data and sends it through the physical interface. When the Ethernet driver receives data, it processes it in a form that can be received by the application layer.
[0025] The network layer can include the IP protocol. The IP protocol provides an unreliable and connectionless service.
[0026] The transport layer can be used to provide end-to-end communication for two devices. The transport layer can include the TCP protocol, UDP (User Datagram Protocol). The TCP protocol can provide a relatively comprehensive error checking mechanism, while UDP provides a lower level of error checking mechanism.
[0027] The application layer can include HTTP (HyperText Transfer Protocol). The HTTP protocol can include HTTP requests and HTTP responses.
[0028] An HTTP request can include a request line, request headers, and a request body. The request line can be expressed as "<request method><request target><HTTP version>". The "request method" can define the type of operation. For example, the request method can include GET, POST, or PUT. GET can be used to return the content of the document pointed to by the URL (Uniform Resource Locator). For example, it can be used to request the download of a web page. POST can be used to request the server to receive a specified document without replacing the existing one, but only append new data to the data. POST can send forms that can be filled in by interactive users. POST can be used to submit data. PUT can be used to update resources. The request target can be the resource path of the request. The resource path can include a URL.
[0029] Request headers can include general headers, cache control, content negotiation, authentication and security, and information related to the request body. General headers can include User-Agent (i.e., the client identifier). Content negotiation can include Accept-Encoding (i.e., the accepted encoding). Information related to the request body can include at least one of the following: Content-Type (i.e., the type of the request body) or Content-Length (i.e., the length of the request body). The request body can be used to transfer actual data.
[0030] An HTTP response can include a status line, response headers, and a response body. The status line can include the HTTP version, a status code, and status text. The status code can include general status codes. For example, general status codes can include at least one of the following: 200 OK (i.e., the client request was successful), 400 Bad Request (i.e., there is a syntax error in the client request), 403 Forbidden (i.e., the server received the request but refused to provide service), 404 Not Found (i.e., the requested resource does not exist), or 500 Internet Server Error (i.e., an unexpected error occurred on the server). Response headers are provided by the server to the client with information about the requested document or the status of the server. The response body can include response information.
[0031] 2. HTML (Hyper Text Markup Language), CSS (Cascading Style Sheets), client-side scripts
[0032] HTML is a markup language on the World Wide Web (WWW), which can be used to provide functions of multimedia information and hyperlinks, enabling the Internet to transform from pure text browsing to multimedia browsing integrating text, images, and sounds. An HTML file can include HTML elements, element attributes, and related attribute values.
[0033] CSS is a standard language used to define the styles and layouts of how pages are presented in documents such as HTML. CSS can be introduced in at least one of the ways such as inline, internal, or external. For example, style code can be added in the style (i.e., style) attribute of a tag to achieve inline in a non-reusable way. CSS selectors can be used to locate HTML elements and apply styles to them. CSS selectors can include at least one of the following: basic selectors, combinatorial selectors, attribute selectors, or pseudo-class selectors, etc. Basic selectors can include at least one of the following: element selectors, class selectors, ID selectors, or universal selectors, etc. Combinatorial selectors can include at least one of the following: descendant selectors, child selectors, adjacent sibling selectors, or general sibling selectors, etc.
[0034] Client-side scripts can refer to JavaScript (i.e., JS) scripts. JavaScript can be a client-side scripting language that is object-based and event-driven and has relatively high security. Client-side scripts can be used to embed in HTML, respond to browser events, operate on HTML elements, dynamically operate on CSS styles, or verify data before it is sent to the server.
[0035] 3. Static resources, dynamic resources, pages, static resource requests, dynamic resource requests
[0036] Resource types can include static resources or dynamic resources. Static resources can include at least one of the following: HTML files, CSS files, client-side script files, or images, etc. Dynamic resources can refer to resources that change within a first predetermined time period. For example, dynamic resources can include sensor data.
[0037] Based on this, a page can include an HTML document, CSS, client-side scripts, or images, etc. The HTML document is the basis of the page, CSS completes the layout of the page styles, and client-side scripts are responsible for the behavior of the page.
[0038] HTML can load corresponding client-side scripts, CSS, or static resources such as images according to target requirements, and can also load dynamic resources according to target requirements, and use the loaded static resources and dynamic resources to complete the rendering of the front-end page.
[0039] A static resource request can be a resource request indicating that the resource type is a static resource.
[0040] A dynamic resource request may be a resource request that indicates that the resource type is a dynamic resource.
[0041] 4. Baseboard Management Controller, Non-Programmable Device, Programmable Device
[0042] The baseboard management controller may refer to an independent microcomputer embedded on the server motherboard. The baseboard management controller can be used for out-of-band management. For example, the baseboard management controller can be used for at least one of device information management, server status detection, server status management, remote control management of the server, maintenance management of the server, or hardware monitoring. The basic management controller can communicate with at least one of the programmable device or the non-programmable device through a communication protocol. The non-programmable device may refer to an integrated circuit with fixed logic functions and difficult to modify through programming. For example, the non-programmable device may include at least one of the following: analog sensors, digital sensors, or application-specific integrated circuits, etc. The programmable device may refer to an integrated circuit whose logic functions are configured through programming. For example, the programmable device may include at least one of the following: programmable logic device, complex programmable logic device, field programmable gate array, programmable logic array, programmable array logic, or generic array logic, etc.
[0043] Edge computing provides support for the iterative optimization of technologies such as 5G, the Internet of Things, or artificial intelligence. The proportion of edge servers used to provide edge computing in the server market is also increasing. In the field of edge servers, there are edge micro-servers. Edge micro-servers have a smaller product volume and lower cost, are more flexible in development and deployment, and have a wide range of applications.
[0044] In order to further reduce the cost of edge micro-servers, the method of replacing the baseboard management controller with a microprocessor can be adopted, that is, the microprocessor is used to implement some functions of the baseboard management controller. For example, power-on and power-off control, sensor data acquisition, or heat dissipation control, etc. Since the development and use of the microprocessor are black boxes, in order to better control the microprocessor, a Web server can be developed based on the network interface, so as to realize controlling the microprocessor through a Web page and displaying the information obtained by the microprocessor.
[0045] In the process of implementing the inventive concept of the present application, it is found that since the Web server depends on the operating system and complex protocol stacks, it is difficult to directly transplant it to a microprocessor with limited resources. For example, the resource occupancy of the Web server is relatively high, that is, the Web server needs to occupy a large amount of memory for protocol parsing, dynamic resource generation, and concurrent connection management, thereby causing memory overflow.
[0046] Therefore, the embodiments of the present application provide an electronic device for processing requests, and this electronic device can be a device with limited resources. An efficient network service is realized through a multi-dimensional resource management strategy.
[0047] For example, the electronic device may include a first memory configured to cache multiple static resources to enable the acquisition of static resources from the cache, and generate dynamic resources in a demand-driven manner. The electronic device and the client perform data transmission based on the lightweight HTTP protocol. Thus, since the resource request is sent based on the lightweight HTTP protocol, and the lightweight HTTP protocol may be obtained by simplifying the HTTP protocol, the parsing overhead of the resource request is reduced. Since the first target static resource is acquired from the multiple static resources cached in the first memory according to the resource path indicated by the resource request when the resource type indicated by the resource request is a static resource, the acquisition of static resources from the cache is achieved. Thus, there is no need for repeated calculation, reducing the processor load. Also, the cached resources do not need to wait for backend processing, shortening the response time and reducing the latency. Since the dynamic resources are obtained by executing a dynamic processing request when the resource type indicated by the resource request is a dynamic resource, the demand-driven generation of dynamic resources is achieved, improving the efficiency of dynamic content generation.
[0048] The following specifically describes the request processing method applied to an electronic device and the electronic device for processing requests provided by the embodiments of the present application with reference to the accompanying drawings.
[0049] First, with reference to Figure 1 , the request processing system applicable to the request processing method is described. Next, taking the request processing system shown in Figure 1 as an example, with reference to Figure 2 and Figure 3 , the request processing method provided by the embodiments of the present application is specifically described. Among them, Figure 2 the request processing method applied to an electronic device is described. Figure 3 The request processing method applied to a client is described. Then, with reference to Figure 4 the electronic device for processing requests provided by the embodiments of the present application is specifically described.
[0050] It should be noted that the embodiments of the present application can be implemented independently or in combination with each other. For the same or similar concepts or processes, they are not described again in some embodiments.
[0051] Figure 1 The block diagram of the request processing system according to the embodiments of the present application is shown.
[0052] As Figure 1 shown, the request processing system may include a client, a physical interface of an Ethernet cable, a Physical Layer (PHY) transceiver, an electronic device, and a device. The PHY transceiver may also be referred to as a PHY chip.
[0053] An electronic device may include an edge micro-server. The edge micro-server may include an embedded Web server based on a single-chip microcomputer (i.e., a microprocessor). The electronic device may include a processor, a first memory, and a second memory. The device may include a programmable device or a non-programmable device. For example, the non-programmable device may include a sensor.
[0054] The first memory may be configured to cache a plurality of static resources. In addition, the first memory may also be configured to cache cached pre-compiled templates and stored hash values associated with the client. The processor may call init_pool() to allocate a memory pool and load the pre-compiled templates into the first memory. In addition, the first memory may also be configured to store the program code of the electronic device, for example, an RTOS (Real-Time Operating System) or HTTP server logic. The first memory may be a non-volatile memory.
[0055] The second memory may be configured to store at least one of a protocol stack space, a cache pool, or a task stack. The protocol stack space may include a network protocol stack. For example, an LwIP (Light Weight IP) protocol stack. The cache pool may be configured to cache a plurality of dynamic resources, a third target static resource, or a stored checksum of cached data. In addition, the cache pool may also be configured to cache the parsed HTTP request headers. The cache pool may be implemented by a memory management unit or a static array. The task stack may allocate runtime stack space for RTOS tasks. For example, RTOS tasks may include an HTTP service thread or a sensor reading thread, etc.
[0056] The client may be installed with various application programs, for example, a browser program for processing requests. The client may be various electronic devices with a display screen and supporting web browsing, and may include a tablet computer, a laptop computer, a desktop computer, or a smart phone, etc.
[0057] The client may be configured to generate a resource request and connect to the physical interface of the Ethernet cable via the Ethernet cable, thereby realizing communication with the physical layer transceiver. For example, the client sends a resource request based on the lightweight HTTP protocol to the physical layer transceiver via the Ethernet cable and the physical interface of the Ethernet cable.
[0058] After converting the received signal into a digital signal, the physical layer transceiver sends the digital signal to the electronic device.
[0059] An electronic device can communicate with a physical layer transceiver through MII (Media Independent Interface) or RMII (Reduced Media Independent Interface). The electronic device can also include a MAC (Media Access Control Address). For example, when the resource type indicated by a resource request is a static resource, the processor can obtain a first target static resource from multiple static resources cached in a first memory according to the resource path indicated by the resource request, and send first response information including the first target static resource to a client. When the resource type indicated by the resource request is a dynamic resource, a dynamic processing flow is executed to obtain a dynamic resource, and second response information including the dynamic resource is sent to the client. The processor can be configured to control a device to obtain data related to the device. For example, the device can be a sensor. The data related to the device can be sensor data. The dynamic resource can include sensor data. The processor can obtain sensor data through SPI (Serial Peripheral Interface) or I2C (Inter-Integrated Circuit).
[0060] Figure 2 The flowchart of a request method applied to an electronic device according to an embodiment of the present application is shown. The electronic device can include a processor and a first memory. The request processing method can be executed by the processor.
[0061] As Figure 2 shown, the method includes operations S210 to S220.
[0062] In operation S210, in response to a received resource request sent based on the lightweight HTTP protocol, when the resource type indicated by the resource request is a static resource, a first target static resource is obtained from multiple static resources cached in a first memory according to the resource path indicated by the resource request, and first response information including the first target static resource is sent to a client.
[0063] In operation S220, when the resource type indicated by the resource request is a dynamic resource, a dynamic processing flow is executed to obtain a dynamic resource, and second response information including the dynamic resource is sent to a client.
[0064] The lightweight HTTP protocol can be obtained by simplifying the HTTP protocol. For example, the lightweight HTTP protocol can be obtained by removing non-core fields from the HTTP protocol. Non-core fields can refer to fields that are irrelevant to the embedded scenario. Non-core fields can include at least one of the following: non-core header fields or non-core status codes. Non-core header fields can include at least one of the following: non-core header fields in the request header (e.g., User-Agent or Accept-Encoding) or non-core header fields in the response header. Thus, the lightweight HTTP protocol removes non-core fields from the HTTP protocol and retains other fields (i.e., core fields), thereby reducing the volume of the HTTP protocol, reducing the parsing overhead of a single request and the storage overhead of the HTTP protocol, and reducing the complexity of the parsing state machine.
[0065] Core fields can include at least one of the following: core header fields in the request header, core header fields in the response header, or basic status codes.
[0066] As an implementation, the request header of the lightweight HTTP protocol can include core header fields in the request header of the HTTP protocol. For example, the request header of the lightweight HTTP protocol can be composed of core header fields in the request header of the HTTP protocol. Core header fields in the request header can include at least one of the following: GET, POST, or Content-Length, etc.
[0067] As another implementation, the response header of the lightweight HTTP protocol can include core header fields in the response header of the HTTP protocol. For example, the response header of the lightweight HTTP protocol can be composed of core header fields in the response header of the HTTP protocol.
[0068] As another implementation, the status code of the lightweight HTTP protocol can be the basic status code in the status line of the HTTP protocol. For example, basic status codes can include at least one of the following: 200 OK, 400 Bad Request, 403 Forbidden, 404 Not Found, or 500 Internet Server Error.
[0069] In addition, the lightweight HTTP protocol can also implement connection multiplexing for high-frequency short connection scenarios by customizing the keep-alive connection (i.e., Connection: keep-alive) to avoid frequent three-way handshakes. The keep-alive connection can be an extension header field used to control the persistence of the TCP connection between the client and the server.
[0070] The dynamic processing flow can be used to generate dynamic resources based on resource requests.
[0071] According to an embodiment of the present application, since the resource request is sent based on the lightweight HTTP protocol, and the lightweight HTTP protocol can be obtained by simplifying the HTTP protocol, the parsing overhead of the resource request is reduced. Since the first target static resource is obtained from multiple static resources cached in the first memory according to the resource path indicated by the resource request when the resource type indicated by the resource request is a static resource, the static resource is obtained from the cache, thereby eliminating the need for repeated calculations and reducing the processor load. And the cached resources do not need to wait for backend processing, shortening the response time and reducing the latency. Since the dynamic resource is obtained by executing a dynamic processing request when the resource type indicated by the resource request is a dynamic resource, the dynamic resource is generated on demand, improving the dynamic content generation efficiency.
[0072] Next, how to determine whether the resource type is a static resource or a dynamic resource, how to obtain the static resource and the optimizations related to the static resource, how to obtain the dynamic resource, the optimizations related to the dynamic resource, and the security enhancement methods will be described respectively.
[0073] 1. Regarding how to determine whether the resource type is a static resource or a dynamic resource
[0074] The client can send a resource request to the electronic device based on the lightweight HTTP protocol. The processor of the electronic device can parse the resource request to obtain the request line and the request headers.
[0075] As an implementation, the resource type can be determined as a static resource or a dynamic resource according to the request method indicated by the request line. For example, when the request method indicated by the request line is GET, the resource type is determined as a static resource. When the request method indicated by the request line is POST or PUT, the resource type is determined as a dynamic resource.
[0076] As another implementation, the resource type can be determined as a static resource or a dynamic resource according to the resource path indicated by the request line. For example, when the resource path indicated by the request line is a URL with parameters, the resource type is determined as a dynamic resource. When the resource path indicated by the request line is a URL without parameters, the resource type is determined as a static resource. The resource path of the dynamic resource can be mapped to a backend processing function. The resource path of the static resource can be mapped to the file system.
[0077] As another implementation, when the request headers include Content-Type or Content-Length, the resource type is determined as a dynamic type.
[0078] 2. Regarding how to obtain the static resource
[0079] The first memory of the electronic device can be configured to cache multiple static resources. Thus, when the resource type indicated by the resource request is a static resource, the processor of the electronic device can obtain the first target static resource from the multiple static resources cached in the first memory according to the resource path indicated by the resource request.
[0080] Thus, the first response information can be generated based on the first target static resource and sent to the client based on the lightweight HTTP protocol.
[0081] 3. Optimization related to static resources
[0082] 3.1. Accelerating the parsing of static resource requests
[0083] Since the content and structure of static resources are relatively fixed, that is, the dynamic parameters in the static resources are less than or equal to the fourth predetermined threshold, and the request body is related to the dynamic parameters, therefore, if the resource type is a static resource, the parsing of the request body can be skipped, and the first target static resource can be directly obtained from the multiple static resources cached in the first memory according to the resource path indicated by the parsing result obtained from at least one of the parsing request line or request header. Since there is no need to parse the request body, the parsing speed of static resource requests is improved, and the parsing overhead of static resource requests is reduced.
[0084] As an implementation, a finite state machine (FSM) can be used to parse the resource request to obtain the parsing result. For example, a positioning function can be used to locate the predetermined delimiter in the resource request. For example, the positioning function can include strstr(). The predetermined delimiter can be "\r \r".
[0085] 3.2. Static resource optimization
[0086] Static resources can include at least one of the following: HTML files or compressed files. Compressed files can include at least one of the following: CSS files or client script files. Thus, the original HTML file can be optimized to obtain the HTML file. The file to be compressed is compressed to obtain the compressed file. The file to be compressed can include at least one of the following: the original CSS file and the original client script file.
[0087] The optimization of HTML files and the optimization of files to be compressed will be described below respectively.
[0088] 3.2.1. HTML file optimization
[0089] The optimization of the original HTML file to obtain the HTML file can be achieved through at least one of the following implementation methods.
[0090] As an implementation, the first invalid character may include at least one of an invalid line break or an invalid space. For example, the invalid line break may refer to an extra line break. The invalid space may refer to an extra space. Thus, the first comment or the first invalid character in the original HTML file can be deleted. For example, the first comment or at least one of the first invalid characters is deleted using a first regular expression. By deleting the first comment or the first invalid character in the original HTML file, the size of the original HTML file is reduced by 40% to 60%, thereby saving storage overhead.
[0091] As another implementation, nested tags in the original HTML file can be converted into single-line tags to obtain single-line tags in the HTML file. For example, the nested tags in the original HTML file can be merged into a single-line form to obtain single-line tags. For example, the nested tag can be " text ". The single-line tag can be " text ".
[0092] Since parsing nested tags requires processing more start tags and end tags and ensuring the correct nesting relationship of the tags, while in the case of parsing single-line tags, there is no need to frequently switch between different tags and verify the nesting relationship, and there is no need to process complex nesting relationships or attributes, therefore, the parsing duration and parsing complexity can be reduced.
[0093] As another implementation, a CSS file or a client script file can be embedded in the original HTML file. For example, an external CSS file can be passed through <style>标签嵌入原始HTML文件。可以将外部客户端脚本文件通过<script>标签嵌入原始HTML文件。<script> 标签可以还是 HTML 中用于嵌入或引用客户端脚本的标签,使页面具备动态交互能力。
[0094] 由此,无需额外请求CSS文件或JS文件,进而可以减少请求CSS文件或客户端脚本文件的请求开销。
[0095] 3.2.2、待压缩文件优化
[0096] 待压缩文件可以包括以下至少一项:原始CSS文件或原始客户端脚本文件。可以通过以下实现方式中的至少一项实现对待压缩文件进行压缩,得到经压缩文件。
[0097] 作为一种实现方式,为了删除未使用的CSS选择器或JS函数,合并重复样式规则,可以对待压缩文件的作用域进行优化。例如,在待压缩文件为原始CSS文件的情况下,可以解析HTML文件,得到原始CSS文件中已使用类标识。根据已使用类标识,删除未使用CSS选择器。根据已使用类标识,合并重复样式规则,由此,得到CSS文件。例如,可以将.header{color:red}与.title {color:red}合并为.shared {color:red}。
[0098] 在待压缩文件为原始客户端脚本文件的情况下,可以根据HTML文件,构建针对原始客户端脚本的依赖图。根据依赖图,确定原始客户端脚本中未使用的函数或变量。删除与未使用的函数或变量关联的代码,得到客户端脚本文件。
[0099] 作为另一种实现方式,在待压缩文件为客户端脚本文件的情况下,令牌(即Token)类型可以包括以下至少一项:关键字、标识符、运算符、字面量、注释或无效字符。例如,标识符可以包括变量名或函数名中的至少一项。无效字符可以包括以下至少一项:无效空格或无效换行符。在待压缩文件为CSS文件的情况下,令牌类型可以包括以下至少一项:选择器、属性、值、注释、大括号或无效字符。
[0100] 可以对待压缩文件进行语法分析,得到多个令牌。例如,利用第二正则表达式处理待压缩文件,得到多个令牌。针对多个令牌中的任一令牌,可以执行以下操作中的至少一项:
[0101] 作为一种实现方式,在该令牌为无效令牌的情况下,删除该令牌。在该令牌为有效令牌的情况下,保留该令牌。无效令牌可以包括第二注释或第二无效字符中的至少一项。
[0102] 作为另一种实现方式, 目标变量名的长度可以小于变量名的长度。可以将至少一个有效令牌各自的变量名转换为至少一个有效令牌各自的目标变量名。针对至少一个有效令牌中的任一有效令牌,可以将该有效令牌的变量名转换为有效令牌的目标变量名。例如,可以利用采用哈希算法将有效令牌的变量名转换为有效令牌的目标变量名。
[0103] 通过对待压缩文件进行压缩,缩减了待压缩文件的体积,由此,降低了存储开销。
[0104] 3.3、静态资源缓存池
[0105] 第二存储器可以配置为缓存多个动态资源。第二存储器的访问速率可以大于第一存储器的访问速率。第三目标静态资源可以在第二预定时段的访问频率可以大于或等于第一预定阈值。例如,第三目标静态资源可以包括index.html(即网站的入口文件)或style.css等中的至少一项。style.css可以用于定义样式,控制HTML 元素的外观和布局。第一预定阈值和第二预定时段可以根据实际业务需求进行配置,在此不作限定。
[0106] 可以响应于电子设备的启动操作,向第二存储器预加载至少一个第三目标静态资源。例如,可以在电子设备启动的情况下,可以向第二存储器的预分配内存池中预加载至少一个第三目标静态资源。例如,预分配内存池可以为SRAM(Static Random-Access Memory,静态随机存取存储器)。
[0107] 在第一存储器满足预定缓存淘汰条件的情况下,可以根据缓存淘汰策略,从第一存储器存储的多个静态资源中淘汰第二目标静态资源。预定缓存淘汰条件可以用于触发缓存淘汰。
[0108] 预定缓存淘汰条件可以包括以下至少一项:容量达到第五预定阈值、第一数目达到第六预定阈值、使用率达到第七预定阈值或命中率小于或等于第八预定阈值。容量可以指示第一存储器的缓存容量。第五预定阈值可以是根据第一存储器的缓存容量确定的。第一数目可以指示第一存储器中静态资源的数目。第六预定阈值可以是根据第一存储器的缓存容量和静态资源的存储大小确定的。使用率可以指示容量与第一存储器的缓存容量之间的比值。命中率可以指示第二数目与第三数目之间的比值。第二数目可以指示与第一存储器对应的缓存命中数目。第三数目可以指示与第一存储器对应的访问数目。
[0109] 预定缓存淘汰策略可以包括以下至少一项:先进先出策略、最近最少使用策略、最少频率使用策略、最近最多使用策略、随机淘汰策略或低交互引用间隔策略。
[0110] 作为一种实现方式,预定淘汰缓存策略可以为最近最少使用策略,可以利用双向链表记录资源访问顺序,针对每次访问,可以将被访问节点移至链表头部。在第一存储器满足预定缓存淘汰条件的情况下,可以删除链表尾部节点指示的静态资源,即链表尾部节点指示的静态资源为第二目标静态资源。
[0111] 此外,还可以针对第一存储器的缓存命中率(即命中率)进行统计,得到缓存命中信息。缓存命中信息可以包括缓存命中率。例如,可以利用计数器确定第一存储器的缓存命中数目(即第二数目),根据缓存命中数目和与第一存储器对应的访问数目(即第三数目),确定缓存命中率(即命中率)。由此,可以根据缓存命中信息,调整第二存储器的预加载策略。例如,在缓存命中率小于或等于第八预定阈值的情况下,可以根据资源优先级,调整第二存储器的预加载策略。
[0112] 作为一种实现方式,可以根据资源访问时刻,确定在第三预定时段内被访问的静态资源的访问数目。将在第三预定时段内被访问的静态资源的访问数目大于或等于第九预定阈值的静态资源作为预加载至第二存储器的第三目标静态资源。
[0113] 作为另一种实现方式,可以根据资源访问时刻,确定在第四预定时段内被访问的静态资源的访问数目,以及在第五预定时段内被访问的静态资源的访问数目。第四预定时段和第五预定时段之间可以无交集。第四预定时段为第五预定时段之前的时段。根据在第四预定时段内被访问的静态资源的访问数目和在第五预定时段内被访问的静态资源的访问数目,确定访问差值大于或等于第十预定阈值的静态资源,将该静态资源作为预加载至第二存储器的第三目标静态资源。访问差值可以指静态资源在第五预定时段的访问数目与该静态资源在第四预定时段的访问数目之间的差值,且该静态资源在第五预定时段的访问数目大于该静态资源在第四预定时段的访问数目。
[0114] 4、针对如何获得动态资源
[0115] 第二存储器可以配置为缓存多个动态资源。可以在资源请求指示的资源类型为动态资源的情况下,触发中断服务例程。例如,可以通过通用输入输出接口(General-PurposeInput / Output,GPIO)中断触发电子设备响应,降低轮询带来的处理器资源开销。
[0116] 可以执行中断服务例程,得到资源请求指示的目标对象的目标数据。目标对象可以包括处理器或被处理器监测的器件中的至少一项。器件可以包括可编程器件或非编程器件中的至少一项。目标数据可以包括用于控制处理器的控制指令或处理器获取到的数据中的至少一项。例如,处理器获取到的数据可以包括传感器数据。
[0117] 可以响应于从第二存储器缓存的多个动态资源中获取到目标对象的缓存数据,在目标数据与缓存数据之间的差值的绝对值大于或等于第一预定阈值的情况下,将缓存数据替换为目标数据,并将目标数据缓存于第二存储器。由此,减少了无效数据的传输。第一预定阈值可以根据实际业务需求进行配置,在此不作限定。由此,可以根据目标数据,生成第二响应信息。
[0118] 此外,还可以利用预编译模板来生成动态数据。预编译模板可以是处理器将HTML模板转换为预定结构体得到的。预编译模板可以包括多个预定占位符。还可以构建预定占位符和数据之间的关联关系。
[0119] 由此,可以根据预定占位符和数据之间的关联关系,将目标数据写入多个预定占位符中的至少一个目标占位符,得到第二响应信息。例如,可以利用memcpy()或sprintf()将目标数据写入多个预定占位符中的至少一个目标占位符。
[0120] 通过将目标数据写入预编译模板中目标占位符的方式实现了动态资源的按需生成,降低实时解析开销。
[0121] 5、与动态资源相关的优化
[0122] 为了降低内存错误导致的第二存储器缓存的动态资源出现异常的概率,保证动态资源的完整性,第二存储器还可以配置为缓存缓存数据的存储校验码,由此,可以响应于从第二存储器缓存的多个动态资源中获取到目标对象的缓存数据,确定缓存数据的读取校验码。在存储校验码与读取校验码相同的情况下,可以说明缓存数据未出现异常,在此情况下,如果在目标数据与缓存数据之间的差值大于或等于第二预定阈值,则可以将缓存数据替换为目标数据。在存储校验码与读取校验码不相同的情况下,可以说明缓存数据出现异常,在此情况下,可以从第二存储器删除该缓存数据。作为一种实现方式,读取校验码可以是在从第二存储器获取缓存数据的情况下,利用循环冗余校验方法处理缓存数据的得到的。存储校验码可以是在将缓存数据缓存于第二存储器的情况下,利用循环冗余校验方法处理缓存数据得到的。
[0123] 此外,目标数据可以包括传感器数据。可以配置传感器数据的缓存有效期。如果超过缓存有效期,则需要重新采集传感器数据,由此,提高了传感器数据的有效性。
[0124] 此外,还可以利用非阻塞模式处理耗时操作,并通过状态机管理任务进度,以实现异步I / O处理。耗时操作可以包括以下至少一项:文件读操作、文件写操作或传感器读取操作等。
[0125] 此外,还可以在动态资源请求处理期间,限制处理器时间片,以使得主线程能够优先处理优先级更高的资源请求。例如,可以响应于动态资源请求的处理时长大于或等于第三预定阈值,暂停处理动态资源请求,以使得处理器可以处理优先级高于该动态资源请求的资源请求。例如,可以使得处理器的主线程可以处理优先级高于该动态资源请求的资源请求。
[0126] 6、安全增强方式
[0127] 第一存储器还可以配置为缓存与客户端关联的存储哈希值。存储哈希值可以用于验证客户端的身份。
[0128] 由此,可以响应于资源请求包括客户端的待验证身份信息,解码待验证身份信息,得到解码信息。确定解码信息的验证哈希值。再从第一存储中获取到与客户端关联的存储哈希值。在验证哈希值与存储哈希值相同的情况下,生成指示客户端的身份验证通过的第三响应信息。在验证哈希值与存储哈希值不相同的情况下,生成指示客户端的身份验证未通过的第三响应信息。
[0129] 此外,可以响应于客户端在预定时长的请求次数等于第三预定阈值,向客户端发送提示客户端降低请求频率的第四响应信息。第三预定阈值可以根据实际业务需求进行配置,在此不作限定。
[0130] 此外,处理器还配置为响应于接收到的基于轻量化HTTP协议的资源请求,在资源请求指示的接口类型为敏感接口的情况下,启动用于建立电子设备与客户端之间的加密连接操作,以提高安全性。例如,敏感接口可以包括登录页面。由于是在接口类型为敏感接口的情况下,执行加密连接操作,而并不是针对所有接口类型均执行该操作,因此,降低了资源消耗,由此实现了安全性与资源消耗之间的平衡。例如,可以利用传输层安全协议1.2(Transport Layer Security 1.2,TLS 1.2)来实现加密连接操作。
[0131] 此外,还通过内存保护单元防止越界访问,提高系统稳定性。
[0132] 7、静态内存池管理
[0133] 此外,还可以预配置多个固定大小的内存块,并构建空闲链表。可以从空闲链表获取内存块,释放时归还空闲链表。内存块结构可以包括数据区和管理信息。数据区用于存储实际数据。管理信息用于指向下一个空闲块的指针。管理信息可以用于链表管理。在电子设备启动的情况下,可以分配连续内存,例如,可以通过静态数组实现,并将连续内存划分为多个固定大小的内存块。将内存块通过链表连接起来,形成空闲链表。头指针指向第一个空闲块。从空闲链表获取内存块,并更新头指针,标记内存块的状态为已分配。可以将释放的内存块重新插入空闲链表头部,并将内存块的状态标记为未分配。内存块可以为第一存储器中的内存块,也可以为第二存储器中的内存块。
[0134] 由于内存块的大小固定,因此可以降低动态分配导致的内存碎片。
[0135] 此外,针对实时性要求较高的控制指令(例如,开关指令),可以基于UDP协议传输,以降低协议栈开销。针对可靠性要求较高的页面传输,可以基于TCP协议传输,以提高传输可靠性。
[0136] 图3示出了根据本申请实施例的应用于客户端的请求处理方法的流程图。
[0137] 如图3所示,该方法包括操作S310~S320。
[0138] 在操作S310,基于轻量化HTTP协议向电子设备发送资源请求,以使得电子设备响应于接收到的基于轻量化HTTP协议发送的资源请求,在资源请求指示的资源类型为静态资源的情况下,根据资源请求指示的资源路径,从第一存储器缓存的多个静态资源中获取第一目标静态资源。在资源请求指示的资源类型为动态资源的情况下,执行动态处理流程,得到动态资源。
[0139] 在S320,接收自电子设备生成的包括第一目标静态资源的的第一响应信息或生成的包括动态资源的第二响应信息。
[0140] 根据本申请的实施例,客户端可以显示第一响应信息或第二响应信息。
[0141] 以上说明了本申请实施例提供的应用于电子设备和客户端的请求处理方法。
[0142] 在上述内容的基础上,下面针对本申请实施例提供的请求处理进行整体说明。
[0143] 本申请实施例提供的请求处理方法,通过协议精简与静态池化,内存占用降低60%,可以支持同时处理大于或等于20个并发连接。可以支持模块化扩展(例如,增加MQTT(Message Queuing Telemetry Transport,消息队列遥测传输协议)),兼容主流IoT(Internet of Things,物联网)平台。HTML文件体积从12KB压缩至3.5KB,首屏加载时间缩短至0.8秒,传输效率提高了40%。事件驱动方式使得待机功耗降低至15mA。
[0144] 由此,本申请实施例的技术方案可以适用于小于或等于8KB RAM(Random AccessMemory,随机存取存储器)的单片机,由此,突破了Web服务器内存限制。通过内存保护单元防止越界访问,提高了系统稳定性。
[0145] 与前述应用于电子设备的请求处理方法的实施例基于相同的发明构思,本申请实施例还提供了一种用于处理请求的电子设备,实现本申请实施例提供的应用于电子设备的请求处理方法。电子设备包括用以实现请求处理方法的各个操作的电路。
[0146] 图4示出了根据本申请实施例的用于处理请求电子设备的框图。
[0147] 如图4所示,该电子设备400可以包括第一存储器410和处理器420。
[0148] 第一存储器410,可以配置为缓存多个静态资源。
[0149] 处理器420,可以配置为:
[0150] 响应于接收到的基于轻量化超文本传输协议发送的资源请求,在资源请求指示的资源类型为静态资源的情况下,根据资源请求指示的资源路径,从第一存储器缓存的多个静态资源中获取第一目标静态资源,并向客户端发送包括第一目标静态资源的第一响应信息。
[0151] 在资源请求指示的资源类型为动态资源的情况下,执行动态处理流程,得到动态资源,并向客户端发送包括动态资源的第二响应信息。
[0152] 根据本申请的实施例,轻量化超文本传输协议可以利用简化超文本传输协议得到的。动态处理流程可以用于基于资源请求生成动态资源。
[0153] 本申请还提供了一种计算机可读存储介质,该计算机可读存储介质可以是上述实施例中描述的设备 / 装置 / 系统中所包含的;也可以是单独存在,而未装配入该设备 / 装置 / 系统中。上述计算机可读存储介质承载有一个或者多个程序,当上述一个或者多个程序被执行时,实现根据本申请实施例的方法。
[0154] 根据本申请的实施例,计算机可读存储介质可以是非易失性的计算机可读存储介质,例如可以包括但不限于:便携式计算机磁盘、硬盘、随机访问存储器(RAM)、只读存储器(ROM)、可擦式可编程只读存储器(EPROM或闪存)、便携式紧凑磁盘只读存储器(CD-ROM)、光存储器件、磁存储器件、或者上述的任意合适的组合。在本申请中,计算机可读存储介质可以是任何包含或存储程序的有形介质,该程序可以被指令执行系统、装置或者器件使用或者与其结合使用。例如,根据本申请的实施例,计算机可读存储介质可以包括ROM(只读存储器)和 / 或RAM和 / 或ROM和RAM以外的一个或多个存储器。
[0155] 本申请的实施例还包括一种计算机程序产品,其包括计算机程序,该计算机程序包含用于执行流程图所示的方法的程序代码。当计算机程序产品在计算机系统中运行时,该程序代码用于使计算机系统实现本申请实施例所提供的请求处理方法。
[0156] 在该计算机程序被处理器执行时执行本申请实施例的系统 / 装置中限定的上述功能。根据本申请的实施例,上文描述的系统、装置、模块、单元等可以通过计算机程序模块来实现。
[0157] 在一种实施例中,该计算机程序可以依托于光存储器件、磁存储器件等有形存储介质。在另一种实施例中,该计算机程序也可以在网络介质上以信号的形式进行传输、分发,并通过通信部分被下载和安装,和 / 或从可拆卸介质被安装。该计算机程序包含的程序代码可以用任何适当的网络介质传输,包括但不限于:无线、有线等等,或者上述的任意合适的组合。
[0158] 在这样的实施例中,该计算机程序可以通过通信部分从网络上被下载和安装,和 / 或从可拆卸介质被安装。在该计算机程序被处理器执行时,执行本申请实施例的系统中限定的上述功能。根据本申请的实施例,上文描述的系统、设备、装置、模块、单元等可以通过计算机程序模块来实现。
[0159] 根据本申请的实施例,可以以一种或多种程序设计语言的任意组合来编写用于执行本申请实施例提供的计算机程序的程序代码,具体地,可以利用高级过程和 / 或面向对象的编程语言、和 / 或汇编 / 机器语言来实施这些计算程序。程序设计语言包括但不限于诸如Java,C++,python,"C”语言或类似的程序设计语言。程序代码可以完全地在用户计算设备上执行、部分地在用户设备上执行、部分在远程计算设备上执行、或者完全在远程计算设备或服务器上执行。在涉及远程计算设备的情形中,远程计算设备可以通过任意种类的网络,包括局域网(LAN)或广域网(WAN),连接到用户计算设备,或者,可以连接到外部计算设备(例如利用因特网服务提供商来通过因特网连接)。
[0160] 附图中的流程图和框图,图示了按照本申请各种实施例的系统、方法和计算机程序产品的可能实现的体系架构、功能和操作。在这点上,流程图或框图中的每个方框可以代表一个模块、程序段、或代码的一部分,上述模块、程序段、或代码的一部分包含一个或多个用于实现规定的逻辑功能的可执行指令。也应当注意,在有些作为替换的实现中,方框中所标注的功能也可以以不同于附图中所标注的顺序发生。例如,两个接连地表示的方框实际上可以基本并行地执行,它们有时也可以按相反的顺序执行,这依所涉及的功能而定。也要注意的是,框图或流程图中的每个方框、以及框图或流程图中的方框的组合,可以用执行规定的功能或操作的专用的基于硬件的系统来实现,或者可以用专用硬件与计算机指令的组合来实现。
[0161] 本领域技术人员可以理解,本申请的各个实施例中记载的特征可以进行多种组合和 / 或结合,即使这样的组合或结合没有明确记载于本申请中。特别地,在不脱离本申请精神和教导的情况下,本申请的各个实施例中记载的特征可以进行多种组合和 / 或结合。所有这些组合和 / 或结合均落入本申请的范围。
[0162] 以上对本申请的实施例进行了描述。但是,这些实施例仅仅是为了说明的目的,而并非为了限制本申请的范围。尽管在以上分别描述了各实施例,但是这并不意味着各个实施例中的措施不能有利地结合使用。不脱离本申请的范围,本领域技术人员可以做出多种替代和修改,这些替代和修改都应落在本申请的范围之内。< / style>
Claims
1. An electronic device, characterized in that, Including: A first memory configured to cache multiple static resources; And A processor configured to: In response to a received resource request sent based on the lightweight Hypertext Transfer Protocol, when the resource type indicated by the resource request is a static resource, obtain a first target static resource from the multiple static resources cached in the first memory according to the resource path indicated by the resource request, and send a first response message including the first target static resource to the client, wherein the lightweight Hypertext Transfer Protocol is obtained by simplifying the Hypertext Transfer Protocol; When the resource type indicated by the resource request is a dynamic resource, execute a dynamic processing flow to obtain a dynamic resource, and send a second response message including the dynamic resource to the client, wherein the dynamic processing flow is used to generate the dynamic resource based on the resource request.
2. The electronic device according to claim 1, wherein The request header of the lightweight Hypertext Transfer Protocol includes the core header fields in the request header of the Hypertext Transfer Protocol; and / or The status code of the lightweight Hypertext Transfer Protocol is the basic status code in the status line of the Hypertext Transfer Protocol; and / or The response header of the lightweight Hypertext Transfer Protocol includes the core header fields in the response header of the Hypertext Transfer Protocol.
3. The electronic device according to claim 1 or 2, characterized in that, The processor is further configured to: Parse at least one of the request line or the request header in the resource request to obtain a parsing result; and When the resource type indicated by the parsing result is the static resource, obtain the first target static resource from the multiple static resources cached in the first memory according to the resource path indicated by the parsing result.
4. The electronic device according to claim 1 or 2, characterized in that, The static resources include at least one of the following: Hypertext Markup Language files, Cascading Style Sheet files, or client script files; Wherein, the processor is further configured to perform at least one of the following operations: Optimize the original Hypertext Markup Language file to obtain the Hypertext Markup Language file; or Compress the file to be compressed to obtain a compressed file, wherein the file to be compressed includes at least one of the following: the original Cascading Style Sheet file or the original client script file, and the compressed file includes at least one of the following: the Cascading Style Sheet file or the client script file.
5. The electronic device according to claim 4, characterized in that, The processor is further configured to perform at least one of the following operations to optimize the original Hypertext Markup Language file to obtain the Hypertext Markup Language file: Delete the first comment or the first invalid characters in the original Hypertext Markup Language file, wherein the first invalid characters include at least one of invalid line breaks or invalid spaces; Convert the nested tags in the original Hypertext Markup Language file into single-line tags; or Embed the Cascading Style Sheet file or the client script file into the original Hypertext Markup Language file.
6. The electronic device according to claim 4, characterized in that The processor is further configured to: Optimize the scope of the file to be compressed; and / or For any one of the multiple tokens obtained by performing syntax analysis on the file to be compressed, perform at least one of the following operations: In response to the token being an invalid token, delete the token; in response to the token being a valid token, retain the token, where the invalid token includes at least one of a second annotation or a second invalid character; or Convert the variable name of each of at least one of the valid tokens into a target variable name of each of at least one of the valid tokens, where the length of the target variable name is less than the length of the variable name.
7. The electronic device according to claim 1 or 2, characterized in that The processor is further configured to: In response to the first memory satisfying a predetermined cache eviction condition, evict a second target static resource from a plurality of static resources stored in the first memory according to a cache eviction policy.
8. The electronic device according to claim 1 or 2, characterized in that, The electronic device further includes a second memory configured to cache a plurality of dynamic resources, and the access rate of the second memory is greater than the access rate of the first memory; wherein the processor is further configured to: In response to the resource type indicated by the resource request being the dynamic resource, trigger an interrupt service routine; Execute the interrupt service routine to obtain target data of a target object indicated by the resource request, where the target object includes at least one of the processor or a device monitored by the processor; In response to obtaining cache data of the target object from a plurality of dynamic resources cached in the second memory, in a case where the difference between the target data and the cache data is greater than or equal to a first predetermined threshold, replace the cache data with the target data and cache the target data in the second memory; Generate the second response information according to the target data; and Send the second response information to the client.
9. The electronic device according to claim 8, wherein The processor is further configured to: Obtain a precompiled template, where the precompiled template is obtained by the processor converting a HyperText Markup Language template into a predetermined structure, and the precompiled template includes a plurality of predetermined placeholders; and Write the target data into at least one target placeholder among the plurality of predetermined placeholders to obtain the second response information.
10. The electronic device according to claim 8, wherein, The processor is further configured to: In response to a startup operation of the electronic device, preload at least one third target static resource into the second memory, where the access frequency of the third target static resource in a predetermined time period is greater than or equal to a first predetermined threshold.
11. The electronic device according to claim 10, characterized in that, The processor is further configured to: Adjust the preloading policy of the second memory according to cache hit information associated with the first memory.
12. The electronic device according to claim 8, wherein, The second memory is further configured to cache a storage check code of the cache data; wherein the processor is further configured to: In response to obtaining cache data of the target object from a plurality of dynamic resources cached in the second memory, determine a read check code of the cache data; In response to the storage check code being the same as the read check code, in a case where the absolute value of the difference between the target data and the cache data is greater than or equal to a second predetermined threshold, replace the cache data with the target data.
13. The electronic device according to claim 8, wherein The processor is further configured to: In response to the processing duration of the dynamic resource request being greater than or equal to a third predetermined threshold, suspend the processing of the dynamic resource request, where the dynamic resource request is a resource request indicating that the resource type is the dynamic resource.
14. The electronic device according to claim 1 or 2, characterized in that, The first memory is further configured to cache a stored hash value associated with the client, and the stored hash value is used to verify the identity of the client; Wherein, the processor is further configured to: In response to the resource request including the identity information to be verified of the client, decode the identity information to be verified to obtain decoded information; Determine the verification hash value of the decoded information; Obtain the stored hash value associated with the client from the first storage; and In response to the verification hash value being the same as the stored hash value, generate third response information indicating that the identity verification of the client has passed.
15. A request processing method, characterized in that, Applied to the electronic device according to any one of claims 1 to 14, the method includes: In response to a received resource request sent based on the lightweight hypertext transfer protocol, when the resource type indicated by the resource request is a static resource, according to the resource path indicated by the resource request, obtain a first target static resource from multiple static resources cached in the first memory, and send first response information including the first target static resource to the client, where the lightweight hypertext transfer protocol is obtained by simplifying the hypertext transfer protocol; and When the resource type indicated by the resource request is a dynamic resource, execute a dynamic processing flow to obtain a dynamic resource, and send second response information including the dynamic resource to the client, where the dynamic processing flow is used to generate the dynamic resource based on the resource request.
Citation Information
Patent Citations
High-availability Web application platform
CN110287067A
Static resource acquisition method and device and related equipment thereof
CN111367673A
Static resource file access method and device, storage medium and server
CN116088957A
Static resource processing method and device, equipment and storage medium
CN116418825A
Front-end and rear-end fused multi-stage braking caching method and device for hot data
CN120066400A