当前位置:网站首页>Chapter 18 using work queue manager (1)

Chapter 18 using work queue manager (1)

2022-07-05 08:28:00 yaoxin521123

Chapter 18 Use the work queue manager ( One )

Work queue manager is a function of , Enables you to improve performance by programmatically allocating work to multiple concurrent processes . Before introducing the work queue manager , May have been used JOB Command starts multiple processes in the application and uses custom code to manage these processes ( And any resulting failure ). Work queue managers provide an efficient and direct API, Enable to uninstall process management .

The code uses the work queue manager internally in multiple places . You can use it for your own needs , As described in the following section .

background

The latest innovations in computer hardware development tend to be high-performance 、 Multiprocessor or multicore architecture . meanwhile , The speed of memory and network devices has only slowly increased . Work queue managers have been developed to respond to these trends and according to the following principles :

  • Hardware resources , Include CPU and I/O、 Memory and network devices , It's all fixed .
  • Hardware resources must be used as efficiently as possible , To maximize the speed of their business tasks .
  • For maximum efficiency , The work queue manager must improve during execution ObjectScript Code may appear CPU The problem of underutilization .
  • solve CPU Underutilized methods include queuing and prioritization .

Although the whole data platform aims to make the most of the hardware resources in the system , However, the work queue manager function of the platform is specifically designed to take advantage of the additional... Available in modern hardware configurations CPU resources . Work queue managers have two key uses :

  • Provide a framework , Enables you to break down large programming tasks into smaller blocks , To execute in multiple concurrent processes . By using multiple at once CPU, Work queue managers significantly reduce the time required to process large workloads .
  • Through the management system, the task is active at one time JOB To control the total on the system CPU load .

ObjectScript CPU utilization

Usually ,ObjectScript The code runs in a single process and uses only one processor core . For transactional database applications that handle relatively few instructions and global references between transactions , This method works well . in fact , A key feature of the data platform is the large-scale scalability of the transaction workload . The platform optimizes the processing of a large number of relatively small work units requested by a large number of users at one time .

Some newer types of workloads ( for example , Analyze the workload ) And The workloads initially built for optimization are different . for example , Newer workloads may involve processing a that requires millions of rows to perform various operations SQL Inquire about . To speed up the processing of such workloads , Developed a work queue manager , It breaks down the overall workload into smaller blocks , Process these blocks in parallel , And relay the results of each block back to the parent process , Then the parent process can relay the results back to you . let me put it another way , Work queue manager is a kind of similar to Queues The mechanism of , It enables developers who build their applications in to break down large tasks into smaller tasks for parallel processing .

Functions of work queue manager

Work queue managers include several key features :

  • Low latency and overhead
  • Extensibility
  • Cooperation with operating system
  • flexibility
  • High level of control and reporting

Low latency and overhead

Work queue managers are designed for low latency and low overhead . for example , Consider a procedural task , System needs 10 Minutes to process in order . If the system has 10 Kernel , Then it will be more efficient to split the tasks and process one tenth of the work in parallel on each kernel . actually , If you split tasks 、 Queue up for each task 、 The overhead involved in starting work jobs and collecting notifications of the completion of each task does not require any additional time , Then you can get the result 10 How fast . Work queue managers are designed to overhead tasks resulting in low latency .

Extensibility

To maximize performance , The work queue manager is able to use all... On the system CPU Resources to handle a single task . actually , The work queue manager limits the number of cores that a given type of task can use , To ensure that all workloads on the system can be effectively handled .

Cooperation with operating system

Use traditional for large transactional database applications ObjectScript Code , The operating system may spend a lot of resources switching between programming tasks , This is sometimes called context switching . Because the work queue manager adopts the queuing mechanism on each kernel , Therefore, the need for context switching is greatly reduced . Only when the number of active jobs managed by the work queue manager exceeds the number of available cores , Only the operating system needs context switching . such , Queuing usually improves performance .

flexibility

