CN114463131A - Transaction processing method and device, storage medium and electronic equipment - Google Patents

Transaction processing method and device, storage medium and electronic equipment Download PDF

Info

Publication number
CN114463131A
CN114463131A CN202210121354.6A CN202210121354A CN114463131A CN 114463131 A CN114463131 A CN 114463131A CN 202210121354 A CN202210121354 A CN 202210121354A CN 114463131 A CN114463131 A CN 114463131A
Authority
CN
China
Prior art keywords
thread
task
processed
transaction
processing
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202210121354.6A
Other languages
Chinese (zh)
Inventor
关中博
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Jilin Yillion Bank Co ltd
Original Assignee
Jilin Yillion Bank Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Jilin Yillion Bank Co ltd filed Critical Jilin Yillion Bank Co ltd
Priority to CN202210121354.6A priority Critical patent/CN114463131A/en
Publication of CN114463131A publication Critical patent/CN114463131A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06QINFORMATION AND COMMUNICATION TECHNOLOGY [ICT] SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES; SYSTEMS OR METHODS SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES, NOT OTHERWISE PROVIDED FOR
    • G06Q40/00Finance; Insurance; Tax strategies; Processing of corporate or income taxes
    • G06Q40/04Trading; Exchange, e.g. stocks, commodities, derivatives or currency exchange
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/48Program initiating; Program switching, e.g. by interrupt
    • G06F9/4806Task transfer initiation or dispatching
    • G06F9/4843Task transfer initiation or dispatching by program, e.g. task dispatcher, supervisor, operating system
    • G06F9/4881Scheduling strategies for dispatcher, e.g. round robin, multi-level priority queues

