Gateway-based script execution method, device and equipment and readable storage medium

By integrating LUA scripts and Redis connection pool reuse mechanisms at the gateway layer, the problem of long user request latency was solved, enabling efficient user request processing and improving system performance and user experience.

CN121485968APending Publication Date: 2026-02-06CHINA ASSET MANAGEMENT CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202511520457.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-10-23
Publication Date
2026-02-06

AI Technical Summary

Technical Problem

In the process of handling Redis-related user requests through network services, user requests need to first penetrate the backend server for business logic processing, resulting in long response times and a poor user experience.

Method used

By integrating LUA scripts into the gateway layer, logic such as access control, user frequency limits, and blacklist interception is pre-processed. Combined with the Redis connection pool reuse mechanism, network overhead is reduced, and probability calculation and inventory deduction operations are uniformly completed in Redis, with results being asynchronously persisted using message queues.

Benefits of technology

It significantly reduces request latency, increases system throughput, supports tens of thousands of QPS on a single node, has an average response time of less than 5ms, avoids resource over-provisioning and duplicate matching issues, and improves user experience.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121485968A_ABST
    Figure CN121485968A_ABST
Patent Text Reader

Abstract

The invention discloses a gateway-based script execution method, apparatus and device, and a readable storage medium, and relates to the technical field of network services. The gateway-based script execution method comprises the following steps: calling a preset script by a gateway, and performing access control on a received user request; obtaining an idle connection from a connection pool configured between the gateway process and the database server in response to access control passing of the user request; verifying the execution qualification of the user according to the user request; in response to the fact that the execution qualification of the user passes the verification, sending the preset script to a database server through the idle connection, and executing the service logic of the preset script to obtain an execution result; and storing the execution result in a non-volatile storage medium to realize persistence of the execution result. By implementing the technical scheme of the invention, the user request can be prevented from penetrating back-end service, and the request response speed is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of network service technology, and in particular to a gateway-based script execution method, apparatus, device, and readable storage medium. Background Technology

[0002] In handling Redis-related user requests via network services, user requests typically need to be transmitted to a backend Java or Python server for response. The backend Java or Python server then connects to the Redis server and invokes a Lua script to process the business logic. This user request response logic requires penetrating the backend server, resulting in significant response latency in high-concurrency scenarios, often exceeding 500 milliseconds. This leads to long waiting times for users to receive request responses, resulting in a poor user experience. Summary of the Invention

[0003] This application provides a gateway-based script execution method, apparatus, device, and readable storage medium, which at least solves the problem of long latency caused by user requests needing to penetrate the backend server before business logic processing.

[0004] Firstly, this application provides a gateway-based script execution method, including: The gateway invokes a preset script to perform access control on received user requests; In response to a user request to pass access control, an idle connection is obtained from the connection pool configured between the gateway process and the database server; Verify the user's eligibility to execute based on the user's request; If the user's execution qualification is verified, the preset script is sent to the database server through an idle connection, and the business logic of the preset script is executed to obtain the execution result; The execution results are stored in a non-volatile storage medium to achieve persistence of the execution results.

[0005] Furthermore, before the gateway invokes a preset script to perform access control on the received user requests, the following steps are also included: Configure a backend application server cluster; Configure the database server and set up a connection pool for the gateway process and the database server.

[0006] Configure application layer service listening and bind domain name.

[0007] Furthermore, the gateway invokes a preset script to perform access control on the received user requests, including: Upon receiving a user request, the gateway loads a pre-defined script. A pre-defined script checks whether the IP address of the client corresponding to the user's request is in the blacklist; A preset script limits the frequency of global user requests.

[0008] Furthermore, in response to a user request failing access control, the user request is rejected and terminated.

[0009] Furthermore, the preset script is a resource matching script. The preset script is sent to the database server via an idle connection, and its business logic is executed to obtain the execution result, including: Determine the matching resource corresponding to the user request; The quantity of the matching resource corresponding to the user request is deducted from the resource inventory of the matching resource; Update the request count for the user corresponding to the updated user request; The matching resources and the updated number of requests are used as the execution result.

[0010] Furthermore, after sending the preset script to the database server via an idle connection, executing the business logic of the preset script, and obtaining the execution result, the process also includes: The execution result is then sent back to the client to complete the response to the user's request; Release the connection used to handle user requests to the connection pool.

[0011] Furthermore, storing the execution results to a non-volatile storage medium to achieve persistence of the execution results includes: The execution result is encapsulated into a structured message, and the structured message is sent to the message queue. After sending the structured message to the message queue, release the client that sent the user request to complete the execution of the user request; Structured messages are saved to non-volatile storage media to achieve persistence of execution results.

