Method for realizing high concurrency of single machine script

By constructing a script execution environment with shared memory and context, the problem of low concurrency in script execution under common technology stacks is solved, and high-concurrency script execution and memory efficiency are improved, supporting high concurrency capabilities of multiple scripting languages.

CN114924894BActive Publication Date: 2025-11-28HANGZHOU INSTRUCTION SET INTELLIGENT TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202210639161.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-06-07
Publication Date
2025-11-28
Estimated Expiration
2042-06-07

AI Technical Summary

Technical Problem

Existing technologies struggle to achieve high-concurrency script execution on common technology stacks such as JavaScript and Python. Lua scripts have a high learning curve, and a single server cannot withstand high concurrency pressure, leading to script execution crashes and freezes.

Method used

By constructing a script execution environment with shared memory, shared directories and files, and shared context, scripts can run synchronously in independent contexts. The shared execution environment reduces memory consumption, and a script caching mechanism is used to improve execution efficiency.

Benefits of technology

It achieves high-concurrency script execution capability on a single server, increasing it to over 10,000 QPS per server, supports high-concurrency execution of multiple scripting languages, and reduces memory usage and learning costs.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114924894B_ABST
    Figure CN114924894B_ABST
Patent Text Reader

Abstract

The application discloses a kind of methods for realizing script single machine high concurrency, including the following steps: step one, start server, build script running environment;Step two, multiple requests are sent to server in client, and server receives multiple requests and processes the script in each request;Step three, server synchronously puts the script in multiple requests into script running environment, synchronously runs multiple scripts in shared context, and returns data to client according to the independent context information corresponding to each script.The method for realizing script single machine high concurrency of the application adopts shared memory, shared directory and file, shared context and other contents for script, to ensure that script can run in independent context in shared space.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to a script concurrent method, more particularly to a method for realizing high concurrency of a single script machine. BACKGROUND

[0002] Script technology is a technology for responding to the need of dynamically loading code for part of the logic, rather than compiling the code in the program. Using script technology can respond to the scene where most business logic is not fixed and needs to be frequently changed. In actual application, only by downloading a new script from the server can the change of business logic be completed.

[0003] However, due to the characteristics of script technology, it is much slower than compiled execution, and there are physical environment limitations, such as memory requirements. As the number of executed scripts increases, a large amount of memory is occupied, thereby directly reducing the concurrency of the script. At the same time, in general cases, scripts are designed to run in single thread, that is, when multiple scripts run, they will be in first-come-first-served order and cannot be run simultaneously.

[0004] Currently, OpenResty built-in LuaJIT can achieve high concurrency of Lua scripts, but the learning cost of Lua scripts is high. In the commonly used language technology system, js, python, java, etc. are included, but lua is not included. Therefore, under the prior art, to achieve high concurrency processing of script languages, only the above Lua-related technology stack can be used, which is basically not universal. In the commonly used technology stack, such as js, python, etc., it is difficult for Lua to have a place, and the cost of additional learning required by the development or implementation personnel is high. And under the existing technical conditions, it is difficult to realize that a single server can withstand high-intensity concurrent pressure of QPS 5000 or more. For complex scripts, even when each request carries different script code, its pressure bearing capacity will further decrease. Under the condition that the number of servers is limited, the server configuration is limited, and the script request business is complex, it will not be able to withstand high concurrent pressure, and various problems such as script execution crash, execution result exception, execution deadlock, and no return will occur. SUMMARY

[0005] In view of the deficiencies of the prior art, the purpose of the present application is to provide a method for enabling a script code to support high concurrency in a scenario requiring dynamic execution of the script code, and completely solving the problems of low script language execution capability and poor concurrency.

[0006] To achieve the above purpose, the present application provides the following technical scheme: a method for realizing high concurrency of a single script machine, comprising the following steps:

[0007] Step 1: Start the server and build a script running environment;

[0008] Step two, the client sends multiple requests to the server, the server receives multiple requests and processes the script in each request;

[0009] Step three, the server puts the script in multiple requests into the script running environment, runs multiple scripts in the shared context, and returns data to the client according to the independent context information of each script.

[0010] As a further improvement of the application, the specific steps of constructing the script running environment are as follows: Step one, constructing a shared directory and file;

[0011] Step two, constructing a shared memory;

[0012] Step three, constructing a shared context data, and completing the construction of the script running environment.

[0013] As a further improvement of the application, the server in step one also loads script cache data after starting, judges whether the script cache hits the script to be executed, if it hits, does not process and runs the script in the shared context, if it does not hit, processes and runs the script in the shared context.

[0014] As a further improvement of the application, the specific steps of processing the script in each request in step two are as follows:

[0015] Step two, analyze the script in each request, and generate independent contexts according to each script;

[0016] Step two, establish a script data sandbox according to the independent context generated in step two one.