Landscapes

  • Engineering & Computer Science (AREA)
  • Business, Economics & Management (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • Accounting & Taxation (AREA)
  • Finance (AREA)
  • Software Systems (AREA)
  • General Physics & Mathematics (AREA)
  • Development Economics (AREA)
  • Technology Law (AREA)
  • General Business, Economics & Management (AREA)
  • Strategic Management (AREA)
  • Marketing (AREA)
  • Economics (AREA)
  • General Engineering & Computer Science (AREA)
  • Debugging And Monitoring (AREA)

Abstract

The invention provides a transaction processing method and device, a storage medium and electronic equipment, wherein the method comprises the following steps: when a processing request of a transaction to be processed is received, determining a target thread number corresponding to the transaction to be processed; determining a target task execution strategy corresponding to a transaction to be processed in a plurality of preset task execution strategies; creating a task thread pool corresponding to the target task execution strategy, wherein the thread number of the task thread pool is the same as the target thread number; determining a plurality of to-be-processed tasks corresponding to the to-be-processed transaction, calling each thread in a task thread pool based on a target task execution strategy, and processing each to-be-processed task; and finishing the processing process of the transaction to be processed after finishing the processing process of each task to be processed. The method of the invention can automatically establish the thread pool to execute the task according with the execution strategy of the response requirement of the transaction to be processed, and does not need the user to establish the thread pool for targeted processing, thereby reducing the workload and improving the efficiency.

Description

Transaction processing method and device, storage medium and electronic equipment
Technical Field
The present invention relates to the field of computer technologies, and in particular, to a transaction processing method and apparatus, a storage medium, and an electronic device.
Background
In the operation process of enterprise institutions such as banks, application systems are often adopted to process various transactions. As the amount of transactions increases, the application system usually processes the transactions in a multi-thread manner during the process of processing the transactions, so as to improve the processing efficiency of the transactions.
Currently, in a multi-thread scenario, an application system usually employs a thread pool of a default execution mode to process transactions. Different types of transactions actually have different response requirements, and the same type of thread pool is adopted to process different types of transactions, so that the response requirements of various types of transactions are difficult to meet. If a user needs to adopt other types of thread pools to process a certain transaction, the user needs to create a corresponding thread pool by himself, and the process is very complicated, the workload is large, and the efficiency is low.
Disclosure of Invention
In view of this, the embodiment of the present invention provides a transaction processing method to solve the problems that a user needs to create a thread pool by himself, the process is complicated, the workload is large, and the efficiency is low.
The embodiment of the invention also provides a transaction processing device which is used for ensuring the actual realization and application of the method.
In order to achieve the above purpose, the embodiments of the present invention provide the following technical solutions:
a transaction processing method, comprising:
when a processing request of a transaction to be processed is received, determining a target thread number corresponding to the transaction to be processed;
determining a target task execution strategy corresponding to the transaction to be processed in a plurality of preset task execution strategies;
creating a task thread pool corresponding to the target task execution strategy, wherein the thread number of the task thread pool is the same as the target thread number;
determining a plurality of to-be-processed tasks corresponding to the to-be-processed transaction, calling each thread in the task thread pool based on the target task execution strategy, and processing each to-be-processed task;
and when the processing process of each task to be processed is finished, ending the processing process of the transaction to be processed.
Optionally, the determining a target thread number corresponding to the to-be-processed transaction includes:
determining each first system parameter, and calculating a first thread number according to each first system parameter; each first system parameter is a parameter representing the use condition of the current system resource;
judging whether the transaction to be processed meets a preset parameter self-defining condition or not;
if the transaction to be processed meets the preset parameter self-defining condition, acquiring a second thread number contained in a processing request of the transaction to be processed; the second thread number is a thread number preset by a user;
judging whether the second thread number is larger than the first thread number;
if the second thread number is larger than the first thread number, taking the first thread number as the target thread number;
and if the second thread number is not larger than the first thread number, taking the second thread number as the target thread number.
The above method, optionally, further includes:
and if the transaction to be processed does not meet the preset parameter self-defining condition, taking the first thread number as the target thread number.
Optionally, in the method, the preset multiple task execution policies include an automatic capacity expansion task processing policy, and the target task execution policy is the automatic capacity expansion task processing policy;
judging whether the task thread pool meets a preset parameter adjusting condition or not in the process of processing each task to be processed;
when the task thread pool meets the preset parameter adjusting condition, determining a current resource parameter set, wherein the current resource parameter set comprises each resource occupation parameter and each second system parameter corresponding to each thread in the current task thread pool, and each second system parameter is a parameter representing the use condition of the current system resource;
determining a third thread number according to the current resource parameter set;
and adjusting the thread number of the task thread pool based on the third thread number.
The above method, optionally, further includes:
and recording an operation log corresponding to the transaction to be processed.
The above method, optionally, further includes:
monitoring whether each thread in the task thread pool is in an abnormal operation state;
and when any thread in the task thread pool is monitored to be in an abnormal operation state, determining abnormal information corresponding to the thread in the abnormal operation state.
The above method, optionally, further includes:
and destroying the task thread pool after finishing the processing process of the transaction to be processed.
A transaction processing device comprising:
the system comprises a first determining unit, a second determining unit and a processing unit, wherein the first determining unit is used for determining a target thread number corresponding to a to-be-processed transaction when a processing request of the to-be-processed transaction is received;
the second determining unit is used for determining a target task execution strategy corresponding to the transaction to be processed in a plurality of preset task execution strategies;
the creating unit is used for creating a task thread pool corresponding to the target task execution strategy, and the thread number of the task thread pool is the same as the target thread number;
a third determining unit, configured to determine multiple to-be-processed tasks corresponding to the to-be-processed transaction, and based on the target task execution policy, invoke each thread in the task thread pool, and process each to-be-processed task;
and the processing unit is used for finishing the processing process of the transaction to be processed after finishing the processing process of each task to be processed.
A storage medium comprising stored instructions, wherein the instructions, when executed, control a device on which the storage medium is located to perform a transaction processing method as described above.
An electronic device comprising a memory, and one or more instructions, wherein the one or more instructions are stored in the memory and configured to be executed by one or more processors to perform a transaction processing method as described above.
Based on the above-mentioned transaction processing method provided by the embodiment of the present invention, the method includes: when a processing request of a transaction to be processed is received, determining a target thread number corresponding to the transaction to be processed; determining a target task execution strategy corresponding to a transaction to be processed in a plurality of preset task execution strategies; creating a task thread pool corresponding to a target task execution strategy, wherein the thread number of the task thread pool is the same as the target thread number; determining a plurality of to-be-processed tasks corresponding to the to-be-processed transaction, calling each thread in a task thread pool based on a target task execution strategy, and processing each to-be-processed task; and finishing the processing process of the transaction to be processed after finishing the processing process of each task to be processed. By applying the method provided by the embodiment of the invention, various task execution strategies can be configured in advance, and the corresponding task thread pool can be automatically established according to the corresponding target task execution strategy in the transaction processing process. The method can provide a uniform transaction processing entrance for the user, the user can submit the transaction triggering processing request to be processed without creating thread pools for different types of transactions, the workload can be reduced, and the transaction processing efficiency can be improved.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the embodiments or the prior art will be briefly described below, it is obvious that the drawings in the following description are only embodiments of the present invention, and for those skilled in the art, other drawings can be obtained according to the provided drawings without creative efforts.
FIG. 1 is a flowchart of a method of transaction processing according to an embodiment of the present invention;
FIG. 2 is a flowchart of another method of a transaction processing method according to an embodiment of the present invention;
FIG. 3 is a schematic diagram illustrating module invocation during transaction processing according to an embodiment of the present invention;
fig. 4 is a flowchart illustrating a thread pool processing procedure according to an embodiment of the present invention;
FIG. 5 is a flowchart illustrating a thread pool processing procedure according to an embodiment of the present invention;
fig. 6 is a schematic structural diagram of a transaction processing apparatus according to an embodiment of the present invention;
fig. 7 is a schematic structural diagram of an electronic device according to an embodiment of the present invention.
Detailed Description
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
In this application, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other identical elements in a process, method, article, or apparatus that comprises the element.
As can be seen from the background art, in an actual application scenario, different kinds of transactions may have different response requirements, for example, a customer needs to check a certain bank product, the system needs to query a series of information to be displayed to the customer, and from the perspective of the customer experience, the result response is faster and better. If a certain report needs to be counted for subsequent marketing analysis, a large number of calculation tasks exist, but the calculation tasks do not need to be completed instantly, and the effective utilization of resources can be emphasized. Under different response requirements, different task execution modes can be actually adopted to call threads to process transactions, in the current system processing process, different types of transactions are usually processed by adopting the same execution mode, if a user wants to adopt a task execution mode which is more in line with the requirements aiming at different types of transactions, the user needs to define and create a thread pool by himself, the process is very complicated, the workload is large, and the transaction processing efficiency is low.
Therefore, the embodiment of the invention provides a transaction processing method, which can preset various task execution strategies, create a thread pool according to the corresponding task execution strategy to process transactions when the transactions are processed, and does not need to be created by a user, thereby reducing the workload and improving the transaction processing efficiency.
The embodiment of the invention provides a transaction processing method, which can be applied to various business systems, wherein an execution main body of the transaction processing method can be a processor of the system, and a method flow chart of the method is shown in figure 1 and comprises the following steps:
s101: when a processing request of a transaction to be processed is received, determining a target thread number corresponding to the transaction to be processed;
in the method provided by the embodiment of the invention, a user can send a processing request of the transaction to be processed through a front-end interface of a current business system, wherein the current business system is a system for processing the transaction to be processed. When the processor of the system receives the processing request, the target thread number corresponding to the current transaction to be processed, that is, the thread number of the thread pool for processing the transaction to be processed, can be determined according to a preset thread number setting strategy.
S102: determining a target task execution strategy corresponding to the transaction to be processed in a plurality of preset task execution strategies;
in the method provided by the embodiment of the present invention, a plurality of task execution policies may be preconfigured in the system, where a task execution policy refers to a specific policy for invoking a multithread processing task, and may include, for example, a fixed-length task processing policy, a timing task processing policy, and the like, where the fixed-length task processing policy refers to creating a fixed-length thread pool, the maximum concurrent number of threads is a preset fixed value, and when no idle thread processes a task, an excess task may wait in a queue. The timing task processing strategy refers to calling a thread processing task according to a preset time interval on the basis of a fixed-length thread pool. The task execution strategy can be set according to the response requirements of various transactions needing to be processed by the service system, and can be made based on the existing thread calling strategy and thread pool type, so that the method provided by the embodiment of the invention is not influenced.
The user can select the task execution strategy corresponding to the to-be-processed transaction at the front end of the system, and the front end responds to the selection operation of the user and can generate a processing request based on the strategy identification corresponding to the task execution strategy corresponding to the current to-be-processed transaction, namely the processing request contains the strategy identification. The system may preset policy identifiers corresponding to various task execution policies, and match the policy identifiers included in the processing request with the policy identifiers preset in the system, so as to determine the task execution policy corresponding to the policy identifier included in the processing request among the preset multiple task execution policies, and use the task execution policy as the target task execution policy.
S103: creating a task thread pool corresponding to the target task execution strategy, wherein the thread number of the task thread pool is the same as the target thread number;
in the method provided by the embodiment of the invention, the preset task execution strategy comprises the type of the thread pool to be executed. The thread pool of the specified type in the policy can be created according to the policy content of the target task type policy, and the number of threads in the thread pool is the target thread number, that is, the maximum concurrency number of threads in the thread pool is the target thread number.
S104: determining a plurality of to-be-processed tasks corresponding to the to-be-processed transaction, calling each thread in the task thread pool based on the target task execution strategy, and processing each to-be-processed task;
in the method provided by the embodiment of the invention, the processing request of the transaction to be processed can be analyzed, and a plurality of tasks to be processed corresponding to the transaction to be processed are created. And calling each thread in the task thread pool to execute each task to be processed according to the target task execution strategy. For example, if the target task execution policy is a fixed-length task processing policy, an idle thread is called, a thread is sequentially allocated to each task to be processed, and a thread corresponding to the task to be processed is called to process the task to be processed. And if no idle thread exists currently, putting the tasks to be processed of the unallocated threads into a queue to wait.
S105: and when the processing process of each task to be processed is finished, ending the processing process of the transaction to be processed.
In the method provided by the embodiment of the invention, after each task to be processed is processed, the processing process of the transaction to be processed can be regarded as completed. By monitoring the processing progress of each task to be processed, after receiving the processing results of all the tasks to be processed, the processing progress of the transaction to be processed is obtained, and in the actual application process, the processing result of the task to be processed can be a task success or a task failure.
Based on the method provided by the embodiment of the invention, when a processing request of a transaction to be processed is received, the target thread number can be determined. And determining a target task execution strategy corresponding to the transaction to be processed in a plurality of preset task execution strategies. And creating a task thread pool with the thread number corresponding to the target thread number according to the target task execution strategy. Determining a plurality of to-be-processed tasks corresponding to the to-be-processed transaction, calling each thread in the task thread pool based on a target task execution strategy, and processing each to-be-processed task. And finishing the processing process of the transaction to be processed after finishing the processing process of each task to be processed. By applying the method provided by the embodiment of the invention, a user can initiate various transactions through a uniform entrance, and when the system processes the current transaction to be processed, the target execution strategy corresponding to the transaction to be processed can be determined in the preset multiple task execution strategies to create the thread pool corresponding to the transaction to perform transaction processing, so that the response requirements of different types of transactions can be met, the user does not need to manually create the thread pool aiming at the transaction, the workload can be reduced, and the transaction processing efficiency can be improved.
To better illustrate the method provided by the embodiment of the present invention, on the basis of the method shown in fig. 1, in conjunction with the flowchart shown in fig. 2, the embodiment of the present invention provides another transaction processing method. In the method provided in the embodiment of the present invention, the process of determining the target thread number corresponding to the transaction to be processed in step S101 includes:
s201: determining each first system parameter, and calculating a first thread number according to each first system parameter; each first system parameter is a parameter representing the use condition of the current system resource;
in the method provided by the embodiment of the invention, the system can monitor each parameter representing the service condition of the system resource in real time, such as the current CPU utilization rate, the memory utilization rate, the total number of processes, the number of processes in operation, the number of sleeping processes, the number of CPUs, the percentage of idle CPUs and the like. The system is pre-configured with a thread number setting strategy, and the thread number matched with the idle resource of the current system, namely the thread number which can be borne by the current idle resource of the system, can be calculated and obtained based on each system parameter representing the service condition of the current system resource, and then the threads with the number are created, so that the resource overload of the system can not be caused.
S202: judging whether the transaction to be processed meets a preset parameter self-defining condition or not;
in the method provided by the embodiment of the invention, the system front end can provide a configuration interface for customizing the thread number by a user, the user can set the thread number through the system front end, and the system front end can generate a processing request according to the thread number set by the user, namely, parameters in the processing request represent whether the user sets the thread number. The method includes the steps of obtaining a request parameter which indicates whether a user sets the number of threads in a processing request of a transaction to be processed, judging whether the request parameter is the same as the parameter which indicates the number of the threads set, if so, determining that the transaction to be processed meets a preset parameter self-defining condition, and entering step S203. If not, determining that the transaction to be processed does not meet the preset parameter self-defining condition, and entering step S207.
S203: acquiring a second thread number contained in a processing request of the transaction to be processed; the second thread number is a thread number preset by a user;
in the method provided by the embodiment of the present invention, if the to-be-processed transaction meets the preset parameter customization condition, that is, the user sets the number of threads, the processing request of the to-be-processed transaction includes a corresponding parameter for indicating the number of threads set by the user. The number of threads included in the processing request of the pending transaction, i.e., the number of threads set by the user, may be obtained.
S204: judging whether the second thread number is larger than the first thread number;
in the method provided in the embodiment of the present invention, the number of threads (i.e., the second number of threads) set by the user may be compared with the number of threads (i.e., the first number of threads) calculated according to each system parameter, and if the second number of threads is greater than the first number of threads, the process proceeds to step S205. If the second thread number is less than or equal to the first thread number, the process proceeds to step S206.
S205: taking the first thread number as the target thread number;
in the method provided by the embodiment of the present invention, if the second thread number is greater than the first thread number, that is, the thread number calculated according to each system parameter representing the current system resource usage, is used as a target thread number, and a thread pool whose thread number corresponds to the first thread number is subsequently created.
S206: taking the second thread number as the target thread number.
In the method provided by the embodiment of the present invention, if the second thread number is not greater than the first thread number, the second thread number, that is, the thread number set by the user, is used as a target thread number, and a thread pool whose thread number corresponds to the second thread number is created subsequently.
Further, the method provided by the embodiment of the present invention further includes:
s207: taking the first thread number as the target thread number.
In the method provided in the embodiment of the present invention, in the determination process of step S202, if the transaction to be processed does not meet the preset parameter customization condition, the first thread number is used as a target thread number, that is, a thread pool is created according to the thread number determined according to the usage of system resources.
Based on the method provided by the embodiment, the user can set the number of threads by himself, and if the number set by the user meets the system operation requirement, the number set by the user is used as the target number of threads to be processed, so that the user experience of the user can be improved. If the number of threads is not set by the user or the set number of threads does not meet the running requirements of the system, the number of threads determined according to the current system resource use condition can be used as the target number of threads, the maximum concurrent number of threads can be effectively controlled, the utilization rate of the system resources is improved, excessive resource competition is avoided, and blockage is avoided.
Further, on the basis of the method shown in fig. 1, an embodiment of the present invention provides another transaction processing method, in the method provided in the embodiment of the present invention, the preset multiple task execution policies include an automatic capacity expansion task processing policy, and the target task execution policy is the automatic capacity expansion task processing policy;
judging whether the task thread pool meets a preset parameter adjusting condition or not in the process of processing each task to be processed;
in the method provided by the embodiment of the present invention, the preset multiple task execution policies include an automatic capacity expansion task processing policy, that is, a processing policy that can automatically change the number of threads in the thread pool (the maximum concurrent number of threads) according to a requirement. And when the target task execution strategy corresponding to the transaction to be processed is the automatic capacity expansion task processing strategy, the target thread number is only the initial thread number of the task thread pool. And in the process of calling each thread processing task of the task thread pool, whether the task thread pool meets the preset parameter adjusting condition can be judged in real time. Specifically, a resource parameter range, i.e., an upper threshold and a lower threshold, may be preset. And monitoring system parameters such as memory utilization rate, CPU utilization rate and the like in real time. And judging whether each system parameter is in a preset resource parameter range in real time, if so, determining that the task thread pool meets a preset parameter adjusting condition if the system parameter exceeds a preset upper limit threshold or is lower than a preset lower limit threshold, and if not, determining that the task thread pool meets the preset parameter adjusting condition. And if the system parameters are still in the preset resource parameter range, determining that the task thread pool does not accord with the preset parameter adjusting conditions. The type of the monitored system parameters can be determined according to actual application requirements, corresponding parameter ranges can be configured for each type of system parameters in the configuration process, the system parameters can also be configured uniformly, at least one parameter which is not in the preset resource parameter range can be regarded as a conforming condition in the judgment process, all the parameters which are not in the preset resource parameter range can also be regarded as a conforming condition, and the method provided by the embodiment of the invention is not influenced in realizing functions.
When the task thread pool meets the preset parameter adjusting condition, determining a current resource parameter set, wherein the current resource parameter set comprises each resource occupation parameter and each second system parameter corresponding to each thread in the current task thread pool, and each second system parameter is a parameter representing the use condition of the current system resource;
in the method provided by the embodiment of the present invention, when it is determined that the task thread pool meets the preset parameter adjusting condition, system parameters (second system parameters) representing the current system resource condition, such as the current CPU utilization, the memory utilization, the total number of processes, the number of running processes, the number of sleeping processes, the number of CPUs, the percentage of idle CPUs, and the like, may be obtained. Each second system parameter may be the same type of system parameter as each first system parameter mentioned in the above embodiment, but the obtained time points are different, and they respectively represent the system resource usage at the information obtaining time points. Meanwhile, resource occupation parameters, such as occupied memory and the like, corresponding to each thread in the current task thread pool can be obtained.
Determining a third thread number according to the current resource parameter set;
in the method provided by the embodiment of the invention, the thread number matched with the current system resource can be calculated according to the current resource parameter set, namely, the thread number which can be borne by the resource which can be reasonably distributed to the current task thread pool, namely, the third thread number, is obtained when the system bears other loads.
And adjusting the thread number of the task thread pool based on the third thread number.
In the method provided by the embodiment of the invention, the number of threads in the task thread pool can be adjusted to be the third number of threads, and if the third number of threads is greater than the current number of threads in the task thread pool, a new thread is created in the task thread pool until the number of threads in the task thread pool is the same as the third number of threads. If the third thread number is smaller than the current thread number of the task thread pool, acquiring idle threads for destroying when the idle threads exist in the task thread pool, and if the idle threads do not exist currently, waiting for the threads to finish the current task until the thread number in the task thread pool is the same as the third thread number.
The method provided by the embodiment of the invention can dynamically adjust the number of threads in the task thread pool, automatically create a reasonable number of threads, and can solve the problems of resource waste caused by too low utilization rate or resource exhaustion caused by too high utilization rate.
Further, on the basis of the method provided by the above embodiment, the method provided by the embodiment of the present invention further includes:
and recording an operation log corresponding to the transaction to be processed.
In the method provided by the embodiment of the invention, the operation log corresponding to the transaction to be processed, namely the log generated in the process of operating the program for processing the transaction can be recorded, the log management can be uniformly carried out, and a log printing inlet is provided for analyzing the subsequent work such as the operation efficiency, the problem location and the like.
Further, on the basis of the method provided by the above embodiment, the method provided by the embodiment of the present invention further includes:
monitoring whether each thread in the task thread pool is in an abnormal operation state;
and when any thread in the task thread pool is monitored to be in an abnormal operation state, determining abnormal information corresponding to the thread in the abnormal operation state.
In the method provided by the embodiment of the invention, the running state of each thread can be monitored, and when any thread is monitored to be in an abnormal running state, corresponding abnormal information can be recorded for subsequent analysis work or fed back to a user.
Further, on the basis of the method provided by the above embodiment, the method provided by the embodiment of the present invention further includes:
and destroying the task thread pool after finishing the processing process of the transaction to be processed.
In the method provided by the embodiment of the invention, after each task of the transaction to be processed is processed, the task thread pool can be destroyed, namely, each thread in the task thread pool is destroyed, and system resources are released.
In a specific implementation process, the method provided by the embodiment of the invention can be implemented by configuring each functional module and implementing functions through module calling. In order to better explain the method provided by the embodiment of the present invention, on the basis of the method provided by the above embodiment, the embodiment of the present invention provides another transaction processing method, and then, the transaction processing process provided by the embodiment of the present invention is further explained in conjunction with a specific module call.
As shown in fig. 3, the main function modules configured in the system include a scheduling module, a parameter processing module, a tool class module, a multi-task processing module, a fixed-length task processing module, an automatic capacity-expansion task processing module, a timing data processing module, an exception handling module, a log printing module, a response data processing module, and an execution efficiency analysis module. The multi-thread processing module, the fixed-length task processing module, the automatic capacity-expansion task processing module and the timing data processing module are multi-thread processing modules respectively corresponding to various task execution strategies and used for creating a thread pool according to the corresponding strategies and calling thread processing tasks.
The main functions of the individual functional modules are as follows:
the main functions of the scheduling module in the embodiment of the invention are as follows: and calling different function modules according to the method call and request incoming parameters (parameters such as whether a user defines the thread number, the thread number of concurrent tasks, the task type, namely a target task execution strategy and the like).
The pseudo code implementing the function of the scheduling module is described as follows:
if (custom) final check
switch (task type) ready pocket
case "fixed length":
"call fixed-length task processing module (number of incoming threads)";
break;
case "expand":
calling an automatic capacity expansion task processing module (the number of incoming threads)';
break;
case "timing":
"call timing data processing module (number of incoming threads)";
break;
case "multitask":
"call multitask module (number of incoming threads)";
break;
}
}else{
"calling entry processing module (number of incoming threads)"
"calling execution efficiency analysis module (number of incoming threads)"
if ("incoming thread number" > "calculated thread number"). a last eye
return "incoming thread count — calculated thread count";
}
return "number of incoming threads";
}
}
switch (task type) ready pocket
case "fixed length":
"call fixed-length task module (number of incoming threads)";
break;
case "expand":
calling an automatic capacity expansion task processing module (the number of incoming threads)';
break;
case "timing":
"call timing data processing module (number of incoming threads)";
break;
case "multitask":
"call multitask data processing Module (number of incoming threads)";
break;
}
}
return "return execution result";
}。
the embodiment of the invention has the main functions of the reference processing module: and acquiring various system parameters (parameters such as the total number of processes, the number of running processes, the number of CPU cores and the like) by calling a tool module, judging whether the number of the transmitted concurrent task threads is reasonable or not, replacing partial parameters or not, and returning to the finally determined number of the threads.
The fixed-length task processing module in the embodiment of the invention has the main functions as follows: and according to the input parameters, creating an initial fixed number of thread pools, executing the multi-thread tasks, wherein the number of the tasks to be processed is greater than the number of the created concurrent threads, the thread processing tasks are not generated continuously, when the created threads are in an idle state, the created threads are not destroyed, but new tasks are executed, and all the tasks are finished and all the threads are automatically destroyed. In an actual application scenario, the tasks processed by the fixed-length task processing module are generally the same kind of tasks, for example, transactions of a statistical form, and each corresponding task is to read and write data of a certain row, and the like.
As shown in fig. 4, the thread pool processing procedure executed by the fixed-length task processing module includes: and setting the thread number of the thread pool according to the transmitted thread number, judging whether the current thread number is larger than or equal to the thread number of the set thread pool when receiving a task to be processed of a transaction to be processed, if not, continuously creating a new thread and calling the new thread to execute the task. If the current thread number reaches the set thread number, judging whether the thread pool queue is full, if the queue is not full, putting the task into the queue, and calling the idle thread to execute the task in the queue when waiting for the idle thread in the thread pool. If the queue is full, the current task is rejected.
The multitasking module in the embodiment of the invention has the following main functions: through the module, a plurality of tasks which are not interfered with each other can be quickly established, and the main thread waits for the sub-threads to finish the tasks and returns results. In an actual application scenario, the tasks processed by the multitasking module are generally different kinds of tasks, such as transacting a certain business, and each corresponding task is a sub-transaction for processing different items.
As shown in fig. 5, the thread pool processing procedure executed by the multitasking module includes: a fixed-length thread pool is created from the number of incoming threads. And calling each thread to execute each task respectively, monitoring whether each task is executed completely, if not, judging whether the execution time is over the preset execution time, if so, determining that the task is abnormal overtime, and feeding back the abnormality to a user. If not, continuing to wait. And after the task is executed, ending the whole process and returning the result.
The timing data processing module in the embodiment of the invention has the main functions as follows: and according to the incoming time and the incoming interval time, a fixed number of threads are created in a timed mode to execute tasks. When the module is called, the processing request of the transaction is usually configured with an interval time, that is, the current transaction has a requirement for the processing time, and a time interval corresponding to the requirement is set. The module may trigger the creation, invocation, and execution of threads at specified times.
The main functions of the automatic capacity expansion task processing module in the embodiment of the invention are as follows: and dynamically configuring task concurrency quantity according to the resource condition of the system in real time, if the task concurrency quantity is less than the number of established threads, automatically recovering the threads, and otherwise, automatically establishing new threads. By the internal encapsulation method, unlimited creation of threads can be prevented.
The tool type module in the embodiment of the invention has the main functions as follows: monitoring various system parameters of the system, such as the number of CPUs, the CPU utilization rate, the memory condition and the like, and feeding back the collected various system parameters to the scheduling module for calculating the number of threads.
The log printing module in the embodiment of the invention has the main functions as follows: unified log management, printing logs in the running process of the program, wherein the recording range of the logs comprises logs generated from the starting time to the ending time of the running process, and the logs are used for analyzing the running efficiency and quickly positioning problems.
The main functions of the response data processing module in the embodiment of the invention are as follows: and for asynchronous tasks with return values, acquiring the return values, performing necessary processing and returning.
The main functions of the exception handling module in the embodiment of the invention are as follows: when the multithread operation generates abnormity, the module is used for packaging and returning the abnormity information.
The execution efficiency analysis module in the embodiment of the invention has the main functions as follows: by calling the module, a List set is returned, and the content of the set comprises the number of CPUs, the utilization rate of the CPUs, the total number of processes, the number of sleeping processes, the percentage of idle CPUs and the like. Meanwhile, the module calculates the thread number according with the current resource use condition of the system according to the List set, and is used for setting the initial thread number of the thread pool or adjusting the thread number for automatic capacity expansion.
In the method provided by the embodiment of the invention, the thread pool abstract packaging is optimized by adopting a pooling design mode, so that the manageability is realized. And providing a bounded queue or an unbounded queue, buffering the tasks, waiting for scheduling, and achieving the effects of peak clipping and valley filling.
According to the method provided by the embodiment of the invention, the survival time of the thread is encapsulated, so that the problem that the thread is not released due to thread deadlock can be solved.
In the method provided by the embodiment of the invention, any queue has a critical point, and when the queue reaches a peak value, the abnormal information is printed and displayed to a worker through a reasonable rejection strategy, so that the problem is convenient to locate.
The method provided by the embodiment of the invention can reduce resource consumption, repeatedly utilize existing threads, reduce the expenses of object creation and extinction, improve the performance, effectively control the maximum concurrent thread number, improve the utilization rate of system resources, avoid excessive resource competition, avoid blockage and provide the control functions of timing, regular execution and concurrent number. A user can send a transaction processing request through a uniform entrance, and then the system can be triggered to automatically call the processing module of the corresponding type of strategy, and a thread pool calling thread is created according to the corresponding execution mode, so that the response requirements of different types of transactions can be met. In the process, the staff does not need to execute technical operations such as thread pool creation and the like, so that the workload of the staff can be reduced, the user experience is improved, and the transaction processing efficiency is improved.
Corresponding to the transaction processing method shown in fig. 1, an embodiment of the present invention further provides a transaction processing apparatus, which is used for implementing the method shown in fig. 1, and a schematic structural diagram of the transaction processing apparatus is shown in fig. 6, and includes:
a first determining unit 301, configured to determine, when a processing request of a to-be-processed transaction is received, a target thread number corresponding to the to-be-processed transaction;
a second determining unit 302, configured to determine, in multiple preset task execution policies, a target task execution policy corresponding to the to-be-processed transaction;
a creating unit 303, configured to create a task thread pool corresponding to the target task execution policy, where the number of threads in the task thread pool is the same as the number of the target threads;
a third determining unit 304, configured to determine multiple to-be-processed tasks corresponding to the to-be-processed transaction, and call, based on the target task execution policy, each thread in the task thread pool to process each to-be-processed task;
the processing unit 305 is configured to end the processing process of the to-be-processed transaction after completing the processing process of each to-be-processed task.
Based on the device provided by the embodiment of the invention, when a processing request of a transaction to be processed is received, the target thread number can be determined. And determining a target task execution strategy corresponding to the transaction to be processed in a plurality of preset task execution strategies. And creating a task thread pool with the thread number corresponding to the target thread number according to the target task execution strategy. Determining a plurality of to-be-processed tasks corresponding to the to-be-processed transaction, calling each thread in the task thread pool based on a target task execution strategy, and processing each to-be-processed task. And finishing the processing process of the transaction to be processed after finishing the processing process of each task to be processed. By applying the device provided by the embodiment of the invention, a user can initiate various transactions through a uniform entrance, and when the system processes the current transaction to be processed, the target execution strategy corresponding to the transaction to be processed can be determined in the preset multiple task execution strategies to create the thread pool corresponding to the transaction to perform transaction processing, so that the response requirements of different types of transactions can be met, the user does not need to manually create the thread pool aiming at the transaction, the workload can be reduced, and the transaction processing efficiency can be improved.
On the basis of the apparatus provided in the foregoing embodiment, in the apparatus provided in an embodiment of the present invention, the first determining unit 301 includes:
the first determining subunit is used for determining each first system parameter and calculating a first thread number according to each first system parameter; each first system parameter is a parameter representing the use condition of the current system resource;
the first judging subunit is used for judging whether the transaction to be processed meets a preset parameter self-defining condition;
the acquiring subunit is configured to acquire a second thread number included in a processing request of the transaction to be processed if the transaction to be processed meets the preset parameter customization condition; the second thread number is a thread number preset by a user;
a second judging subunit, configured to judge whether the second thread number is greater than the first thread number;
a second determining subunit, configured to take the first thread number as the target thread number if the second thread number is greater than the first thread number; and if the second thread number is not larger than the first thread number, taking the second thread number as the target thread number.
On the basis of the device provided by the above embodiment, the device provided by the embodiment of the present invention further includes:
and the third determining subunit is configured to, if the to-be-processed transaction does not meet the preset parameter customization condition, take the first thread number as the target thread number.
On the basis of the device provided in the foregoing embodiment, in the device provided in the embodiment of the present invention, the preset multiple task execution policies include an automatic capacity expansion task processing policy, and the target task execution policy is the automatic capacity expansion task processing policy;
the device provided by the embodiment of the invention further comprises: the parameter adjusting subunit is used for judging whether the task thread pool meets a preset parameter adjusting condition or not in the process of processing each task to be processed; when the task thread pool meets the preset parameter adjusting condition, determining a current resource parameter set, wherein the current resource parameter set comprises each resource occupation parameter and each second system parameter corresponding to each thread in the current task thread pool, and each second system parameter is a parameter representing the use condition of the current system resource; determining a third thread number according to the current resource parameter set; and adjusting the thread number of the task thread pool based on the third thread number.
On the basis of the device provided by the above embodiment, the device provided by the embodiment of the present invention further includes:
and the log recording unit is used for recording the running log corresponding to the transaction to be processed.
On the basis of the device provided by the above embodiment, the device provided by the embodiment of the present invention further includes:
the monitoring unit is used for monitoring whether each thread in the task thread pool is in an abnormal operation state;
and the exception recording unit is used for determining the exception information corresponding to the thread in the abnormal running state when any thread in the task thread pool is monitored to be in the abnormal running state.
On the basis of the device provided by the above embodiment, the device provided by the embodiment of the present invention further includes:
and the destroying unit is used for destroying the task thread pool after finishing the processing process of the transaction to be processed.
The embodiment of the invention also provides a storage medium, which comprises stored instructions, wherein when the instructions are executed, the device where the storage medium is located is controlled to execute the transaction processing method.
An electronic device is provided in an embodiment of the present invention, and the structural diagram of the electronic device is shown in fig. 7, which specifically includes a memory 401 and one or more instructions 402, where the one or more instructions 402 are stored in the memory 401 and configured to be executed by one or more processors 403 to perform the following operations for executing the one or more instructions 402:
when a processing request of a transaction to be processed is received, determining a target thread number corresponding to the transaction to be processed;
determining a target task execution strategy corresponding to the transaction to be processed in a plurality of preset task execution strategies;
creating a task thread pool corresponding to the target task execution strategy, wherein the thread number of the task thread pool is the same as the target thread number;
determining a plurality of to-be-processed tasks corresponding to the to-be-processed transaction, calling each thread in the task thread pool based on the target task execution strategy, and processing each to-be-processed task;
and after finishing the processing process of each task to be processed, finishing the processing process of the transaction to be processed.
The embodiments in the present specification are described in a progressive manner, and the same and similar parts among the embodiments are referred to each other, and each embodiment focuses on the differences from the other embodiments. In particular, the system or system embodiments are substantially similar to the method embodiments and therefore are described in a relatively simple manner, and reference may be made to some of the descriptions of the method embodiments for related points. The above-described system and system embodiments are only illustrative, wherein the units described as separate parts may or may not be physically separate, and the parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of the present embodiment. One of ordinary skill in the art can understand and implement it without inventive effort.
Those of skill would further appreciate that the various illustrative elements and algorithm steps described in connection with the embodiments disclosed herein may be implemented as electronic hardware, computer software, or combinations of both, and that the various illustrative components and steps have been described above generally in terms of their functionality in order to clearly illustrate this interchangeability of hardware and software. Whether such functionality is implemented as hardware or software depends upon the particular application and design constraints imposed on the technical solution. Skilled artisans may implement the described functionality in varying ways for each particular application, but such implementation decisions should not be interpreted as causing a departure from the scope of the present invention.
The previous description of the disclosed embodiments is provided to enable any person skilled in the art to make or use the present invention. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the generic principles defined herein may be applied to other embodiments without departing from the spirit or scope of the invention. Thus, the present invention is not intended to be limited to the embodiments shown herein but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.