[0012] Secondly, this application also provides a gateway-based script execution device, comprising: The access control module is used by the gateway to call a preset script to perform access control on the received user requests; The connection acquisition module is used to obtain an idle connection from the connection pool configured between the gateway process and the database server in response to a user request to pass access control. The qualification verification module is used to verify a user's eligibility to execute based on the user's request; The business execution module is used to respond to the user's execution qualification being verified, by sending a preset script to the database server through an idle connection, executing the business logic of the preset script, and obtaining the execution result; The result storage module is used to store the execution results to a non-volatile storage medium to achieve the persistence of the execution results.

[0013] Thirdly, this application also provides a computer device, including a memory, a processor, and a gateway-based script execution program stored in the memory and executable on the processor. When the processor executes the gateway-based script execution program, it implements the gateway-based script execution method described in the first aspect. This includes: The gateway invokes a preset script to perform access control on received user requests; In response to a user request to pass access control, an idle connection is obtained from the connection pool configured between the gateway process and the database server; Verify the user's eligibility to execute based on the user's request; If the user's execution qualification is verified, the preset script is sent to the database server through an idle connection, and the business logic of the preset script is executed to obtain the execution result; The execution results are stored in a non-volatile storage medium to achieve persistence of the execution results.

[0014] Fourthly, this application also provides a computer-readable storage medium storing a gateway-based script execution program thereon. When executed by a processor, the gateway-based script execution program implements the gateway-based script execution method described in the first aspect. This includes: The gateway invokes a preset script to perform access control on received user requests; In response to a user request to pass access control, an idle connection is obtained from the connection pool configured between the gateway process and the database server; Verify the user's eligibility to execute based on the user's request; If the user's execution qualification is verified, the preset script is sent to the database server through an idle connection, and the business logic of the preset script is executed to obtain the execution result; The execution results are stored in a non-volatile storage medium to achieve persistence of the execution results.

[0015] Fifthly, this application also provides a computer program product, including a computer program that, when executed by a processor, implements the gateway-based script execution method described in the first aspect, including: The gateway invokes a preset script to perform access control on received user requests; In response to a user request to pass access control, an idle connection is obtained from the connection pool configured between the gateway process and the database server; Verify the user's eligibility to execute based on the user's request; If the user's execution qualification is verified, the preset script is sent to the database server through an idle connection, and the business logic of the preset script is executed to obtain the execution result; The execution results are stored in a non-volatile storage medium to achieve persistence of the execution results.

[0016] The beneficial effects of the technical solution provided in this application are as follows: By implementing the gateway-based script execution method, apparatus, device, and readable storage medium provided in this application, and by integrating LUA scripts at the Nginx gateway layer, access control, user frequency limits, blacklist interception, and other logic are pre-processed to avoid requests penetrating to the backend service; combined with the Redis connection pool reuse mechanism, network overhead is reduced, a single node can support tens of thousands of QPS, and the average response time is less than 5ms; utilizing the single-threaded characteristics of Redis and the atomic execution capability of LUA scripts, probability calculation, inventory deduction, and user count update operations are uniformly completed in Redis, avoiding data anomalies such as resource over-issuance and duplicate matching; by asynchronously persisting the winning results through a message queue, the main process can return a response to the client without waiting for the database to be written, improving the user experience; and by having an independent data persistence service consume messages and write them to the database, system decoupling and fault isolation are ensured. Attached Figure Description

[0017] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0018] Figure 1 This is a schematic diagram of a gateway-based script execution method provided in an embodiment of this application; Figure 2 This is a schematic diagram of a gateway-based script execution device provided in an embodiment of this application; Figure 3 This is a schematic diagram of a computer device provided in an embodiment of this application. Detailed Implementation

[0019] To make the objectives, technical solutions, and advantages of this application clearer, the technical solutions in the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of this application, and not all of the embodiments. Based on the embodiments in this application, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the scope of protection of this application.

[0020] Unless otherwise defined, the technical or scientific terms used in this disclosure shall have the ordinary meaning understood by one of ordinary skill in the art to which this disclosure pertains. The terms “first,” “second,” and similar terms used in this disclosure do not indicate any order, quantity, or importance, but are merely used to distinguish different components. Similarly, the terms “an,” “a,” or “the,” and similar terms do not indicate a quantity limitation, but rather indicate the presence of at least one. The numbers in the accompanying drawings are only used to distinguish individual functional parts or modules and do not indicate logical relationships between parts or modules. The terms “comprising,” “including,” or “including,” and similar terms mean that the element or object preceding the term encompasses the element or object listed following the term and its equivalents, without excluding other elements or objects. The terms “connected,” “linked,” and similar terms are not limited to physical or mechanical connections, but can include electrical connections, whether direct or indirect. “Above,” “below,” “left,” “right,” etc., are used only to indicate relative positional relationships; when the absolute position of the described object changes, the relative positional relationship may also change accordingly.

