Business execution method and device, equipment, medium and program product
By executing the loop rounds of the business logic to be looped in parallel within the database system, the problem of low efficiency under the serial execution method is solved, and more efficient business execution and improved CPU utilization are achieved.
Patent Information
- Application Number
- CN202410727957.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-05
- Publication Date
- 2025-12-05
AI Technical Summary
In existing technologies, business execution efficiency based on database systems is relatively low, especially in the serial execution mode, which leads to low efficiency in accounting business waiting for cyclic business logic.
The parallelism N of the business logic to be looped is obtained from the backend server of the target database system, and it is divided into N loop round groups. These loop round groups are executed in parallel by N worker processes to achieve parallel business execution.
It improved business execution efficiency and increased the CPU utilization of the backend server.
Smart Images

Figure CN121070535A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] Embodiments of the present application relate to the technical field of database, and particularly relate to a business execution method and device, equipment, medium and program product. BACKGROUND
[0002] Business scenarios based on database systems are common. For example, the accounting business in the financial industry is a business scenario based on a database system, wherein order data is stored in the database system, a background server corresponding to the database system can query a table structure corresponding to the order data, determine an accounting rule based on the table structure, and further, the background server can loop through all the order data, calculate each item of order data based on the above accounting rule, obtain a bill corresponding to each item of order data, and finally store the bills corresponding to the order data in the form of a table in the database system, that is, implement bill entry.
[0003] Currently, a serial execution mode is used for the to-be-looped business logic. Taking the above accounting business as an example, the background server first reads order data in a first row of a table structure corresponding to the order data, calculates and enters the order data in the row using an accounting rule, reads order data in a second row of the table structure corresponding to the order data, calculates and enters the order data in the row using the accounting rule, and so on, until order data in a last row of the table structure corresponding to the order data is read and calculated and entered using the accounting rule. However, this mode results in low business execution efficiency. SUMMARY
[0004] Embodiments of the present application provide a business execution method, device, equipment, medium and program product, thereby improving the business execution efficiency.
[0005] In a first aspect, the embodiments of the present application provide a business execution method, which is executed by a background server corresponding to a target database system, and the method comprises: obtaining a parallelism N of to-be-looped business logic of a target business; wherein N is a positive integer; dividing M loop rounds of the to-be-looped business logic based on the parallelism N of the to-be-looped business logic, to obtain N loop round groups of the to-be-looped business logic; wherein M is an integer greater than or equal to N; and executing the N loop round groups of the to-be-looped business logic in parallel.
[0006] In a second aspect, an embodiment of the present application provides a service execution apparatus, comprising: a communication module and a processing module; the communication module is configured to obtain a parallelism N of to-be-looped service logic of a target service; wherein N is a positive integer; the processing module is configured to divide M loop rounds of the to-be-looped service logic based on the parallelism N of the to-be-looped service logic, to obtain N loop round groups of the to-be-looped service logic; wherein M is an integer greater than or equal to N; and the processing module is further configured to execute the N loop round groups of the to-be-looped service logic in parallel.
[0007] In some implementable manners, the communication module is specifically configured to obtain the parallelism N of the to-be-looped service logic through a target background sub-process in a target database system.
[0008] In some implementable manners, the communication module is specifically configured to receive execution code of the target service or receive a calling statement through the target background sub-process; wherein the calling statement is used to call a service execution function of the target service; and the execution code or the calling statement carries the parallelism N of the to-be-looped service logic.
[0009] In some implementable manners, the processing module is specifically configured to divide, based on the parallelism N of the to-be-looped service logic, the M loop rounds of the to-be-looped service logic by the target background sub-process in the target database system, to obtain the N loop round groups of the to-be-looped service logic.
[0010] In some implementable manners, the processing module is specifically configured to divide, based on the parallelism N of the to-be-looped service logic, the M loop rounds of the to-be-looped service logic by the target background sub-process when the target background sub-process executes the to-be-looped service logic, to obtain the N loop round groups of the to-be-looped service logic.
[0011] In some implementable manners, the processing module is specifically configured to: set, based on the parallelism N of the to-be-looped service logic, N initial loop round groups by the target background sub-process; and distribute, by the target background sub-process, the M loop rounds of the to-be-looped service logic to the N initial loop round groups in turn, to obtain the N loop round groups of the to-be-looped service logic.
[0012] In some implementable manners, before the processing module executes the N loop round groups of the to-be-looped service logic in parallel, the communication module or the processing module is further configured to trigger, by the target background sub-process in the target database system, a parent process in the target database system to create N worker processes; and the processing module is further configured to distribute, by the target background sub-process, respective corresponding loop round groups to the N worker processes; correspondingly, the processing module is specifically configured to execute, by the N worker processes, the respective corresponding loop round groups in parallel.
[0013] In some implementable manners, the communication module is specifically configured to: send a notification message to the parent process by the target background sub-process; and the parent process creates the N worker processes in response to the notification message.
[0014] In some implementable manners, the processing module is specifically configured to: dispatch a worker process creation function by the target background sub-process, so that the parent process creates the N worker processes.
[0015] In some implementable manners, before the processing module executes the respective corresponding loop round groups by the N worker processes in parallel, the processing module is further configured to: apply, by the parent process, shared memory for the N worker processes; allocate, by the parent process, memory spaces in the shared memory to the N worker processes respectively; the communication module is further configured to: notify, by the parent process, the respective corresponding memory spaces to the N worker processes respectively; and notify, by the parent process, the target background sub-process of the respective corresponding memory spaces of the N worker processes; and the processing module is further configured to: write, by the target background sub-process, the respective corresponding loop round groups of the N worker processes into the respective corresponding memory spaces of the N worker processes; and read, by the N worker processes, the respective corresponding loop round groups from the respective corresponding memory spaces respectively.
[0016] In some implementable manners, the processing module is specifically configured to: write, by the target background sub-process, the respective corresponding loop round groups of the N worker processes into the respective corresponding memory spaces of the N worker processes in the form of asynchronous message queues.
[0017] In some implementable manners, before the processing module executes the respective corresponding loop round groups by the N worker processes in parallel, the processing module is further configured to: obtain, by the target background sub-process, context data of the to-be-looped business logic; wherein, if there is a first business logic, the first business logic is a business logic located before the to-be-looped business logic in the business logic of the target business, the context data comprises: the associated data of the first business logic and the to-be-looped business logic; if there is no first business logic, the context data comprises: the to-be-looped business logic; serialize, by the target background sub-process, the context data to obtain serialized data; and store, by the target background sub-process, the serialized data into shared memory; correspondingly, the processing module is specifically configured to: read, by the N worker processes, the serialized data in the shared memory; deserialize, by the N worker processes, the serialized data to obtain the context data; and execute, by the N worker processes, the respective corresponding loop round groups in parallel based on the context data.
[0018] In some implementable manners, the processing module is specifically configured to: obtain, by the target background sub-process, the data types and corresponding values of each variable in the context data; and group, by the target background sub-process, the data types and corresponding values of each variable into serialized data.
[0019] In some implementable manners, the processing module is specifically configured to: the N worker processes construct the data structure of each variable based on the data type and the corresponding value of each variable; and the context data comprises the data structure of each variable.
[0020] In some implementable manners, after the processing module executes the respective corresponding group of loop rounds by the N worker processes in parallel, the communication module is further configured to: after the N worker processes execute the respective corresponding group of loop rounds, the N worker processes notify the target background sub-process that the respective corresponding group of loop rounds has been executed by the N worker processes.
[0021] In some implementable manners, the processing module is further configured to: if there is a second business logic, the second business logic is a business logic in the business logic of the target business located after the to-be-looped business logic, the target background sub-process executes the second business logic by the target background sub-process after determining that the N groups of loop rounds have been executed.
[0022] In a third aspect, an electronic device is provided, comprising: a processor and a memory, the memory being configured to store a computer program, and the processor being configured to invoke and run the computer program stored in the memory to execute the method in the first aspect or the implementation manners thereof.
[0023] In a fourth aspect, a computer readable storage medium is provided, configured to store a computer program, and the computer program causes a computer to execute the method in the first aspect or the implementation manners thereof.
[0024] In a fifth aspect, a computer program product is provided, comprising computer program instructions, and the computer program instructions cause a computer to execute the method in the first aspect or the implementation manners thereof.
[0025] In a sixth aspect, a computer program is provided, and the computer program causes a computer to execute the method in the first aspect or the implementation manners thereof.
[0026] According to the technical solutions provided in the present application, since the N groups of loop rounds can be executed by the N worker processes in parallel, the business execution method provided in the embodiments of the present application can help to improve the business execution efficiency compared with the business execution method provided in the related art. In addition, the CPU utilization of the background server can also be improved. BRIEF DESCRIPTION OF DRAWINGS
[0027] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings needed in the embodiment description will be briefly introduced. Obviously, the drawings in the following description are only some embodiments of the present application, and other drawings can also be obtained by those skilled in the art without any creative effort.
[0028] Figure 1 A system architecture diagram related to an embodiment of the present application;
[0029] Figure 2 A flowchart of a service execution method provided by an embodiment of the present application;
[0030] Figure 3 A schematic diagram of a service execution method of a dual-core background server provided by an embodiment of the present application;
[0031] Figure 4 A schematic diagram of obtaining parallelism provided by an embodiment of the present application;
[0032] Figure 5 A schematic diagram of a target background sub-process notifying a parent process to create a worker process provided by an embodiment of the present application;
[0033] Figure 6 A schematic diagram of a correlation between the number of worker processes and the parallelism of to-be-circulated service logic provided by an embodiment of the present application;
[0034] Figure 7 A schematic diagram of a shared memory provided by an embodiment of the present application;
[0035] Figure 8 Another schematic diagram of a shared memory provided by an embodiment of the present application;
[0036] Figure 9 A schematic diagram of a service execution method example provided by an embodiment of the present application;
[0037] Figure 10 A schematic diagram of a service execution apparatus 1000 provided by an embodiment of the present application;
[0038] Figure 11 A schematic block diagram of an electronic device 1100 provided by an embodiment of the present application. DETAILED DESCRIPTION
[0039] The technical solutions in the embodiments of the present application will be described clearly and completely below with reference to the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, rather than all the embodiments of the present application. Based on the embodiments in the present application, all other embodiments obtained by a person of ordinary skill in the art without creative work fall within the protection scope of the present application.
[0040] It should be noted that the terms "first", "second", and the like in the description and in the claims of the present application and the above-described drawings are used to distinguish similar objects, and do not necessarily indicate a specific order or sequence. It should be understood that the data thus used can be interchanged under appropriate circumstances, so that the embodiments of the application described herein can be implemented in an order other than that illustrated or described herein. In addition, the terms "include" and "have" and any variations thereof are intended to cover non-exclusive inclusion, for example, a process, method, system, product or server including a series of steps or units does not necessarily have to be limited to those steps or units clearly listed, but can include other steps or units not clearly listed or inherent to these processes, methods, products or devices.
[0041] In the embodiments of the present application, the term "module" or "unit" refers to a computer program or a part of a computer program with a predetermined function, and works together with other related parts to achieve a predetermined target, and can be implemented entirely or partially by using software, hardware (such as a processing circuit or a memory) or a combination thereof. Similarly, one processor (or multiple processors or memories) can be used to implement one or more modules or units. In addition, each module or unit can be a part of an integral module or unit that includes the functions of the module or unit.
[0042] The embodiments of the present application can relate to cloud technology, and in particular can relate to cloud computing and databases, but are not limited thereto.
[0043] Cloud technology refers to a kind of hosting technology that unifies a series of resources such as hardware, software, network in a wide area network or a local area network to realize data calculation, storage, processing and sharing.
[0044] Cloud technology is a general term for network technology, information technology, integration technology, management platform technology, application technology and the like based on cloud computing business model application, can form a resource pool, and is used on demand, flexible and convenient. Cloud computing technology will become an important support. The background service of the technical network system needs a large amount of calculation and storage resources, such as video websites, picture websites and more portals. With the high development and application of the Internet industry, every item may have its own identification mark in the future, and needs to be transmitted to the background system for logical processing. Different levels of data will be processed separately, and various industry data need strong system support, which can only be realized through cloud computing.
[0045] Cloud computing is a computing model that distributes computing tasks on a resource pool composed of a large number of computers, so that various application systems can obtain computing power, storage space and information services according to needs. The network providing resources is called "cloud". The resources in the "cloud" are infinitely expandable to users and can be obtained at any time, used on demand, expanded at any time, and paid according to use.
[0046] As a basic capability provider of cloud computing, a cloud computing resource pool (referred to as a cloud platform, generally referred to as Infrastructure as a Service (IaaS)) platform will be established, and various types of virtual resources will be deployed in the resource pool for external customers to select and use. The cloud computing resource pool mainly includes: computing devices (virtualized machines containing operating systems), storage devices, network devices.
[0047] According to logical function division, the Platform as a Service (PaaS) layer can be deployed on the IaaS layer, and the Software as a Service (SaaS) layer can be deployed on the PaaS layer, or the SaaS can be directly deployed on the IaaS. PaaS is a platform for software running, such as databases, web containers, etc. SaaS is various business software, such as web portal websites, SMS mass senders, etc. Generally speaking, SaaS and PaaS are upper layers relative to IaaS.
[0048] Database (Database), in short, can be regarded as an electronic file cabinet - a place to store electronic files, users can add, query, update, delete and other operations on the data in the file. So-called "database" is a collection of data stored together in a certain way, shared by multiple users, with as little redundancy as possible, and independent of application programs.
[0049] A database management system (DBMS) is a computer software system designed for managing databases, typically with basic functions such as storage, retrieval, security, backup, and more. DBMS can be classified based on the database model it supports, such as relational or XML, or based on the type of computer it supports, such as server clusters or mobile phones, or based on the query language it supports, such as SQL or XQuery, or based on performance focus, such as maximum size or maximum speed, or other ways. Regardless of the classification, some DBMS can cross categories, such as supporting multiple query languages at the same time.
[0050] The relevant knowledge related to the present application will be described below:
[0051] I. A database system (DBS) is a software system used to store, manage, retrieve, and update large amounts of data. It is composed of multiple components that work together to provide efficient, reliable, and secure access to data.
[0052] II. A distributed database system (DDBS) is a database system that is physically dispersed but logically centralized. The system stores data on multiple different physical nodes, connects these nodes through a computer network, and is managed by one or more database management systems.
[0053] III. TDSQL PostgreSQL is a distributed database system independently developed by Tencent. TDSQL PostgreSQL combines high scalability, high SQL compatibility, complete distributed transaction support, multi-level disaster recovery, and multi-dimensional resource isolation, and adopts a shared-nothing cluster architecture to provide a complete solution for disaster recovery, backup, recovery, detection, security, and auditing, suitable for gigabyte (GB) to petabyte (PB) level of massive hybrid transactional analytical processing (HTAP) scenarios.
[0054] IV. PLpgSQL, is a procedural programming language for TDSQL PostgreSQL database system, which allows to write complex functions and stored procedures. PLpgSQL is an extension of SQL language, providing control structures, variable declarations and exception handling, etc. programming language features.
[0055] V. The parent process (Postmaster process) is the main process of PostgreSQL (including TDSQL PostgreSQL), which is also the parent process. It is responsible for initializing the database system and creating necessary auxiliary processes and detecting client connections when the server starts. Once the parent process starts, it allocates shared memory, opens necessary file descriptors, and sets up other system resources to prepare for the running of background child processes and other processes. The parent process is also responsible for detecting client connection requests and creating (forking) new background child processes to handle these requests when they are received.
[0056] VI. The background (Backend) child process is a child process created by the parent process, which is responsible for receiving and executing command requests issued by clients (such as SQL commands, function calls, etc.). Whenever a client connects to the database, the parent process will create a new background child process for it, which will exist until the client actively closes the database connection or encounters an exception and ends running. Among them, the background child process is the main working unit of the database to handle client requests, which can execute SQL queries, update databases, return results, etc.
[0057] VII. The worker (Worker) process is a general background process framework in PostgreSQL, which allows users to create and execute custom background tasks. These tasks can include asynchronous task processing, periodic tasks, data maintenance, etc.
[0058] VIII. Asynchronous message queue is a commonly used software architecture pattern, which establishes an intermediate layer between different systems or modules to deliver messages, achieving decoupling, asynchronous processing and peak shaving between systems. This pattern mainly relies on the producer-consumer model. Among them, the producer: the message sender in the message queue. It is responsible for creating and sending messages to the message queue for consumers to consume. The producer is usually associated with specific business logic, generating messages according to business needs and sending them to the message queue. The producer sends messages to a specific queue or topic, and the message queue will deliver the message to one or more consumers for processing. Consumer: message receiver in the message queue. It is responsible for obtaining messages from the message queue and processing them.
[0059] The technical problems, invention concepts and system architecture to be solved by the embodiments of the present application will be described below:
[0060] As described above, the current method for the to-be-circulated business logic is serial execution, which results in low business execution efficiency.
[0061] To solve the above technical problems, the embodiment of the present application proposes a business parallel execution method, including: a background server corresponding to a target database system acquires a parallelism N of to-be-circulated business logic of a target business; wherein N is a positive integer; based on the parallelism N of the to-be-circulated business logic, M circulation rounds of the to-be-circulated business logic are divided to obtain N circulation round groups of the to-be-circulated business logic; wherein M is an integer greater than or equal to N; and the N circulation round groups of the to-be-circulated business logic are executed in parallel. Since the N circulation round groups can be executed in parallel, this parallel method helps to improve the business execution efficiency compared with the serial method.
[0062] In some implementable manners, the system architecture of the embodiment of the present application is as shown in Figure 1 .
[0063] Figure 1 A system architecture diagram related to the embodiment of the present application is as shown in Figure 1 , which includes a background server 110 corresponding to a target database system and a terminal device 120.
[0064] Wherein, the background server 110 and the terminal device 120 can be directly or indirectly connected through wired or wireless communication, which is not limited by the present application.
[0065] In some implementable manners, the target database system can be a distributed database system, but is not limited to this. For example, the target database system can be TDSQL PostgreSQL, but is not limited to this.
[0066] In some implementable manners, the background server 110 can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server providing cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, content distribution networks (Content Delivery Network, CDN), and big data and artificial intelligence platforms, etc. basic cloud computing services.
[0067] In some implementable manners, the terminal device 120 can be installed with a client corresponding to the target database system.
[0068] In some implementable manners, the terminal device 120 can be a desktop computer, a notebook computer, a tablet computer, a smart phone, a tablet computer, a smart watch, a virtual reality (VR) device, an augmented reality (AR) device, an Internet of Things device, and a portable wearable device, but is not limited thereto. Among them, the Internet of Things device can be a smart speaker, a smart television, a smart air conditioner, a smart vehicle device, etc. The portable wearable device can be a smart watch, a smart bracelet, a head-mounted device, etc. The terminal device 120 is often configured with a display device, which can also be a display, a display screen, a touch screen, etc. The touch screen can also be a touch screen, a touch panel, etc.
[0069] The background server 110 can obtain the parallelism N of the to-be-looped business logic of the target business; N is a positive integer; based on the parallelism N of the to-be-looped business logic, the M loop rounds of the to-be-looped business logic are divided to obtain N loop round groups of the to-be-looped business logic; M is an integer greater than or equal to N; and the N loop round groups of the to-be-looped business logic are executed in parallel.
[0070] In some implementable manners, the background server 110 can receive a business execution function of a target business sent by the terminal device 120 or receive a calling statement for scheduling the business execution function; the business execution function or the calling statement carries the parallelism N of the to-be-looped business logic, so that the background server 110 obtains the parallelism N of the to-be-looped business logic of the target business.
[0071] It should be noted that, Figure 1 An example of a terminal device 120 is shown. Optionally, the system architecture can include at least two terminal devices 120, and the embodiments of the present application do not limit this. In addition, the system architecture can also include other communication devices, such as a base station, wherein the base station is directly or indirectly connected with the background server 110 and the terminal device 120 through wired or wireless communication, and the present application does not limit this.
[0072] The embodiments of the present application will be described in detail below:
[0073] Figure 2 A flowchart of a business execution method provided by the embodiments of the present application is shown. The method can be executed by a background server corresponding to a target database system, which can be a distributed database system, such as TDSQL PostgreSQL, but is not limited thereto. Of course, the target database system can also not be a distributed database system, wherein the background server can be a background server 110 in Figure 1 , but is not limited thereto, such as Figure 2As shown, the method can include:
[0074] S210: Obtain the parallelism N of the to-be-circulated business logic of the target business; wherein N is a positive integer;
[0075] It should be understood that the target business can be any business including to-be-circulated business logic, for example, the target business can be a billing business in the financial industry.
[0076] It should be understood that the to-be-circulated business logic refers to the business logic that needs to be circulated in the target business, for example, taking the billing business in the financial industry as an example, the following business logic is the to-be-circulated business logic of the billing business: loop through all order data, calculate each item of order data based on billing rules to obtain the bill corresponding to each item of order data, and finally store the bills corresponding to the order data in the form of a table in the database system, that is, realize billing.
[0077] It should be noted that there is no dependency relationship between the circulation rounds in the to-be-circulated business logic, that is, the circulation rounds in the to-be-circulated business logic need to be decoupled from each other.
[0078] In some implementable manners, the to-be-circulated business logic can include at least one of the following logics, but is not limited to this: increase, delete, modify, query, function call, etc., and can even include more complex business logic.
[0079] It should be understood that the to-be-circulated business logic can also be referred to as to-be-circulated business code, to-be-circulated business program, to-be-circulated business module, to-be-circulated business unit, etc., and the embodiments of the present application do not limit this.
[0080] It should be understood that the parallelism of the to-be-circulated business logic refers to the number of tasks that can be executed simultaneously in parallel in the to-be-circulated business logic.
[0081] In some implementable manners, the parallelism of the to-be-circulated business logic can be set as needed, and generally the parallelism does not exceed the number of central processing units (CPUs) of the background server corresponding to the target database system. For example, the number of CPU cores of the background server is 100, and the parallelism of the to-be-circulated business logic of a certain business is 96. For another example, the number of CPU cores of the background server is 4, and the parallelism of the to-be-circulated business logic of a certain business is 2.
[0082] In some implementable manners, the background server can receive an execution code of a target business sent by a terminal device; wherein the execution code carries the parallelism N of the to-be-circulated business logic.
[0083] It should be understood that the execution code of the target business is used to implement the execution of the target business.
[0084] For example, the execution code sent by the terminal device to the background server is as follows:
[0085] DECLARE
[0086] r user_data%rowtype; / / declare a row type variable r
[0087] BEGIN / / start
[0088] PARALLEL_FOR(4)r IN / / parallel execution of the to-be-looped business logic, that is, the logic from PARALLEL_FOR to endloop, wherein the parallel degree is 4
[0089] SELECT*FROM user_data / / select a row of data from the user_data table and assign it to the variable r
[0090] LOOP / / loop
[0091] CALL proc_batch1(); / / execute batch business 1 for the selected row of data
[0092] CALL proc_batch2(); / / execute batch business 2 for the selected row of data
[0093] CALL proc_batch2(); / / execute batch business 3 for the selected row of data
[0094] END LOOP; / / end loop
[0095] END; / / end
[0096] It should be understood that the execution code in this example is used to implement batch business 1, 2 and 3 for each row of data in the user_data table, wherein the parallel degree of the to-be-looped business logic is 4, and assuming that the number of business loops is 100, the 1-100 loop rounds can be divided into 4 groups to parallelize the 4 groups of loop rounds.
[0097] In the PARALLEL_FOR(4)r IN, the 4 is the parallel degree of the to-be-looped business logic.
[0098] In some implementations, the background server can receive a call statement sent by the terminal device; wherein the call statement is used to call a business execution function of a target business, and the call statement carries a parallel degree N of to-be-looped business logic.
[0099] It should be understood that the business execution function is used to execute the target business.
[0100] For example, the business execution function can be as follows:
[0101] CREATE OR REPLACE PROCEDURE proc_parallel()AS / / Create or replace the business execution function;
[0102] DECLARE
[0103] `r user_data%rowtype;` / / Declare a variable `r` representing the row type.
[0104] BEGIN
[0105] PARALLEL_FOR(4)r IN / / Parallel execution of the business logic to be looped, that is, the logic from PARALLEL_FOR to endloop, where the parallelism is 4
[0106] SELECT * FROM user_data / / Select one row of data from the user data and assign it to the variable r
[0107] LOOP
[0108] CALL proc_batch1(); / / Perform batch processing on the selected row of data.
[0109] CALL proc_batch2(); / / Execute batch processing 2 on the selected row of data.
[0110] CALL proc_batch3(); / / Execute batch processing 3 on the selected row of data.
[0111] END LOOP; / / End the loop
[0112] END; / / End
[0113] It should be understood that this business execution function has the same effect as the execution code in the previous example. However, the terminal device has already sent the business execution function to the backend server. Therefore, the terminal device only needs to send a call statement to the backend server to invoke the business execution function, such as: CALL proc_parallel(parameter1, parameter2, ...), where proc_parallel() represents the function name of the business execution function. The parallelism of the business logic to be looped can be carried in the call statement as a parameter. For example, parameter1 can be the parallelism of the business logic to be looped.
[0114] It should be noted that the embodiments of the present application do not limit the manner of obtaining the parallelism of the to-be-circulated business logic.
[0115] S220: dividing the M loop rounds of the to-be-circulated business logic based on the parallelism N of the to-be-circulated business logic to obtain N loop round groups of the to-be-circulated business logic; wherein M is an integer greater than or equal to N;
[0116] It should be understood that M represents the number of loops of the to-be-circulated business logic, and the M loop rounds are respectively the 1st loop round, the 2nd loop round, …, and the Mth loop round.
[0117] S220 can be implemented by any of the following manners, but is not limited thereto:
[0118] In some implementable manners, S220 can include:
[0119] S220-1A: based on the parallelism N of the to-be-circulated business logic, setting N initial loop round groups;
[0120] S220-2A: sequentially distributing the M loop rounds of the to-be-circulated business logic to the N initial loop round groups to obtain the N loop round groups of the to-be-circulated business logic.
[0121] It should be understood that the N initial loop round groups are all empty.
[0122] For example, assuming that the to-be-circulated business logic of a certain business includes 10 loop rounds, which are respectively the 1st loop round, the 2nd loop round, …, and the 10th loop round, and the parallelism of the to-be-circulated business logic is 2, then the background server can first set 2 initial loop round groups, which are empty at the beginning, and further, the background server can distribute the 1st loop round to the 1st initial loop round group, the 2nd loop round to the 2nd initial loop round group, the 3rd loop round to the 1st initial loop round group, the 4th loop round to the 2nd initial loop round group, the 5th loop round to the 1st initial loop round group, the 6th loop round to the 2nd initial loop round group, the 7th loop round to the 1st initial loop round group, the 8th loop round to the 2nd initial loop round group, the 9th loop round to the 1st initial loop round group, and the 4th loop round to the 10th initial loop round group.
[0123] In some implementable manners, S220 can include:
[0124] S220-1B: if M is an integer multiple of N, then dividing the M loop rounds into N loop round groups, wherein each loop round group includes a number of loop rounds of M / N;
[0125] In some implementations, dividing the M loop turns into N loop turn groups includes that the background server can assign the 1st to the M / Nth loop turns to the 1st loop turn group, assign the M / N+1st to the 2*M / Nth loop turns to the 2nd loop turn group, and so on, and assign the (N-1)*(M / N)+1st to the (N)*(M / N)th loop turns to the Nth loop turn group, but the present application is not limited thereto.
[0126] For example, assuming that the to-be-looped business logic of a certain business includes 10 loop turns, which are the 1st loop turn, the 2nd loop turn, …, and the 10th loop turn, and assuming that the parallelism of the to-be-looped business logic is 2, the background server can divide the 10 loop turns into 2 loop turn groups. The 1st loop turn group includes the 1st loop turn, the 2nd loop turn, the 3rd loop turn, the 4th loop turn, and the 5th loop turn. The 2nd loop turn group includes the 6th loop turn, the 7th loop turn, the 8th loop turn, the 9th loop turn, and the 10th loop turn.
[0127] In some implementations, dividing the M loop turns into N loop turn groups includes that the background server can assign the 1st to the M / Nth loop turns to the Nth loop turn group, assign the M / N+1st to the 2*M / Nth loop turns to the N-1th loop turn group, and so on, and assign the (N-1)*(M / N)+1st to the (N)*(M / N)th loop turns to the 1st loop turn group, but the present application is not limited thereto.
[0128] For example, assuming that the to-be-looped business logic of a certain business includes 10 loop turns, which are the 1st loop turn, the 2nd loop turn, …, and the 10th loop turn, and assuming that the parallelism of the to-be-looped business logic is 2, the background server can divide the 10 loop turns into 2 loop turn groups. The 2nd loop turn group includes the 1st loop turn, the 2nd loop turn, the 3rd loop turn, the 4th loop turn, and the 5th loop turn. The 1st loop turn group includes the 6th loop turn, the 7th loop turn, the 8th loop turn, the 9th loop turn, and the 10th loop turn.
[0129] S220-2B: If M is not an integer multiple of N, divide the M loop turns into N loop turn groups, wherein each loop turn group includes a number of loop turns that is The remaining loop turns are assigned to at least one loop turn group.
[0130] In some implementations, dividing the M loop turns into N loop turn groups includes that the background server can assign the 1st to the M / Nth loop turns to the Nth loop turn group, assign the M / N+1st to the 2*M / Nth loop turns to the N-1th loop turn group, and so on, and assign the (N-1)*(M / N)+1st to the (N)*(M / N)th loop turns to the 1st loop turn group, but the present application is not limited thereto. The first cycle round is assigned to the first cycle round group, the second cycle round and the third cycle round are assigned to the second cycle round group, and the fourth cycle round and the fifth cycle round are assigned to the third cycle round group. The first cycle round is assigned to the first cycle round group, the second cycle round and the third cycle round are assigned to the second cycle round group, and the fourth cycle round and the fifth cycle round are assigned to the third cycle round group. The first cycle round is assigned to the first cycle round group, the second cycle round and the third cycle round are assigned to the second cycle round group, and the fourth cycle round and the fifth cycle round are assigned to the third cycle round group. The first cycle round is assigned to the first cycle round group, the second cycle round and the third cycle round are assigned to the second cycle round group, and the fourth cycle round and the fifth cycle round are assigned to the third cycle round group. The first cycle round is assigned to the first cycle round group, the second cycle round and the third cycle round are assigned to the second cycle round group, and the fourth cycle round and the fifth cycle round are assigned to the third cycle round group.
[0131] In some implementable manners, the M cycle rounds are divided into N cycle round groups, including: the background server can assign the first cycle round to the Nth cycle round group, assign the first cycle round to the Nth cycle round group, assign the first cycle round to the Nth cycle round group, and assign the first cycle round to the Nth cycle round group. The first cycle round is assigned to the first cycle round group, the second cycle round and the third cycle round are assigned to the second cycle round group, and the fourth cycle round and the fifth cycle round are assigned to the third cycle round group. The first cycle round is assigned to the first cycle round group, the second cycle round and the third cycle round are assigned to the second cycle round group, and the fourth cycle round and the fifth cycle round are assigned to the third cycle round group. The first cycle round is assigned to the first cycle round group, the second cycle round and the third cycle round are assigned to the second cycle round group, and the fourth cycle round and the fifth cycle round are assigned to the third cycle round group. The first cycle round is assigned to the first cycle round group, the second cycle round and the third cycle round are assigned to the second cycle round group, and the fourth cycle round and the fifth cycle round are assigned to the third cycle round group. The first cycle round is assigned to the first cycle round group, the second cycle round and the third cycle round are assigned to the second cycle round group, and the fourth cycle round and the fifth cycle round are assigned to the third cycle round group.
[0132] In some implementable manners, the remaining cycle rounds are assigned to at least one cycle round group, including: the background server assigns all the remaining cycle rounds to any cycle round group, but not limited to this.
[0133] In some implementable manners, the remaining cycle rounds are assigned to at least one cycle round group, including: if there is one remaining cycle round, the background server assigns the remaining cycle round to any cycle round group, and if there are multiple remaining cycle rounds, the background server assigns the multiple remaining cycle rounds to multiple cycle round groups, but not limited to this.
[0134] For example, assuming that the to-be-circulated business logic of a certain business includes 11 cycle rounds, which are the first cycle round, the second cycle round,..., and the eleventh cycle round, and assuming that the parallelism of the to-be-circulated business logic is 2, then the background server can divide the 11 cycle rounds into 2 cycle round groups, the first cycle round group includes the first cycle round, the second cycle round, the third cycle round, the fourth cycle round, and the fifth cycle round. The second cycle round group includes the sixth cycle round, the seventh cycle round, the eighth cycle round, the ninth cycle round, and the tenth cycle round, and further, the background server can assign the eleventh cycle round to the first cycle round group.
[0135] For example, assuming that the to-be-looped business logic of a certain business includes 11 loop rounds, which are the 1st loop round, the 2nd loop round,..., the 11th loop round, and assuming that the parallelism of the to-be-looped business logic is 2, the background server can divide the 11 loop rounds into 2 loop round groups, the 2nd loop round group including the 1st loop round, the 2nd loop round, the 3rd loop round, the 4th loop round, and the 5th loop round. The 1st loop round group includes the 6th loop round, the 7th loop round, the 8th loop round, the 9th loop round, and the 10th loop round, and further, the background server can assign the 11th loop round to the 1st loop round group.
[0136] For example, assuming that the to-be-looped business logic of a certain business includes 11 loop rounds, which are the 1st loop round, the 2nd loop round,..., the 10th loop round, and assuming that the parallelism of the to-be-looped business logic is 3, the background server can divide the 11 loop rounds into 3 loop round groups, the 1st loop round group including the 1st loop round, the 2nd loop round, and the 3rd loop round. The 2nd loop round group includes the 4th loop round, the 5th loop round, and the 6th loop round. The 3rd loop round group includes the 7th loop round, the 8th loop round, and the 9th loop round, and further, the background server can assign the 10th loop round and the 11th loop round to the 1st loop round group.
[0137] For example, assuming that the to-be-looped business logic of a certain business includes 11 loop rounds, which are the 1st loop round, the 2nd loop round,..., the 10th loop round, and assuming that the parallelism of the to-be-looped business logic is 3, the background server can divide the 11 loop rounds into 3 loop round groups, the 1st loop round group including the 1st loop round, the 2nd loop round, and the 3rd loop round. The 2nd loop round group includes the 4th loop round, the 5th loop round, and the 6th loop round. The 3rd loop round group includes the 7th loop round, the 8th loop round, and the 9th loop round, and further, the background server can assign the 10th loop round to the 1st loop round group and assign the 11th loop round to the 2nd loop round group.
[0138] In some implementable manners, the background server can divide the M loop rounds of the to-be-looped business logic into N loop round groups based on the parallelism N of the to-be-looped business logic when executing the to-be-looped business logic.
[0139] For example, assuming that the to-be-looped business is as follows:
[0140]
[0141] Then, when the background server executes the PARALLEL_FOR(4) r IN, the M loop rounds of the to-be-looped business logic can be divided based on the parallelism N of the to-be-looped business logic to obtain N loop round groups of the to-be-looped business logic.
[0142] In some implementable manners, the background server divides the M loop rounds of the to-be-looped business logic based on the parallelism N of the to-be-looped business logic during the compilation stage of the execution code or the business execution function of the target business to obtain N loop round groups of the to-be-looped business logic. Through this manner, the loop round groups can be divided as early as possible, thereby improving the business execution efficiency.
[0143] S230: Parallelly execute the N loop round groups of the to-be-looped business logic.
[0144] It should be understood that the reason why the background server can parallelly execute the N loop round groups is that the background server has multiple cores, wherein N is less than or equal to the number of cores of the background server, for example, the background server is a 4-core, and 2 cores can be used to parallelly execute 2 loop round groups.
[0145] Figure 3 The schematic diagram of the business execution method of the dual-core background server provided by the embodiments of the present application is as follows: Figure 3As shown, assuming that the background server includes CPU core 1 and CPU core 2, the loop turn group to which CPU core 1 is allocated includes all odd loop turns: {1st loop turn, 3rd loop turn, 5th loop turn, …}, the loop turn group to which CPU core 2 is allocated includes all even loop turns: {2nd loop turn, 4th loop turn, 6th loop turn, …}, based on this, CPU core 1 enters PLpgSQL (i.e., starts to execute the execution code of the target business), then executes the statement (i.e., executes the code before the PARALLEL_FOR), further, executes the loop body (i.e., executes the code starting from the PARALLEL_FOR), and when the loop body is executed, the statement in the loop body is executed in a loop (i.e., after each loop turn is executed, the next loop turn is executed, for example, the 1st loop turn is executed first, after the execution, the 3rd loop turn is executed, and the like). Similarly, CPU core 2 enters PLpgSQL (i.e., starts to execute the execution code of the target business), then executes the statement (i.e., executes the code before the PARALLEL_FOR), further, executes the loop body (i.e., executes the code starting from the PARALLEL_FOR), and when the loop body is executed, the statement in the loop body is executed in a loop (i.e., after each loop turn is executed, the next loop turn is executed, for example, the 2nd loop turn is executed first, after the execution, the 4th loop turn is executed, and the like). It should be noted that CPU core 1 and CPU core 2 execute the respective loop turn groups in parallel.
[0146] In some implementable manners, if there is still business logic of the target business after the business logic to be looped, the background server executes the business logic after the N loop turn groups are all executed.
[0147] In the embodiment of the present application, because the N loop turn groups can be executed in parallel, the business execution method provided by the embodiment of the present application can help to improve the business execution efficiency relative to the business execution method provided by the related art. In addition, the CPU utilization of the background server can also be improved.
[0148] For example, the execution code of the business execution method provided in the related art is as follows:
[0149]
[0150] The execution code of the business execution method provided in the embodiment of the present application is as follows:
[0151] CREATE OR REPLACE PROCEDURE proc_parallel()AS / / create or replace business execution function;
[0152]
[0153] Suppose the to-be-circulated business logic includes 100 loop rounds, and the execution time of each loop round is 20 min, then according to the business execution method provided by the related art, that is, the serial mode, the total execution time of 100 loop rounds is 2000 min. According to the business execution method provided by the related art, that is, the parallel mode, assuming that the parallelism is 4, then the total execution time of 100 loop rounds is 500 min.
[0154] For example, for the billing business of the financial industry, the background server usually queries the table structure corresponding to the order data to determine the billing rules for about 10 minutes, then serially traverses all the order data according to the serial mode, and calculates each item of order data based on the above billing rules to obtain the bill corresponding to each item of order data, and finally the bills corresponding to the order data can be stored in the database system in the form of a table, that is, the billing takes about 6 hours, wherein the number of loops is about 100,000. Further, if the order data processing fails, the background server needs to spend another 10 minutes to process the failed order data. After using the business execution method provided in the embodiments of the present application, the background server can use 64 cores to process 64 loop round groups, so the time spent by the loop round is reduced from 6 hours to 30 minutes.
[0155] In addition, assuming that the number of cores of the background server is 96, only one core can be used in the serial mode, while 64 cores can be used in the embodiments of the present application, so that the CPU utilization rate reaches more than 60%.
[0156] In some implementable manners, each client corresponding to the target database system corresponds to a background sub-process, or a terminal device to which the client belongs corresponds to a background sub-process.
[0157] It should be understood that the background sub-process is a child process created by the parent process in the target database system, and the background sub-process is mainly responsible for receiving and executing the command request issued by the client. For example, in the embodiments of the present application, the background sub-process can receive the business execution function of the target business or receive the calling statement for scheduling the business execution function to obtain the parallelism N of the to-be-circulated business logic of the target business; the M loop rounds of the to-be-circulated business logic are divided based on the parallelism N of the to-be-circulated business logic to obtain N loop round groups of the to-be-circulated business logic.
[0158] It should be understood that whenever a client is connected to the target database system, the parent process will create a new background sub-process for it, and the background sub-process will exist until the client actively closes the database connection or ends running due to an exception.
[0159] In some implementable manners, the backend sub-process mentioned in the embodiments of the present application can be a Backend sub-process in PostgreSQL, but is not limited thereto.
[0160] It should be understood that the parent process in the target database system is the master process in the target database system, which is responsible for initializing the database system and creating necessary auxiliary processes such as worker processes and detecting client connections when the server starts. Once the parent process starts, it allocates shared memory, opens necessary file descriptors, and sets other system resources to prepare for the running of the background sub-process and other processes. The parent process is also responsible for detecting client connection requests and creating (forking) new background sub-processes to handle these requests when receiving the requests.
[0161] In some implementable manners, the parent process mentioned in the embodiments of the present application can be a Postmaster process in PostgreSQL, but is not limited thereto.
[0162] In some implementable manners, the target background server can obtain the parallelism N of the to-be-looped business logic of the target business through the target background sub-process.
[0163] It should be understood that the target background sub-process refers to the background sub-process corresponding to the client initiating the target business.
[0164] In some implementable manners, obtaining the parallelism N of the to-be-looped business logic through the target background sub-process in the target database system includes: receiving execution code of the target business or receiving a call statement through the target background sub-process; wherein the call statement is used to call a business execution function of the target business; the execution code or the call statement carries the parallelism N of the to-be-looped business logic.
[0165] For example, Figure 4 The schematic diagram of obtaining the parallelism provided by the embodiments of the present application is shown in FIG. 1, wherein a client sends the following code to a target background sub-process, and the execution code includes a parallelism of 4: Figure 4
[0166] DECLARE
[0167] r user_data%rowtype; / / declare a variable r of row type
[0168] BEGIN / / start
[0169] PARALLEL_FOR(4)r IN / / parallel execution of to-be-looped business logic, that is, the logic from PARALLEL_FOR to endloop, wherein the parallelism is 4
[0170] SELECT * FROM user_data / / Select a row of data from user_data and assign it to variable r
[0171]
[0172] It should be understood that the way of obtaining parallelism can refer to the above, and embodiments of the present application will not be repeated.
[0173] In some implementable manners, the target background sub-process can divide the M loop rounds of the to-be-looped business logic based on the parallelism N of the to-be-looped business logic, to obtain N loop round groups of the to-be-looped business logic.
[0174] In some implementable manners, the target background sub-process in the target database system divides the M loop rounds of the to-be-looped business logic based on the parallelism N of the to-be-looped business logic, to obtain N loop round groups of the to-be-looped business logic, including: the target background sub-process divides the M loop rounds of the to-be-looped business logic based on the parallelism N of the to-be-looped business logic when executing the to-be-looped business logic, to obtain N loop round groups of the to-be-looped business logic.
[0175] In some implementable manners, the target background sub-process in the target database system divides the M loop rounds of the to-be-looped business logic based on the parallelism N of the to-be-looped business logic, to obtain N loop round groups of the to-be-looped business logic, including: the target background sub-process sets N initial loop round groups based on the parallelism N of the to-be-looped business logic; and the target background sub-process distributes the M loop rounds of the to-be-looped business logic to the N initial loop round groups in turn, to obtain N loop round groups of the to-be-looped business logic.
[0176] It should be understood that the introduction of how the target background sub-process divides the N loop round groups and the timing of dividing the N loop round groups can refer to the above, and embodiments of the present application will not be limited.
[0177] In some implementable manners, before S230, the target background sub-process in the target database system triggers the parent process in the target database system to create N worker processes; and the target background sub-process distributes the respective corresponding loop round groups to the N worker processes; correspondingly, S230 can include: the N worker processes execute the respective corresponding loop round groups in parallel.
[0178] It should be understood that the worker process is a process created by the parent process, and each worker process can be used to execute the respective corresponding loop round group.
[0179] In some implementable manners, in the embodiments of the present application, the worker process can be a worker process in PostgreSQL, but is not limited thereto.
[0180] In some implementable manners, the parent process in the target database system is triggered by the target background sub-process in the target database system to create N worker processes, including: sending a notification message by the target background sub-process to the parent process; and the parent process responds to the notification message to create N worker processes. Wherein, the notification message is used to notify the parent process to create N worker processes.
[0181] For example, Figure 5 A schematic diagram of the target background sub-process notifying the parent process to create worker processes is provided for the embodiments of the present application, as shown in Figure 5 As shown, after the target background sub-process receives the execution code or the calling statement of the target business, the target background sub-process can notify the parent process to create two worker processes.
[0182] In some implementable manners, the parent process in the target database system is triggered by the target background sub-process in the target database system to create N worker processes, including: scheduling a worker process creation function by the target background sub-process to make the parent process create N worker processes.
[0183] It should be understood that the worker process creation function is used to create worker processes.
[0184] In some implementable manners, the parent process creates a worker process each time the worker process creation function is called. For example, if the target background sub-process determines that the parallelism of the business logic to be looped is 2, the target background sub-process can call the worker process creation function twice to make the parent process create 2 worker processes.
[0185] In some implementable manners, the parent process creates N worker processes each time the worker process creation function is called. For example, if the target background sub-process determines that the parallelism of the business logic to be looped is 2, the target background sub-process can call the worker process creation function once and transmit the parallelism 2 to the parent process in the form of a parameter to make the parent process create two worker processes.
[0186] It should be understood that the number of worker processes is the same as the parallelism of the business logic to be looped, for example, Figure 6 A schematic diagram of the number of worker processes and the parallelism of the business logic to be looped is provided for the embodiments of the present application, as shown in Figure 6As shown, after the target background sub-process obtains the execution code of the target service, the parallelism of the to-be-looped business logic can be obtained as 2. Based on this, the target background sub-process can trigger the parent process to create 2 worker processes, and the 2 worker processes can execute the to-be-looped business logic in parallel.
[0187] It should be understood that, in order to enable the N worker processes to respectively know the loop round groups to which they are respectively assigned and execute the respective corresponding loop round groups, the embodiments of the present application propose that the shared memory of the N worker processes can be applied by the parent process; the memory spaces in the shared memory can be respectively allocated to the N worker processes by the parent process; the respective corresponding memory spaces of the N worker processes can be respectively notified to the N worker processes by the parent process; the respective corresponding memory spaces of the N worker processes can be notified to the target background sub-process; the respective corresponding loop round groups of the N worker processes can be written into the respective corresponding memory spaces of the N worker processes by the target background sub-process; and the respective corresponding loop round groups of the N worker processes can be respectively read from the respective corresponding memory spaces by the N worker processes.
[0188] It should be understood that the shared memory in the embodiments of the present application is the shared memory of the N worker processes, and each worker process has its own corresponding memory space in the shared memory.
[0189] For example, Figure 7 A shared memory diagram provided by the embodiments of the present application is as shown in Figure 7 As shown, the worker process 1 and the worker process 2 respectively correspond to the memory space 1 and the memory space 2 in the shared memory, and the memory space 1 can store the odd loop rounds, including the 1st loop round, the 3rd loop round, the 5th loop round, and the memory space 2 can store the even loop rounds, including the 2nd loop round, the 4th loop round, the 6th loop round.
[0190] In some implementable manners, the respective corresponding loop round groups of the N worker processes are written into the respective corresponding memory spaces of the N worker processes by the target background sub-process, including that the respective corresponding loop round groups of the N worker processes are written into the respective corresponding memory spaces of the N worker processes in the form of asynchronous message queues by the target background sub-process, but not limited thereto.
[0191] It should be understood that the advantages of the asynchronous message queue include: improving the execution efficiency of the loop round, and further improving the execution efficiency of the business logic, because after the producer sends the message to the asynchronous message queue, it does not need to wait for the response of the consumer, but returns immediately to continue executing other tasks. The consumer can read the loop round from the queue at an appropriate time and execute it.
[0192] For example, Figure 8Another shared memory diagram provided by the embodiments of the present application is shown in Figure 8 Worker process 1 and worker process 2 correspond to memory space 1 and memory space 2 in the shared memory respectively, and memory space 1 can store odd cycle rounds in the form of asynchronous message queues, including the 1st cycle round, the 3rd cycle round, the 5th cycle round, and so on. Memory space 2 can store even cycle rounds in the form of asynchronous message queues, including the 2nd cycle round, the 4th cycle round, the 6th cycle round, and so on.
[0193] In some implementable manners, the shared memory of the N worker processes can be the memory of the target background sub-process, based on which the N worker processes can obtain the context data of the to-be-circulated business logic from the memory.
[0194] In some implementable manners, assuming that the business logic of the target business located before the to-be-circulated business logic is referred to as first business logic, if the first business logic exists and is the business logic of the target business located before the to-be-circulated business logic, the context data includes the associated data of the first business logic and the to-be-circulated business logic; if the first business logic does not exist, the context data includes the to-be-circulated business logic.
[0195] In some implementable manners, the associated data of the first business logic includes the data structure and value of at least one variable. The variable can be a variable defined in the first business logic, or a return result of a function in the first business logic, but is not limited thereto.
[0196] In some implementable manners, the variable can be a local variable or a global variable, and the embodiments of the present application do not limit this.
[0197] In some implementable manners, the variable can be an in-package variable, but is not limited thereto.
[0198] In some implementable manners, the to-be-circulated business logic includes the data result and value of at least one variable. The explanation of the variable can be referred to the above, and the embodiments of the present application do not repeat the explanation.
[0199] In some implementable manners, the memory of the target background sub-process is the private memory of the target background sub-process, in which case the N worker processes do not have the context data of the to-be-circulated business logic, resulting in that the N worker processes cannot execute the corresponding cycle round group.
[0200] For example, the business execution function of the target business is as follows:
[0201]
[0202] It should be understood that when the target background child process executes PARALLEL_FOR, the code preceding that statement has already been executed. For example, the executed code might include assigning a value to variable 'a', specifically 'a:= 10'. Assuming the parent process creates the worker process, and the worker process lacks context data, if 'a' is used when the worker process executes its looping business logic, it will be unable to execute the looping business logic because it cannot know that 'a:= 10'.
[0203] However, it's not simply a matter of copying the context data of the business logic to be looped into the shared memory of N worker processes. For example, suppose the context data includes:
[0204] struct A{int len;struct B*p}
[0205] struct B{int kk;int jj;}
[0206] struct A a;
[0207] struct B b;
[0208] b.kk = 1;
[0209] b.jj = 20;
[0210] a.len = 10;
[0211] ap = &b;
[0212] The address of b is 0x55343243.
[0213] If the context data is simply copied to the shared memory of N worker processes, the data stored in the shared memory includes: struct A a{int 10, 0x55343243}, struct B b{int 1, int 20}. Clearly, 0x55343243 is the address of b, but the correct data corresponding to this entry is struct B b. Based on this, this application proposes that the target background subprocess can serialize the context data of the looping business logic to obtain serialized data. Furthermore, the N worker processes can deserialize the serialized data to obtain the context data.
[0214] In some implementable manners, the context data of the to-be-looped business logic is acquired by the target background sub-process; the context data is serialized by the target background sub-process to obtain serialized data; the serialized data is stored into the shared memory by the target background sub-process; the serialized data in the shared memory is read by the N worker processes; the serialized data is deserialized by the N worker processes to obtain the context data; and the N worker processes perform the respective corresponding loop round groups in parallel based on the context data.
[0215] It should be understood that, in the embodiments of the present application, the serialization process of the context data can be referred to as a packing process of the context data, and the deserialization process of the serialized data can be referred to as an unpacking process of the serialized data.
[0216] It should be understood that, the serialization process of the context data refers to a process of acquiring the data type and corresponding value of each variable in the context data, and a process of grouping the data type and corresponding value of each variable to form the serialized data.
[0217] Based on this, in some implementable manners, the serialization of the context data by the target background sub-process to obtain the serialized data comprises: the target background sub-process acquiring the data type and corresponding value of each variable in the context data; and the target background sub-process grouping the data type and corresponding value of each variable to form the serialized data.
[0218] For example, it is assumed that the context data comprises:
[0219] struct A{int len;struct B*p}
[0220] struct B{int kk;int jj;}
[0221] struct A a;
[0222] struct B b;
[0223] b.kk=1;
[0224] b.jj=20;
[0225] a.len=10;
[0226] a.p=&b;
[0227] wherein, the address of b is 0x55343243.
[0228] The context data includes variables a and b, whose data types are struct A and struct B respectively, and their corresponding values are {int 10, {int 1, int 20}} and {int 1, int 20} respectively. Therefore, the serialized data obtained by combining the data types and corresponding values of the two variables is: struct A a{int len=10, struct B b{int kk=1, int jj=20}}.
[0229] It should be understood that the deserialization of the serialized data refers to a process of constructing the data structure of each variable based on the data type and corresponding value of each variable.
[0230] In some implementations, the N worker processes deserialize the serialized data to obtain context data, including: the N worker processes construct the data structure of each variable based on the data type and corresponding value of each variable; wherein the context data includes: the data structure of each variable.
[0231] For example, assuming the serialized data is struct A a{int len=10, struct B b{int kk=1, int jj=20}}, then the data structure of each variable obtained after deserialization is as follows:
[0232] struct A{int len;struct B*p}
[0233] struct B{int kk;int jj;}
[0234] struct A a;
[0235] struct B b;
[0236] b.kk=1;
[0237] b.jj=20;
[0238] a.len=10;
[0239] a.p=&b。
[0240] In some implementations, after the N worker processes execute the respective corresponding cycle round group in parallel, the N worker processes further notify the target background sub-process that the respective corresponding cycle round group has been executed.
[0241] In some implementations, N worker processes notify the target background child process that their respective round-robin groups have been completed. This includes: N worker processes asynchronously notifying the target background child process that their respective round-robin groups have been completed. In other words, the N worker processes are independent of each other and do not need to wait for each other, thereby further improving business execution efficiency.
[0242] In some feasible implementations, if the business logic following the pending loop business logic in the target business logic is called the second business logic, then if the second business logic exists, the target background subprocess will execute the second business logic after determining that all N loop rounds have been executed.
[0243] The following is an example illustrating the method for executing this business:
[0244] For example, Figure 9 A schematic diagram illustrating an example of a business execution method provided in this application embodiment, such as... Figure 9 As shown, the method includes:
[0245] S910: The target background subprocess receives the execution code or call statement of the target business sent by the client; wherein, the call statement is used to call the business execution function of the target business, and the execution code or call statement carries the parallelism of the business logic to be looped 2;
[0246] S920: The target background child process triggers the parent process to create two worker processes and requests shared memory for the two worker processes; allocates memory space in the shared memory to the two worker processes respectively; notifies the two worker processes of their respective memory space; and notifies the target background child process of the two worker processes of their respective memory space.
[0247] S930: The target background subprocess divides the six iterations of the business logic to be iterated into two iteration groups based on the parallelism of 2; writes the iteration groups corresponding to each of the two worker processes into their respective memory spaces; and serializes the context data of the business logic to be iterated into serialized data; the target background subprocess stores the serialized data in shared memory.
[0248] For example, such as Figure 9 As shown, the target background child process can store the first, third, and fifth loop cycles in the memory space of worker process 1 in the form of an asynchronous message queue.
[0249] S940: 2 worker processes read the respective corresponding cycle round groups from the respective corresponding memory spaces respectively; and read the serialized data in the shared memory; deserialize the serialized data to obtain context data; perform the respective corresponding cycle round groups in parallel based on the context data; after the N worker processes perform the respective corresponding cycle round groups, the target background sub-process is notified that the respective corresponding cycle round groups have been performed.
[0250] In some implementable manners, after the N worker processes notify the target background sub-process that the respective corresponding cycle round groups have been performed, the N worker processes can automatically exit.
[0251] Embodiments of the present application mainly describe a business execution method from the perspective of a process. Since the N cycle round groups can be performed in parallel by the N worker processes, the business execution method provided by the embodiments of the present application can help improve the business execution efficiency compared with the business execution method provided by the related art. In addition, the CPU utilization of the background server can also be improved.
[0252] Further, the embodiments of the present application serialize the context data of the business logic to be circulated, and store the serialized data in the shared memory corresponding to the N worker processes, so that the N worker processes deserialize the serialized data to obtain the context data, so that the N worker processes can perform the corresponding cycle round groups based on the context data.
[0253] The preferred embodiments of the present application are described in detail above with reference to the accompanying drawings, but the present application is not limited to the specific details in the above-described embodiments. Within the technical concept of the present application, various simple modifications can be made to the technical solutions of the present application, and these simple modifications all belong to the protection scope of the present application. For example, in the above-described specific embodiments, various specific technical features described in the above-described specific embodiments can be combined in any appropriate manner without contradiction. In order to avoid unnecessary repetition, various possible combination manners are not described again in the present application. For example, various different embodiments of the present application can also be combined in any manner, as long as it does not deviate from the idea of the present application, and it should also be considered as disclosed in the present application.
[0254] It should also be understood that in various method embodiments of the present application, the size of the serial number of the above-described processes does not mean the order of execution, and the execution order of the processes should be determined according to its function and inherent logic, and should not constitute any limitation on the implementation process of the embodiments of the present application.
[0255] The above describes the method provided by the embodiments of the present application, and the following describes the business execution device provided by the embodiments of the present application.
[0256] Figure 10A schematic diagram of a service execution apparatus 1000 provided by an embodiment of the present application is shown in Figure 10 The service execution apparatus 1000 includes a communication module 1010 and a processing module 1020. The communication module 1010 is configured to obtain a parallelism N of to-be-looped service logic of a target service. N is a positive integer. The processing module 1020 is configured to divide M loop rounds of the to-be-looped service logic based on the parallelism N of the to-be-looped service logic, to obtain N loop round groups of the to-be-looped service logic. M is an integer greater than or equal to N. The processing module 1020 is further configured to perform the N loop round groups of the to-be-looped service logic in parallel.
[0257] In some implementable manners, the communication module 1010 is specifically configured to obtain the parallelism N of the to-be-looped service logic through a target background sub-process in a target database system.
[0258] In some implementable manners, the communication module 1010 is specifically configured to receive execution code of the target service or receive a calling statement through the target background sub-process. The calling statement is used to call a service execution function of the target service. The execution code or the calling statement carries the parallelism N of the to-be-looped service logic.
[0259] In some implementable manners, the processing module 1020 is specifically configured to divide, by the target background sub-process in the target database system, the M loop rounds of the to-be-looped service logic based on the parallelism N of the to-be-looped service logic, to obtain the N loop round groups of the to-be-looped service logic.
[0260] In some implementable manners, the processing module 1020 is specifically configured to divide, by the target background sub-process, the M loop rounds of the to-be-looped service logic based on the parallelism N of the to-be-looped service logic, to obtain the N loop round groups of the to-be-looped service logic, when the target background sub-process executes the to-be-looped service logic.
[0261] In some implementable manners, the processing module 1020 is specifically configured to set, by the target background sub-process based on the parallelism N of the to-be-looped service logic, N initial loop round groups; and distribute, by the target background sub-process, the M loop rounds of the to-be-looped service logic to the N initial loop round groups in turn, to obtain the N loop round groups of the to-be-looped service logic.
[0262] In some implementable manners, before the processing module 1020 executes the N loop round groups of the to-be-looped business logic in parallel, the communication module 1010 or the processing module 1020 is further configured to trigger the parent process in the target database system to create N worker processes through a target background sub-process in the target database system; the processing module 1020 is further configured to assign each corresponding loop round group to the N worker processes through the target background sub-process; correspondingly, the processing module 1020 is specifically configured to execute each corresponding loop round group in parallel through the N worker processes.
[0263] In some implementable manners, the communication module 1010 is specifically configured to send a notification message to the parent process through the target background sub-process; the parent process creates the N worker processes in response to the notification message.
[0264] In some implementable manners, the processing module 1020 is specifically configured to schedule a worker process creation function through the target background sub-process, so that the parent process creates the N worker processes.
[0265] In some implementable manners, before the processing module 1020 executes each corresponding loop round group in parallel through the N worker processes, the processing module 1020 is further configured to apply shared memory of the N worker processes through the parent process; the parent process is further configured to assign memory space in the shared memory to the N worker processes respectively; the communication module 1010 is further configured to notify each corresponding memory space of the N worker processes through the parent process respectively; and notify the target background sub-process of each corresponding memory space of the N worker processes; the processing module 1020 is further configured to write each corresponding loop round group of the N worker processes into each corresponding memory space of the N worker processes through the target background sub-process; and read each corresponding loop round group from each corresponding memory space through the N worker processes respectively.
[0266] In some implementable manners, the processing module 1020 is specifically configured to write each corresponding loop round group of the N worker processes into each corresponding memory space of the N worker processes in the form of an asynchronous message queue through the target background sub-process.
[0267] In some implementable manners, before the processing module 1020 executes the respective corresponding loop round groups in parallel by the N worker processes, the processing module 1020 is further configured to: acquire, by the target background sub-process, context data of the to-be-looped business logic; wherein, if there is a first business logic, the first business logic being a business logic located before the to-be-looped business logic in the business logic of the target business, the context data comprising: the associated data of the first business logic and the to-be-looped business logic; if there is no first business logic, the context data comprising: the to-be-looped business logic; serialize, by the target background sub-process, the context data to obtain serialized data; and store, by the target background sub-process, the serialized data into the shared memory; correspondingly, the processing module 1020 is specifically configured to: read, by the N worker processes, the serialized data in the shared memory; deserialize, by the N worker processes, the serialized data to obtain the context data; and execute, by the N worker processes, the respective corresponding loop round groups in parallel based on the context data.
[0268] In some implementable manners, the processing module 1020 is specifically configured to: acquire, by the target background sub-process, the data type and the corresponding value of each variable in the context data; and group, by the target background sub-process, the data type and the corresponding value of each variable into the serialized data.
[0269] In some implementable manners, the processing module 1020 is specifically configured to: construct, by the N worker processes, the data structure of each variable based on the data type and the corresponding value of each variable; and wherein, the context data comprises: the data structure of each variable.
[0270] In some implementable manners, after the processing module 1020 executes the respective corresponding loop round groups in parallel by the N worker processes, the communication module 1010 is further configured to: notify, by the N worker processes to the target background sub-process, that the respective corresponding loop round groups have been executed after the N worker processes execute the respective corresponding loop round groups.
[0271] In some implementable manners, the processing module 1020 is further configured to: if there is a second business logic, the second business logic being a business logic located after the to-be-looped business logic in the business logic of the target business, execute, by the target background sub-process, the second business logic after the target background sub-process determines that the N loop round groups have all been executed.
[0272] It should be understood that the device embodiments and the method embodiments can correspond to each other, and similar descriptions can be referred to the method embodiments. To avoid repetition, details are not described here. Specifically, Figure 10 The illustrated business execution device 1000 can execute Figure 2The foregoing and other operations and / or functions of the various modules in the service execution apparatus 1000 are respectively implemented in order to achieve the corresponding method embodiments Figure 2 The corresponding flow in each method in the foregoing is not repeated here for brevity.
[0273] The service execution apparatus 1000 of the embodiments of the present application is described above from the perspective of functional modules in combination with the drawings. It should be understood that the functional modules can be implemented in the form of hardware, or in the form of instructions of software, or in the form of a combination of hardware and software modules. Specifically, each step of the method embodiments in the embodiments of the present application can be completed by integrated logic circuits of hardware in a processor and / or instructions in the form of software, the steps of the method disclosed in the embodiments of the present application can be directly embodied as hardware code processing and executed by a processor, or executed by a combination of hardware and software modules in a code processing processor. Alternatively, the software modules can be located in mature storage media in the art, such as random access memory, flash memory, read-only memory, programmable read-only memory, electrically erasable programmable memory, register, etc. The storage media is located in a memory, and a processor reads information in the memory and combines hardware thereof to complete the steps in the method embodiments described above.
[0274] Figure 11 is a schematic block diagram of the electronic device 1100 provided by the embodiments of the present application. As shown in Figure 11 The electronic device 1100 can include:
[0275] The memory 1110 is configured to store a computer program 1130 and transmit the computer program 1130 to the processor 1120. In other words, the processor 1120 can call and run the computer program 1130 from the memory 1110 to implement the method in the embodiments of the present application.
[0276] For example, the processor 1120 can be configured to perform the steps in the method according to the instructions in the computer program 1130.
[0277] In some embodiments of the present application, the processor 1120 can include but is not limited to:
[0278] A general processor, a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc.
[0279] In some embodiments of the present application, the memory 1110 includes, but is not limited to:
[0280] volatile memory and / or non-volatile memory. The non-volatile memory can be a Read-Only Memory (ROM), a Programmable ROM (PROM), an Erasable PROM (EPROM), an Electrically EPROM (EEPROM), or a flash memory. The volatile memory can be a Random Access Memory (RAM) used as an external cache. By way of example, and not limitation, many forms of RAM are available, such as Static RAM (SRAM), Dynamic RAM (DRAM), Synchronous DRAM (SDRAM), Double Data Rate SDRAM (DDR SDRAM), Enhanced SDRAM (ESDRAM), Synch link DRAM (SLDRAM), and Direct Rambus RAM (DR RAM).
[0281] In some embodiments of the present application, the computer program 1130 can be divided into one or more modules stored in the memory 1110 and executed by the processor 1120 to complete the method provided by the present application. The one or more modules can be a series of computer program instruction segments capable of completing a specific function, which are used to describe the execution process of the computer program 1130 in the electronic device.
[0282] As shown in Figure 11 The electronic device 1100 can further include:
[0283] a transceiver 1140, which can be connected to the processor 1120 or the memory 1110.
[0284] The processor 1120 can control the transceiver 1140 to communicate with other devices, specifically, to send information or data to other devices or receive information or data sent by other devices. The transceiver 1140 can include a transmitter and a receiver. The transceiver 1140 can further include an antenna, and the number of antennas can be one or more.
[0285] It should be understood that the various components of the electronic device 1100 are coupled together by a bus system, which can include a power bus, a control bus and a status signal bus in addition to a data bus.
[0286] According to an aspect of the present application, a computer storage medium is provided, which stores a computer program. The computer program is executed by a computer to enable the computer to perform the method of the above method embodiments. Alternatively, the embodiments of the present application also provide a computer program product containing instructions. The instructions are executed by a computer to perform the method of the above method embodiments.
[0287] According to another aspect of the present application, a computer program product or computer program is provided, which includes computer instructions stored in a computer readable storage medium. A processor of a computer device reads the computer instructions from the computer readable storage medium. The processor executes the computer instructions to enable the computer device to perform the method of the above method embodiments.
[0288] In other words, when implemented using software, the embodiments of the present application can be implemented in the form of a computer program product. The computer program product includes one or more computer instructions. When loaded and executed by a computer, the computer program instructions generate the flow or function according to the embodiments of the present application in whole or in part. The computer can be a general purpose computer, a special purpose computer, a computer network, or other programmable apparatus. The computer instructions can be stored in a computer readable storage medium or transferred from one computer readable storage medium to another computer readable storage medium, for example, the computer instructions can be transferred from one website site, computer, server or data center to another website site, computer, server or data center through wired (such as coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (such as infrared, wireless, microwave, etc.) manner. The computer readable storage medium can be any available medium accessible by a computer or a data storage device such as a server, data center, etc. containing one or more available media sets. The available medium can be a magnetic medium (such as a floppy disk, a hard disk, a magnetic tape), an optical medium (such as a digital video disc (DVD)), or a semiconductor medium (such as a solid state disk (SSD)), etc.
[0289] Those skilled in the art can understand that the modules and algorithm steps of each example described in combination with the embodiments disclosed herein can be realized by electronic hardware or a combination of computer software and electronic hardware. Whether the functions are performed 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 the present application.
[0290] In several embodiments provided in the present application, it should be understood that the disclosed system, device and method can be implemented in other ways. For example, the device embodiments described above are merely illustrative, for example, the division of the modules is only a logical function division, and actual implementation can have another division manner, for example, a plurality of modules or components can be combined or integrated into another system, or some features can be ignored or not executed. In addition, the coupling or direct coupling or communication connection between the displayed or discussed modules can be indirect coupling or communication connection through some interfaces, devices or modules, which can be electrical, mechanical or other forms.
[0291] The modules described as separate components can or can not be physically separated, and the components shown as modules can or can not be physical modules, i.e. they can be located in one place or distributed on multiple network units. Part or all of the modules can be selected to implement the embodiments of the present application according to actual needs. For example, the functional modules in each embodiment of the present application can be integrated in one processing module, or each module can be physically present separately, or two or more modules can be integrated in one module.
[0292] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto, and any skilled person in the art can easily think of changes or replacements within the technical scope disclosed in the present application, which should be covered within the protection scope of the present application. Therefore, the protection scope of the present application should be subject to the protection scope of the claims.
Claims
1. A service execution method characterized by, The method is executed by a background server corresponding to a target database system, and the method comprises: Obtaining parallelism N of to-be-circulated business logic of a target service; wherein N is a positive integer; Dividing M circulation rounds of the to-be-circulated business logic based on the parallelism N of the to-be-circulated business logic, to obtain N circulation round groups of the to-be-circulated business logic; wherein M is an integer greater than or equal to N; Parallelly executing the N circulation round groups of the to-be-circulated business logic.
2. The method of claim 1, wherein, The obtaining of the parallelism N of the to-be-circulated business logic of the target service comprises: Obtaining the parallelism N of the to-be-circulated business logic by a target background sub-process in the target database system.
3. The method of claim 2, wherein, The obtaining of the parallelism N of the to-be-circulated business logic by the target background sub-process in the target database system comprises: Receiving execution code of the target service or receiving a calling statement by the target background sub-process; The calling statement is used to call a business execution function of the target service; the execution code or the calling statement carries the parallelism N of the to-be-circulated business logic.
4. The method according to any one of claims 1 to 3, characterized in that, The dividing of the M circulation rounds of the to-be-circulated business logic based on the parallelism N of the to-be-circulated business logic, to obtain the N circulation round groups of the to-be-circulated business logic, comprises: The target background sub-process in the target database system divides the M circulation rounds of the to-be-circulated business logic based on the parallelism N of the to-be-circulated business logic, to obtain the N circulation round groups of the to-be-circulated business logic.
5. The method of claim 4, wherein, The target background sub-process in the target database system divides the M circulation rounds of the to-be-circulated business logic based on the parallelism N of the to-be-circulated business logic, to obtain the N circulation round groups of the to-be-circulated business logic, comprises: When the target background sub-process executes the to-be-circulated business logic, the target background sub-process divides the M circulation rounds of the to-be-circulated business logic based on the parallelism N of the to-be-circulated business logic, to obtain the N circulation round groups of the to-be-circulated business logic.
6. The method of claim 4, wherein, The target background sub-process in the target database system divides the M circulation rounds of the to-be-circulated business logic based on the parallelism N of the to-be-circulated business logic, to obtain the N circulation round groups of the to-be-circulated business logic, comprises: The target background sub-process sets N initial circulation round groups based on the parallelism N of the to-be-circulated business logic; The target background sub-process sequentially distributes the M circulation rounds of the to-be-circulated business logic to the N initial circulation round groups, to obtain the N circulation round groups of the to-be-circulated business logic.
7. The method according to any one of claims 1 to 3, characterized in that, Before the parallel execution of the N circulation round groups of the to-be-circulated business logic, further comprising: Triggering a parent process in the target database system to create N worker processes by a target background sub-process in the target database system; Distributing respective corresponding circulation round groups to the N worker processes by the target background sub-process; The parallel execution of the N circulation round groups of the to-be-circulated business logic comprises: Parallelly executing respective corresponding circulation round groups by the N worker processes.
8. The method of claim 7, wherein, The target background sub-process in the target database system triggers a parent process in the target database system to create N worker processes, including: sending a notification message to the parent process by the target background sub-process; the parent process responds to the notification message to create the N worker processes.
9. The method of claim 7, wherein, The target background sub-process in the target database system triggers a parent process in the target database system to create N worker processes, including: scheduling a worker process creation function by the target background sub-process to make the parent process create the N worker processes.
10. The method of claim 7, wherein, Before the N worker processes execute the respective corresponding cycle round groups in parallel, further including: applying for shared memory of the N worker processes by the parent process; allocating memory space in the shared memory to the N worker processes respectively by the parent process; notifying the respective corresponding memory space of the N worker processes respectively by the parent process; and notifying the respective corresponding memory space of the N worker processes to the target background sub-process; writing the respective corresponding cycle round groups of the N worker processes into the respective corresponding memory space of the N worker processes by the target background sub-process; reading the respective corresponding cycle round groups from the respective corresponding memory space by the N worker processes respectively.
11. The method of claim 10, wherein, The target background sub-process in the target database system triggers a parent process in the target database system to create N worker processes, including: writing the respective corresponding cycle round groups of the N worker processes into the respective corresponding memory space of the N worker processes by the target background sub-process in the form of an asynchronous message queue.
12. The method according to claim 10 or 11, characterized in that, Before the N worker processes execute the respective corresponding cycle round groups in parallel, further including: obtaining context data of the to-be-circulated business logic by the target background sub-process; wherein, if there is a first business logic, the first business logic is a business logic in the target business logic before the to-be-circulated business logic, then the context data includes: the associated data of the first business logic and the to-be-circulated business logic; if there is no first business logic, the context data includes: the to-be-circulated business logic; serializing the context data by the target background sub-process to obtain serialized data; storing the serialized data into the shared memory by the target background sub-process; The N worker processes execute the respective corresponding cycle round groups in parallel, including: reading the serialized data in the shared memory by the N worker processes; de-serializing the serialized data by the N worker processes to obtain the context data; the N worker processes execute the respective corresponding cycle round groups in parallel based on the context data.
13. The method of claim 12, wherein, The target background sub-process serializes the context data to obtain serialized data, including: obtaining, by the target background sub-process, data types and corresponding values of each variable in the context data; composing, by the target background sub-process, the data types and corresponding values of each variable into the serialized data.
14. The method of claim 13, wherein, The deserializing, by the N worker processes, the serialized data to obtain the context data, comprises: The N worker processes construct data structures of the variables based on the data types and corresponding values of the variables. The context data comprises the data structures of the variables.
15. The method of claim 7, wherein, After the N worker processes execute the respective corresponding groups of loop rounds in parallel, the method further comprises: After the N worker processes execute the respective corresponding groups of loop rounds, the N worker processes notify the target background sub-process that the respective corresponding groups of loop rounds have been executed.
16. The method of claim 15, wherein, The method further comprises: If there is second business logic, which is business logic of the target business located after the business logic to be looped, the target background sub-process executes the second business logic after determining that the N groups of loop rounds have been executed.
17. A service execution apparatus characterized by comprising: comprises: a communication module and a processing module; The communication module is configured to obtain a parallel degree N of business logic to be looped of a target business; wherein N is a positive integer; The processing module is configured to divide M loop rounds of the business logic to be looped based on the parallel degree N of the business logic to be looped, to obtain N groups of loop rounds of the business logic to be looped; wherein M is an integer greater than or equal to N; The processing module is further configured to execute the N groups of loop rounds of the business logic to be looped in parallel.
18. An electronic device, comprising: comprises: a processor and a memory, the memory is configured to store a computer program, and the processor is configured to call and run the computer program stored in the memory to execute the method in any one of claims 1 to 16.
19. A computer-readable storage medium, characterized in that, A computer program for storing, the computer program causes a computer to execute the method in any one of claims 1 to 16.
20. A computer program product comprising computer programs / instructions, characterized in that, The computer program / instruction is executed by the processor to implement the method in any one of claims 1 to 16.