A unit of work is a class method or subroutine that takes a set of parameters and meets the requirements described in the unit of work . Any logic that can be represented in these constraints can be handled by the work queue manager , So as to provide great flexibility .

High level of control and reporting

The work queue manager provides access to CPU Advanced control of resource usage . for example , You can create job Categories and define the staff assigned to these categories job The number of . Besides , The work queue manager provides workload metrics , So that the load on the system can be monitored in real time .

About work units

The work queue manager processes units of work ( Also known as work items ) To make a difference , These work units meet the following requirements ObjectScript Class method or subroutine :

  • Class methods or subroutines can be handled independently . for example , A unit of work cannot depend on the output of different units of work . Because work units can be processed in any order , Therefore, independence is needed . however , if necessary , You can use callbacks to perform work in sequence .
  • The size of a class method or subroutine is about thousands of lines ObjectScript Code . This requirement ensures that the overhead of the framework is not an important factor .

Besides , It's best to use a lot ( for example ,100 individual ) Smaller units of work , Instead of using a few very large units of work ( for example ,4 individual ). Allocating work in this way allows the system to do more CPU Expand when the kernel is available .

  • The code returns a %Status Value to indicate success or failure , In order to WaitForComplete() Method can return a %Status Value to indicate overall success or failure . perhaps , Work units can throw exceptions , The exception is caught 、 Convert to %Status Value and return in the main process .
  • If the code changes the same global to a different unit of work , Then a locking strategy must be adopted to ensure a work JOB In another work The global cannot be changed while it is being read .
  • This code does not include news, kills, unlocks, Because these will interfere with the framework .
  • If the code contains process private global variables for storing data , Then these process private global variables will not be accessed from the main process or any other block . This requirement is necessary , Because multiple jobs process each block .
  • Any logic called as part of a class method or subroutine is cleaned up correctly , So that there are no variables in the partition 、 lock 、 Process specific global variables or other artifacts . This requirement is important , Because then the same process will be used to deal with completely independent work items .

To use the work queue manager , Some procedural work must be divided into work units .

About Worker Jobs

Worker jobs It is the process of completing the unit of work for the work queue manager . By using %SYSTEM.Process class , It can be viewed like other processes 、 Manage and monitor jobs . If you need to know whether a given process is a work job , You can call $system.WorkMgr.IsWorkerJob()

The work queue manager uses the controller process to guide the work job, The controller process is a dedicated process that performs the following operations :

  • start-up worker jobs
  • management worker jobs The number of
  • Detect and report suspended worker jobs
  • Record workload metrics
  • Detect inactive work queues
  • Delete work queue

worker jobs Can be in any of the following states :

  • Waiting to be attached to the work queue
  • Waiting for work unit . Before release ,worker jobs Can only be in this state for a very short time .
  • Activate . Only when it performs the forwarding process while executing a unit of work ,worker jobs Is active .
  • Blocked by a lock or event while processing a unit of work . Blocked worker jobs Not active . If worker jobs Blocked and there is extra job, Work queue managers can activate inactive woker Or start a new woker. When worker jobs When it is no longer blocked , Activities worker jobs The number of may exceed the activities specified for the work queue worker jobs Maximum number of . If this happens , The controller process will eliminate the next unit of work worker jobs. therefore , When worker jobs The number of activities for exceeds the specified for the given work queue worker jobs The maximum number of , There may be a short period of time .
  • Disabled and can be quickly activated

That is not used worker jobs It can still be used by other work queue manager queues for a short time . The timeout period may change , And deliberately unrecorded . After the timeout period expires ,worker Removed .

If worker jobs Actively processing work items of deleted or cleared queues , The system will wait for a very short time , Then send out EXTERNAL INTERRUPT error . If worker jobs Continue processing after the error , The system will wait DeleteTimeout The number of seconds specified in the property , Then forcibly terminate worker And start a new worker To deal with work units .

Super server starts worker jobs, This means that they run under the name of the operating system user used by the super server process . This user name may be different from the currently logged in operating system user .

原网站

版权声明
本文为[yaoxin521123]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/186/202207050821589698.html