[0021] The various embodiments according to this disclosure will now be described in detail with reference to the accompanying drawings. It should be noted that in the drawings, the same reference numerals are assigned to components having substantially the same or similar structure and function, and repeated descriptions of them will be omitted.

[0022] To address the issue of long latency caused by the need for user requests to first penetrate the backend server before business logic processing in existing technologies, this application provides the following implementation method: In some embodiments, such as Figure 1 As shown, a gateway-based script execution method includes: S100: The gateway calls a preset script to perform access control on the received user requests.

[0023] S200a: In response to a user request to pass access control, an idle connection is obtained from the connection pool configured between the gateway process and the database server.

[0024] S300: Verify the user's eligibility to execute based on the user's request.

[0025] S400a: In response to the user's execution qualification being verified, the preset script is sent to the database server through an idle connection, and the business logic of the preset script is executed to obtain the execution result.

[0026] S500: Store the execution result to a non-volatile storage medium to achieve persistence of the execution result.

[0027] Preferably, before the gateway invokes a preset script to perform access control on the received user requests, the process further includes: S000: Loading the gateway configuration and performing service initialization. Specifically, this includes: S010: Configure the backend application server cluster.

[0028] To illustrate, configure the backend application server cluster by executing the following commands: upstream backend_servers { server 10.0.1.100:8080; server 10.0.1.101:8080; The `upstream` directive configures a backend application server cluster named `backend_servers`. This cluster consists of two application servers with IP addresses 10.0.1.100:8080 and 10.0.1.101:8080. These servers provide Java / Python backend application services. The Nginx gateway uses this cluster when it needs to forward requests to these backend Java or Python application services. This configuration provides load balancing for API requests.

[0029] S020: Configure the database server and configure a connection pool for the gateway process and the database server.

[0030] The connection pool contains several idle connections. By configuring the gateway process to maintain idle connections with the database server, the overhead caused by frequently establishing or disconnecting connections with the database server can be reduced.

[0031] To illustrate, the database server is configured by executing the following instructions, and a connection pool is configured between the gateway process and the database server.

[0032] upstream redis_cluster { server 10.0.2.100:6379; server 10.0.2.101:6379; keepalive 100; keepalive_timeout 60s; } A Redis server cluster named redis_cluster was configured using the upstream command. This Redis server cluster has two IP addresses: 10.0.2.100:6379 and 10.0.2.101:6379.

[0033] A connection pool of 100 idle connections is configured between the Nginx gateway process and any Redis server in the Redis server cluster. This allows the Nginx gateway to directly obtain an established idle connection from the connection pool when a new request arrives, avoiding the overhead of frequent TCP connection establishment and termination, and improving performance.

[0034] Additionally, the maximum duration for an idle connection is set to 60 seconds. If a connection remains unused for 60 seconds, it will be closed to release resources.

[0035] S030: Configure application layer service listening and bind domain name.

[0036] To illustrate, configure application layer service listening and perform domain name binding by executing the following commands.

[0037] server { listen 80; server_name activity.example.com; } This configuration enables the Nginx gateway to listen on port "80" and provide services for the domain "activity.example.com".

[0038] The above configuration is a specific example of loading gateway configuration and performing service initialization in the gateway-based script execution method disclosed in this application. This application does not limit the specific content of the configuration objects or values. Those skilled in the art can configure the system to suit their specific execution scenario, following the process of loading gateway configuration and performing service initialization disclosed in this application.

[0039] The gateway described in this application is preferably an Nginx gateway. Nginx is a high-performance, lightweight web server and reverse proxy gateway widely used in high-concurrency internet services. In this application, Nginx, as the access layer gateway, is deployed at the front end of the system, responsible for receiving user requests from clients and performing request routing, access control, and business logic scheduling. By integrating the OpenResty extension framework, Nginx supports direct execution of LUA scripts at the gateway layer, efficiently processing business logic that would otherwise need to be forwarded to the backend application server at the gateway layer, significantly reducing request latency and improving system throughput, making it suitable for large-scale concurrent operation scenarios.

[0040] The preferred script type described in this application is a LUA script. LUA scripts are a lightweight, high-performance embedded scripting language characterized by high execution efficiency, concise syntax, and ease of integration. In this application, the LUA script is embedded in the Nginx gateway to implement the core logic for handling user requests, including access control, user qualification verification, and rule scheduling. Through LUA scripts, atomic operations can be performed directly in Redis at the gateway layer, preventing requests from penetrating to the backend service. It also supports hot updates, allowing dynamic adjustments to the lottery rules without restarting the service, meeting the high requirements for flexibility and real-time performance in event operations.

[0041] Specifically, the gateway invokes a preset script to perform access control on the received user requests, including: S110: Obtain user requests and load preset scripts on the gateway.

[0042] To illustrate, the Nginx gateway loads a pre-defined script upon receiving a user request by executing the following instructions.

[0043] access_by_LUA_block { local redis = require "resty.redis" local red = redis:new() The Nginx gateway enters the "access_by_LUA_block" script, loads the OpenResty resty.redis module, and creates a new Redis instance named red.

[0044] S120: A preset script checks whether the IP address of the client corresponding to the user request is in the blacklist.

[0045] To illustrate, the default script performs a blacklist check on client IP addresses by executing the following commands.

[0046] local client_ip = ngx.var.remote_addr local black_key = "blacklist:ip:" .. client_ip local is_black = red:exists(black_key) if is_black == 1 then ngx.log(ngx.WARN, "Blacklisted IP: ", client_ip) ngx.exit(ngx.HTTP_FORBIDDEN) end Get the client IP address and construct the Redis key name: blacklist:ip: <ip>This function checks if the key exists in the blacklist. If the key exists in the blacklist, the user request is rejected. For example, returning "1" indicates that the IP address has been blocked.

[0047] Preferably, after rejecting the user request, the user request issued by the client IP address is recorded in the alarm log.

[0048] This allows for effective filtering of access from users on the blacklist.

[0049] S130: Global user request frequency limit is implemented by a preset script.

[0050] To illustrate, the default script limits the frequency of global user requests by executing the following instructions.

[0051] local limit_key = "global_rate:" .. ngx.today() local current = red:incr(limit_key) if current == 1 then red:expire(limit_key, 86400) end If current>10000 then ngx.exit(ngx.HTTP_SERVICE_UNAVAILABLE) end } The rate limiting counter is constructed using the current date and its key name is global_rate:YYYY-MM-DD. Whenever a user request is received, an atomic increment operation "incr" is performed on this key to obtain the current request count.

[0052] Preferably, when the first request of the day is received (current == 1), the expiration time of the key is set to 86400 seconds (i.e. 24 hours).

[0053] "10000" is the preset value for the total number of requests per day. If the total number of requests per day exceeds this value, the user's request will be rejected to prevent the system from being overloaded.

[0054] The preset value of the total number of requests per day can be adjusted as needed. "10000" is just an illustrative value set in the embodiment. This application does not limit the value of the total number of requests per day.

[0055] Whenever a user request arrives, the Nginx gateway enters a pre-defined script phase before routing to perform security filtering.

[0056] Preferably, after a user request passes access control, the Nginx gateway distributes the user request to the corresponding server or server cluster for processing based on the request path.

[0057] For user requests whose request path matches the preset business path, the Nginx gateway calls the preset script to respond to the user request.

[0058] The following code is executed as an illustration.

[0059] location = / api / lottery / draw { content_by_LUA_file / usr / local / nginx / LUA / lottery_business.LUA; } When the request path is / api / lottery / draw, the Nginx gateway calls the LUA file: / usr / local / nginx / LUA / lottery_business.LUA to respond to the user request, and performs business logic processing on the user request in the database server.

[0060] The following is a sample code for obtaining an idle connection from the connection pool configured between the gateway process and the database server.

[0061] local ok, err = red:connect("redis_cluster", 6379) If not OK then ngx.log(ngx.ERR, "Failed to get connection from pool: ", err) ngx.say('{"code": 500, "msg": "System busy"}') return end Attempt to connect to the Redis cluster. If the connection fails, log the error and return a system busy message to the client, then terminate the process.

[0062] Optionally, S200b: In response to a user request failing access control, the user request is rejected and terminated.

[0063] Optionally, for requests starting with / static / , the request can be distributed to a CDN (Content Delivery Network) server to improve loading speed. An example code snippet is shown below.

[0064] location / static / { proxy_pass https: / / cdn.example.com / ; } Optionally, for other user requests under the ` / api / ` interface, they are sent to the backend application server cluster. The backend application servers in the cluster process the user requests using load balancing. An illustrative code example is shown below.

[0065] location / api / { proxy_pass http: / / backend_servers; } S300: Verify the user's eligibility to execute based on the user's request.

[0066] The illustrative code is as follows.

[0067] if user_status ~= "active" or daily_draws>= 10 then red:set_keepalive(10000, 100) ngx.say('{"code": 403, "msg": "Insufficient permissions"}') return end Determine if the user's status is normal and the daily lottery draw limit has not been reached (e.g., 10 times); if the conditions are not met, release the connection and return insufficient permissions, then end the process.

[0068] Optionally, the preset script is a resource matching script. Accordingly, the preset script is sent to the database server via an idle connection, and the business logic of the preset script is executed to obtain the execution result, including: S410: Determine the matching resource corresponding to the user request.

[0069] S420: Deduct the quantity of the matching resource corresponding to the user request from the resource inventory of the matching resource.

[0070] S430: Update the number of requests for the user corresponding to the user request.

[0071] S440: The matching resource and the updated number of requests are used as the execution result.

[0072] In some optional embodiments, the resource matching script is specifically a probability matching script, which can generate a random number based on the user request and determine the resource corresponding to the user request based on the random number.

[0073] When the resource matching script is a probability-based matching script, S410: Determine the matching resource corresponding to the user request, specifically including: Generate a random number within a preset range.

[0074] Iterate through the resource list, accumulate resource scores according to weights, and find the first resource whose accumulated resource score is greater than or equal to the random number as the matching result.

[0075] The illustrative code is as follows.

[0076] local rand = math.random() * total_weight local sum = 0 for _, p in ipairs(prize_list) do sum = sum + p.weight if rand <= sum then selected_prize = p.id break end end The code above generates random numbers in the range of 0 to total_weight.

[0077] S420: Deduct the quantity of the matching resource corresponding to the user request from the resource inventory of the matching resources. Example code is as follows.

[0078] local stock_key = "stock:" .. selected_prize local remaining = redis.call('DECR', stock_key) if remaining<0 then redis.call('INCR', stock_key) return {err = 'prize_stock_out'} end Construct the inventory key name corresponding to the prize (e.g., stock:1001).

[0079] Use the "DECR" command to atomically reduce the resource inventory and retrieve the remaining inventory.

[0080] If the remaining inventory is less than 0, it means there is no inventory left. Immediately execute the "INCR" command to roll back the inventory and return "Insufficient Inventory". This avoids over-issuing resources.

[0081] S430: Update the number of requests for the user corresponding to the updated user request, illustrated as follows.

[0082] local user_key = "user_draws:" .. user_id .. ":" .. ngx.date('%Y-%m-%d') redis.call('INCR', user_key) redis.call('EXPIRE', user_key, 86400) S440: The execution result is shown schematically, with the matched resources and the updated number of requests as the result.

[0083] return {suc = true, prize_id = selected_prize, remaining_stock =remaining} Preferably, after sending the preset script to the database server via an idle connection, executing the business logic of the preset script, and obtaining the execution result, the process further includes: S450: The execution result is fed back to the client to complete the response to the user's request, which is illustrated as follows.

[0084] local response = { code = 200, data = { prize_id = result.prize_id, remaining_stock = result.remaining_stock } } ngx.say(cjson.encode(response)) The matching results are encapsulated in JSON format and the response body is output through ngx.say() to inform the front-end user of the matching status.

[0085] S460: Releases the connection used to handle the user request to the connection pool. This is illustrated schematically.

[0086] local keepalive_ok, keepalive_err = red:set_keepalive(10000, 100) if keepalive_ok then ngx.log(ngx.ERR, "Failed to return connection: ", keepalive_err) end Return the current Redis connection to the connection pool so that it can be reused for subsequent requests, avoiding the overhead of duplicate connections.

[0087] Optionally, S400b: In response to the user's execution qualification failing the verification, a failure is recorded and the connection is released to the connection pool.

[0088] Specifically, storing the execution results to a non-volatile storage medium to achieve persistence of the execution results includes: S510: Encapsulate the execution result into a structured message and send the structured message to the message queue; S520: After sending the structured message to the message queue, release the client that sent the user request to complete the execution of the user request; S530: Saves structured messages to non-volatile storage media to achieve persistence of execution results.

[0089] This non-volatile storage medium holds MySQL or other persistent databases. Structured messages are typically saved asynchronously to ensure high performance during script execution.

[0090] It should be understood that, although Figure 1 The steps in the flowchart are shown sequentially as indicated by the arrows, but these steps are not necessarily executed in the order indicated by the arrows. Unless otherwise specified herein, there is no strict order in which these steps are executed, and they can be performed in other orders. Figure 1 At least some of the steps in the process may include multiple sub-steps or multiple stages. These sub-steps or stages are not necessarily completed at the same time, but can be executed at different times. The execution order of these sub-steps or stages is not necessarily sequential, but can be executed in turn or alternately with other steps or at least some of the sub-steps or stages of other steps.

[0091] By implementing the gateway-based script execution method provided in this application, and integrating LUA scripts at the Nginx gateway layer, access control, user frequency limits, blacklist interception, and other logic are pre-processed to prevent requests from penetrating to the backend service. Combined with the Redis connection pool reuse mechanism, network overhead is reduced, enabling a single node to support tens of thousands of QPS with an average response time of less than 5ms. Leveraging Redis's single-threaded nature and the atomic execution capability of LUA scripts, probability calculation, inventory deduction, and user count update operations are uniformly completed in Redis, avoiding data anomalies such as resource over-issuance and duplicate matching. Asynchronous persistence of winning results via message queues allows the main process to return a client response without waiting for database writes, improving user experience. An independent data persistence service consumes messages and writes them to the database, ensuring system decoupling and fault isolation.

[0092] In other embodiments, such as Figure 2 As shown, a gateway-based script execution device includes: The access control module is used by the gateway to call a preset script to perform access control on the received user requests; The connection acquisition module is used to obtain an idle connection from the connection pool configured between the gateway process and the database server in response to a user request to pass access control. The qualification verification module is used to verify a user's eligibility to execute based on the user's request; The business execution module is used to respond to the user's execution qualification being verified, by sending a preset script to the database server through an idle connection, executing the business logic of the preset script, and obtaining the execution result; The result storage module is used to store the execution results to a non-volatile storage medium to achieve the persistence of the execution results.

[0093] By implementing the gateway-based script execution device provided in this application embodiment, and integrating LUA scripts at the Nginx gateway layer, access control, user frequency limits, blacklist interception and other logic are pre-processed to avoid requests penetrating to the backend service; combined with the Redis connection pool reuse mechanism, network overhead is reduced, a single node can support tens of thousands of QPS, and the average response time is less than 5ms.

[0094] For specific limitations regarding the gateway-based script execution device described above, please refer to the limitations regarding the gateway-based script execution method above, which will not be repeated here. Each module in the aforementioned gateway-based script execution device can be implemented entirely or partially through software, hardware, or a combination thereof. These modules can be embedded in or independent of the processor in a computer device in hardware form, or stored in the memory of a computer device in software form, so that the processor can call and execute the operations corresponding to each module.

[0095] In other embodiments, such as Figure 3 As shown, a computer device includes a memory, a processor, and a gateway-based script execution program stored in the memory and executable on the processor. When the processor executes the gateway-based script execution program, it implements the gateway-based script execution method described above. Specifically, it includes: S100: The gateway invokes a preset script to perform access control on the received user requests; S200a: In response to a user request to pass access control, an idle connection is obtained from the connection pool configured between the gateway process and the database server; S300: Verify the user's eligibility to execute based on the user's request; S400a: In response to the user's execution qualification being verified, the preset script is sent to the database server through an idle connection, and the business logic of the preset script is executed to obtain the execution result; S500: Store the execution result to a non-volatile storage medium to achieve persistence of the execution result.

[0096] By implementing the gateway-based script execution device provided in this application embodiment, and integrating LUA scripts at the Nginx gateway layer, access control, user frequency limits, blacklist interception and other logic are pre-processed to avoid requests penetrating to the backend service; combined with the Redis connection pool reuse mechanism, network overhead is reduced, a single node can support tens of thousands of QPS, and the average response time is less than 5ms.

[0097] In other embodiments, a computer-readable storage medium stores a gateway-based script execution program, which, when executed by a processor, implements the gateway-based script execution method described above. Specifically, it includes: S100: The gateway invokes a preset script to perform access control on the received user requests; S200a: In response to a user request to pass access control, an idle connection is obtained from the connection pool configured between the gateway process and the database server; S300: Verify the user's eligibility to execute based on the user's request; S400a: In response to the user's execution qualification being verified, the preset script is sent to the database server through an idle connection, and the business logic of the preset script is executed to obtain the execution result; S500: Store the execution result to a non-volatile storage medium to achieve persistence of the execution result.

[0098] By implementing the readable storage medium provided in the embodiments of this application, and by integrating LUA scripts into the Nginx gateway layer, access control, user frequency limits, blacklist interception and other logic are pre-processed to avoid requests penetrating to the backend service; combined with the Redis connection pool reuse mechanism, network overhead is reduced, a single node can support tens of thousands of QPS, and the average response time is less than 5ms.

[0099] In other embodiments, a computer program product includes a computer program that, when executed by a processor, implements the gateway-based script execution method described in the first aspect. Specifically, it includes: S100: The gateway invokes a preset script to perform access control on the received user requests; S200a: In response to a user request to pass access control, an idle connection is obtained from the connection pool configured between the gateway process and the database server; S300: Verify the user's eligibility to execute based on the user's request; S400a: In response to the user's execution qualification being verified, the preset script is sent to the database server through an idle connection, and the business logic of the preset script is executed to obtain the execution result; S500: Store the execution result to a non-volatile storage medium to achieve persistence of the execution result.

[0100] Implementing the computer program product provided in this application embodiment, by integrating LUA scripts into the Nginx gateway layer, preprocesses logic such as access control, user frequency limits, and blacklist interception, avoiding requests from penetrating to the backend service; combined with the Redis connection pool reuse mechanism, it reduces network overhead, and a single node can support tens of thousands of QPS with an average response time of less than 5ms.

[0101] By implementing the gateway-based script execution method, apparatus, device, and readable storage medium provided in this application, and integrating LUA scripts at the Nginx gateway layer, access control, user frequency limits, blacklist interception, and other logic are pre-processed to prevent requests from penetrating to backend services. Combined with the Redis connection pool reuse mechanism, network overhead is reduced, enabling a single node to support tens of thousands of QPS with an average response time of less than 5ms. Utilizing Redis's single-threaded nature and LUA script's atomic execution capability, probability calculation, inventory deduction, and user count update operations are uniformly completed in Redis, avoiding data anomalies such as resource over-issuance and duplicate matching. Asynchronous persistence of winning results via message queues allows the main process to return a client response without waiting for database writes, improving user experience. An independent data persistence service consumes messages and writes them to the database, ensuring system decoupling and fault isolation.

[0102] Those skilled in the art will further recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the components and steps of the various examples have been generally described in terms of functionality in the foregoing description. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.

[0103] Specifically, according to embodiments of this application, the processes described above with reference to the flowcharts can be implemented as steps controlled by a computer software program. For example, embodiments of this application include a computer program product comprising a computer program loaded on a computer-readable medium, the computer program containing program code for performing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network via a communication device, or installed from memory, or installed from ROM. When the computer program is executed by an external processor, it performs the functions defined in the methods of embodiments of this application.

[0104] It should be noted that the computer-readable medium in the embodiments of this application can be a computer-readable signal medium or a computer-readable storage medium, or any combination of the two. A computer-readable storage medium can be, for example,—but not limited to—an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples of a computer-readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination thereof. In the embodiments of this application, a computer-readable storage medium can be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, apparatus, or device. In the embodiments of this application, a computer-readable signal medium can include a data signal propagated in baseband or as part of a carrier wave, carrying computer-readable program code. Such propagated data signals can take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. A computer-readable signal medium may also be any computer-readable medium other than a computer-readable storage medium, which can send, propagate, or transmit a program for use by or in connection with an instruction execution system, apparatus, or device. The program code contained on the computer-readable medium can be transmitted using any suitable medium, including but not limited to: wires, optical fibers, RF (Radio Frequency), etc., or any suitable combination thereof.

[0105] The aforementioned computer-readable medium may be included in the aforementioned server; or it may exist independently and not assembled into the server. The aforementioned computer-readable medium carries one or more programs that, when executed by the server, cause the server to: in response to detecting that the peripheral mode of the terminal is not activated, acquire the frame rate of the application on the terminal; when the frame rate meets the screen-off condition, determine whether the user is acquiring the terminal's screen information; and in response to the determination that the user is not acquiring the terminal's screen information, control the screen to enter an immediate dimming mode.

[0106] Computer program code for performing the operations of the embodiments of this application can be written in one or more programming languages ​​or a combination thereof. Programming languages ​​include object-oriented programming languages—such as Java, Smalltalk, and C++—and conventional procedural programming languages—such as the "C" language or similar programming languages. The program code can be executed entirely on the user's computer, partially on the user's computer, as a standalone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving remote computers, the remote computer can be connected to the user's computer via any type of network—including a local area network (LAN) or a wide area network (WAN)—or can be connected to an external computer (e.g., via the Internet using an Internet service provider).

[0107] The various embodiments in this specification are described in a progressive manner. Similar or identical parts between embodiments can be referred to mutually. Each embodiment focuses on describing the differences from other embodiments. In particular, for system or system embodiments, since they are basically similar to method embodiments, the description is relatively simple, and relevant parts can be referred to the descriptions in the method embodiments. The systems and system embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs. Those skilled in the art can understand and implement this without creative effort.

[0108] The technical solutions provided in this application have been described in detail above. Specific examples have been used to illustrate the principles and implementation methods of this application. The descriptions of the above embodiments are only for the purpose of helping to understand the methods and core ideas of this application. Furthermore, those skilled in the art will recognize that, based on the ideas of this application, there will be changes in the specific implementation methods and application scope. Therefore, the content of this specification should not be construed as a limitation of this application.

[0109] The foregoing has provided a detailed description of the gateway-based script execution method, device, and storage medium provided in this application. Specific examples have been used to illustrate the principles and implementation methods of this application. These embodiments are merely preferred embodiments of this application, intended to aid in understanding the method and its core ideas, and are not intended to limit the scope of this application. It should be noted that for those skilled in the art, any modifications, equivalent substitutions, or improvements made within the spirit and principles of this application without departing from its principles are also within the protection scope of the claims of this application.< / ip>

Claims

1. A gateway-based script execution method, characterized in that, include: The gateway invokes a preset script to perform access control on received user requests; In response to the user request passing access control, an idle connection is obtained from the connection pool configured between the gateway process and the database server; Verify the user's eligibility to execute based on the user request; In response to the user's qualification being verified, the preset script is sent to the database server through the idle connection, and the business logic of the preset script is executed to obtain the execution result; The execution result is stored in a non-volatile storage medium to achieve persistence of the execution result.

2. The gateway-based script execution method according to claim 1, characterized in that, Before the gateway invokes a preset script to perform access control on the received user requests, the process also includes: Configure a backend application server cluster; Configure the database server and configure a connection pool for the gateway process and the database server; Configure application layer service listening and bind domain name.

3. The gateway-based script execution method according to claim 1, characterized in that, The step of the gateway invoking a preset script to perform access control on the received user requests includes: Upon receiving a user request, the gateway loads a preset script; The preset script checks whether the IP address of the client corresponding to the user request is in the blacklist; The preset script is used to limit the frequency of global user requests.

4. The gateway-based script execution method according to claim 1, characterized in that, If the user request fails to pass access control, the user request is rejected and terminated.

5. The gateway-based script execution method according to claim 1, characterized in that, The preset script is a resource matching script. Sending the preset script to the database server via the idle connection and executing its business logic to obtain the execution result includes: Determine the matching resource corresponding to the user request; The quantity of the matching resource corresponding to the user request is deducted from the resource inventory of the matching resource; Update the request count for the user corresponding to the aforementioned user request; The matched resources and the updated number of requests are used as the execution result.

6. The gateway-based script execution method according to claim 1, characterized in that, After sending the preset script to the database server via the idle connection, executing the business logic of the preset script, and obtaining the execution result, the process further includes: The execution result is then sent back to the client to complete the response to the user's request; Release the connection used to process the user request to the connection pool.

7. The gateway-based script execution method according to claim 1, characterized in that, The step of storing the execution result to a non-volatile storage medium to achieve persistence of the execution result includes: The execution result is encapsulated into a structured message, and the structured message is sent to a message queue; After sending the structured message to the message queue, the client that sent the user request is released to complete the execution of the user request; The structured message is saved to a non-volatile storage medium to achieve persistence of the execution result.

8. A gateway-based script execution device, characterized in that, include: The access control module is used by the gateway to call a preset script to perform access control on the received user requests; The connection acquisition module is used to obtain an idle connection from the connection pool configured between the gateway process and the database server in response to the user request to pass access control. The qualification verification module is used to verify the user's qualification to execute based on the user request; The business execution module is used to respond to the user's execution qualification passing the verification, by sending the preset script to the database server through the idle connection, executing the business logic of the preset script, and obtaining the execution result; The result storage module is used to store the execution result to a non-volatile storage medium to achieve the persistence of the execution result.

9. A computer device, characterized in that, The method includes a memory, a processor, and a gateway-based script execution program stored in the memory and executable on the processor. When the processor executes the gateway-based script execution program, it implements the gateway-based script execution method according to any one of claims 1 to 7.

10. A computer-readable storage medium, characterized in that, It stores a gateway-based script execution program, which, when executed by a processor, implements the gateway-based script execution method according to any one of claims 1 to 7.