Claims (10)

1. A transaction processing method, comprising:
when a processing request of a transaction to be processed is received, determining a target thread number corresponding to the transaction to be processed;
determining a target task execution strategy corresponding to the transaction to be processed in a plurality of preset task execution strategies;
creating a task thread pool corresponding to the target task execution strategy, wherein the thread number of the task thread pool is the same as the target thread number;
determining a plurality of to-be-processed tasks corresponding to the to-be-processed transaction, calling each thread in the task thread pool based on the target task execution strategy, and processing each to-be-processed task;
and when the processing process of each task to be processed is finished, ending the processing process of the transaction to be processed.
2. The method of claim 1, wherein determining the target number of threads for the pending transaction comprises:
determining each first system parameter, and calculating a first thread number according to each first system parameter; each first system parameter is a parameter representing the use condition of the current system resource;
judging whether the transaction to be processed meets a preset parameter self-defining condition or not;
if the to-be-processed transaction meets the preset parameter self-defining condition, acquiring a second thread number contained in a processing request of the to-be-processed transaction; the second thread number is a thread number preset by a user;
judging whether the second thread number is larger than the first thread number;
if the second thread number is larger than the first thread number, taking the first thread number as the target thread number;
and if the second thread number is not larger than the first thread number, taking the second thread number as the target thread number.
3. The method of claim 2, further comprising:
and if the transaction to be processed does not meet the preset parameter self-defining condition, taking the first thread number as the target thread number.
4. The method according to claim 1, wherein the preset multiple task execution policies include an automatic capacity expansion task processing policy, and the target task execution policy is the automatic capacity expansion task processing policy;
judging whether the task thread pool meets a preset parameter adjusting condition or not in the process of processing each task to be processed;
when the task thread pool meets the preset parameter adjusting condition, determining a current resource parameter set, wherein the current resource parameter set comprises each resource occupation parameter and each second system parameter corresponding to each thread in the current task thread pool, and each second system parameter is a parameter representing the use condition of the current system resource;
determining a third thread number according to the current resource parameter set;
and adjusting the thread number of the task thread pool based on the third thread number.
5. The method of claim 1, further comprising:
and recording an operation log corresponding to the transaction to be processed.
6. The method of claim 1, further comprising:
monitoring whether each thread in the task thread pool is in an abnormal running state;
and when any thread in the task thread pool is monitored to be in an abnormal operation state, determining abnormal information corresponding to the thread in the abnormal operation state.
7. The method of claim 1, further comprising:
and destroying the task thread pool after finishing the processing process of the transaction to be processed.
8. A transaction processing device, comprising:
the system comprises a first determining unit, a second determining unit and a processing unit, wherein the first determining unit is used for determining a target thread number corresponding to a to-be-processed transaction when a processing request of the to-be-processed transaction is received;
the second determining unit is used for determining a target task execution strategy corresponding to the transaction to be processed in a plurality of preset task execution strategies;
the creating unit is used for creating a task thread pool corresponding to the target task execution strategy, and the thread number of the task thread pool is the same as the target thread number;
a third determining unit, configured to determine multiple to-be-processed tasks corresponding to the to-be-processed transaction, and based on the target task execution policy, invoke each thread in the task thread pool, and process each to-be-processed task;
and the processing unit is used for finishing the processing process of the transaction to be processed after finishing the processing process of each task to be processed.
9. A storage medium comprising stored instructions, wherein the instructions, when executed, control a device on which the storage medium resides to perform a transaction processing method according to any one of claims 1 to 7.
10. An electronic device comprising a memory, and one or more instructions, wherein the one or more instructions are stored in the memory and configured to be executed by the one or more processors to perform the transaction processing method of any one of claims 1-7.
CN202210121354.6A 2022-02-09 2022-02-09 Transaction processing method and device, storage medium and electronic equipment Pending CN114463131A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202210121354.6A CN114463131A (en) 2022-02-09 2022-02-09 Transaction processing method and device, storage medium and electronic equipment

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202210121354.6A CN114463131A (en) 2022-02-09 2022-02-09 Transaction processing method and device, storage medium and electronic equipment