[0017] As a further improvement of the application, the specific steps of judging whether the script cache hits the script to be executed in step one are as follows: when the server accepts a script request, it will first perform a hash operation on the script code, and use the operation result to match the cache, if it hits the cache, it will directly read the compiled script from the cache and execute, if it does not hit the cache, it will compile the script code, write the compiled result into the cache, and then execute the compiled script.

[0018] The beneficial effects of the present application adopt the shared memory, shared directory and file, shared context and other contents for script construction, ensure that the script can run in the shared space with independent context, through this mechanism, no matter how many scripts to be executed, they all use a common running environment, that is, the running environment itself only occupies a memory, and will not increase the memory occupation with the increasing of the executed scripts. At the same time, for the individual script, the data isolation of the independent context is included, so that each script can independently maintain its own data. BRIEF DESCRIPTION OF DRAWINGS

[0019] Figure 1 The flow chart of the method for realizing the high concurrency of the script single machine of the present application. DETAILED DESCRIPTION

[0020] The present application will be further described in detail below with the embodiments given in the accompanying drawings.

[0021] Referring to Figure 1 The method for realizing the high concurrency of the script single machine of the present application includes the following steps: step one, starting the service end, constructing the script running environment;

[0022] Step two, the client sends multiple requests to the service end, and the service end processes the script in each request after receiving the multiple requests;

[0023] Step three, the service end synchronously puts the script in the multiple requests into the script running environment, synchronously runs the multiple scripts in the shared context, and returns the data to the client according to the independent context information of each script, and the specific steps of step one for constructing the script running environment are as follows:

[0024] Step one, constructing the shared directory and file;

[0025] Step two, constructing the shared memory;

[0026] Step three, constructing the shared context data, completing the script running environment construction, and the specific steps of step two for processing the script in each request are as follows:

[0027] Step two one, analyzing the script in each request, and generating the independent context according to each script;

[0028] In the process of using the method of the embodiment, only the above steps need to be executed in sequence, and therefore, the embodiment ensures that the scripts can run in the shared space with independent contexts by using the shared memory, shared directory and file, and shared context for the scripts. For example, there are script A and script B, both of which contain variable X and both of which call system function FUNC, the value of X in script A can be 1, and the value of X in script B can be 2, and they do not conflict with each other, and when the function FUNC is called, it is read from the shared memory, that is, the two scripts call the same system function, and by this mechanism, no matter how many scripts need to be executed, they all use a common running environment, that is, the running environment itself only occupies one memory, and will not increase the memory occupation with the increase of the executed scripts. At the same time, for the individual scripts, the data isolation of the independent context, the operation of script A will not affect script B, and therefore each script can independently maintain its own data.

[0029] As a specific embodiment of the improvement, the server in step one also loads script cache data after starting, judges whether the script cache hits the script to be executed, if it hits, does not process and runs the script in the shared context, if it does not hit, processes and then runs the script in the shared context, and the specific steps of judging whether the script cache hits the script to be executed in step one are that when the server receives a request of a script, the script code is first subjected to a hash operation, and the operation result is used to match the cache, if it hits the cache, the compiled script is directly read from the cache and executed, if it does not hit the cache, the script code is compiled, the compilation result is written into the cache, and then the compiled script is executed, so that the compiled script content is saved to increase the execution efficiency.

[0030] In summary, the method of the embodiment does not judge the type of the script language, and any script language is treated equally, and in the actual production scene, the custom language script can also be perfectly supported. The application can improve the pressure bearing capacity of the script execution to more than 10,000 QPS per server.

[0031] The above only describes the preferred embodiments of the application, and the protection scope of the application is not limited to the above embodiments, and any technical solution falling within the idea of the application belongs to the protection scope of the application. It should be noted that for ordinary technical personnel in the technical field, some improvements and decorations without departing from the principle of the application are also considered as the protection scope of the application.

Claims

1. A method for achieving high concurrency on a single machine using a script, characterized in that: Includes the following steps: Step 1: Start the server, load the script cache data, and determine if the script to be executed is found in the cache. If it is found, no processing is done, and the script is run in the shared context. If it is not found, processing is performed, and the script is run in the shared context. The specific steps are as follows: When the server receives a script request, it first performs a hash operation on the script code and uses the result to match it in the cache. If the cache is hit, the compiled script is directly read from the cache and executed. If the cache is not hit, the script code is compiled, the compilation result is written to the cache, and then the compiled script is executed. The specific steps for building the script execution environment are as follows:

1. Build shared directories and files; 2. Build shared memory; 3. Build shared context data, thus completing the script execution environment construction. Step 2: The client sends multiple requests to the server. After receiving the multiple requests, the server processes the scripts contained in each request. The specific steps are as follows: analyze the scripts contained in each request, generate an independent context based on each script, and establish a script data sandbox based on the generated independent context. Step 3: The server synchronously puts the scripts contained in multiple requests into the script execution environment, runs multiple scripts synchronously in the shared context, and returns data to the client according to the independent context information corresponding to each script.

Citation Information

Patent Citations

  • Execution method and device for script codes in application program

    CN111427622A

  • Method and System for Script Processing for Web-Based Applications

    US20110289484A1