Publications (1)

Publication Number Publication Date
CN114463131A true CN114463131A (en) 2022-05-10

Family

ID=81412606

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202210121354.6A Pending CN114463131A (en) 2022-02-09 2022-02-09 Transaction processing method and device, storage medium and electronic equipment

Country Status (1)

Country Link
CN (1) CN114463131A (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115878664A (en) * 2022-11-24 2023-03-31 灵犀科技有限公司 Method and system for real-time query matching of mass input data
CN117112206A (en) * 2023-08-16 2023-11-24 中电金信软件有限公司 Transaction resource isolation method, device, computer equipment and storage medium

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115878664A (en) * 2022-11-24 2023-03-31 灵犀科技有限公司 Method and system for real-time query matching of mass input data
CN117112206A (en) * 2023-08-16 2023-11-24 中电金信软件有限公司 Transaction resource isolation method, device, computer equipment and storage medium

Similar Documents

Publication Publication Date Title
CN106802826B (en) Service processing method and device based on thread pool
CN114463131A (en) Transaction processing method and device, storage medium and electronic equipment
WO2021159638A1 (en) Method, apparatus and device for scheduling cluster queue resources, and storage medium
EP3335120B1 (en) Method and system for resource scheduling
CN111427751B (en) Method and system for processing business based on asynchronous processing mechanism
CN106569891B (en) Method and device for scheduling and executing tasks in storage system
CN111858065B (en) Data processing method, device, storage medium and device
US9003410B2 (en) Abstracting a multithreaded processor core to a single threaded processor core
CN108363623A (en) GPU resource dispatching method, device, equipment and computer readable storage medium
US8813082B2 (en) Thread priority based on object creation rates
CN109471711B (en) Task processing method and device
CN109298990A (en) Log storing method, device, computer equipment and storage medium
CN109542600B (en) Distributed task scheduling system and method
WO2020000668A1 (en) Server cluster-based task execution method and server
US7827282B2 (en) System and method for processing hardware or service usage data
CN114661476A (en) Task processing method, device, equipment and storage medium
CN110633133A (en) Task processing method and device and computer readable storage medium
CN107589993A (en) A kind of dynamic priority scheduling algorithm based on linux real time operating systems
CN110888726A (en) Multitask concurrent processing method and system
US8001341B2 (en) Managing dynamically allocated memory in a computer system
CN113867954A (en) Thread processing method, system and medium based on thread pool and object pool
CN111767125A (en) Task execution method and device, electronic equipment and storage medium
CN114661415A (en) Scheduling method and computer system
CN114157717A (en) Micro-service dynamic current limiting system and method
CN113742059A (en) Task allocation method and device, computer equipment and storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination