INFORMIX
DataBlade Developers Kit User's Guide
Chapter 4: C Programming Guidelines
Home Contents Index Master Index New Book

Informix Dynamic Server Architecture

Informix Dynamic Server uses virtual processors. A virtual processor is a process that Informix Dynamic Server uses to execute queries and perform other tasks, such as disk I/O and network management. Because virtual processors control interaction with the operating system, any code you write must not bypass virtual processors. For example, do not use standard C functions to make operating system calls because they interfere with database server efficiency. Do not use standard C functions to allocate memory; use proprietary Informix routines instead.

This section describes how Informix Dynamic Server architecture affects DataBlade programming. Obtain more information from these sources:

What Are Virtual Processors?

Virtual processors are the processes Informix Dynamic Server uses to manage its tasks. Informix Dynamic Server assigns different tasks to specific classes of virtual processors. Informix Dynamic Server uses virtual processors to achieve concurrent processing by queuing virtual processors that have tasks to perform. When a virtual processor finishes a task or goes into a wait state, the next virtual processor in the queue takes over the CPU. Each virtual processor can concurrently process multiple tasks by switching between them. The tasks virtual processors perform are called threads and are controlled by the Informix database server; virtual processor threads are distinct from operating system threads. Virtual processors use shared memory to store information about threads. Threads can migrate between different virtual processors as needed.

Figure 4-1 illustrates Informix Dynamic Server architecture with various virtual processors (VPs) that process client threads.

Figure 4-1
Informix Dynamic Server Architecture

UNIX
On UNIX, virtual processors run as separate processes. Monitor virtual processors with the onstat command.

Windows NT
On Windows NT, virtual processors run as operating system threads.

The following sections discuss how:

Virtual Processor Classes

Virtual processors are divided into classes according to the types of tasks or threads they handle. You can run multiple virtual processor instances in any class of virtual processor.

Virtual processor classes include:

When you define a user-defined routine, you can assign it to a CPU VP or a user-defined VP. For more information, see "When to Use a User-Defined Virtual Processor".

See the INFORMIX-Universal Server Administrator's Guide for information on all types of virtual processors.

Thread Management

A virtual processor runs one thread at a time. A virtual processor services multiple threads concurrently by switching between them. The virtual processor runs a thread until the thread yields; then switches to the next thread that is ready to run. The virtual processor continues this process and eventually returns to the original thread when that thread is ready to continue. Because a virtual processor switches between threads, it can keep the CPU processing continually. Your user-defined routines must explicitly yield by calling mi_yield() before entering resource-intensive sections of code. Use DataBlade API calls whenever possible because they implicitly yield at appropriate points.

If you have more than one CPU VP, a thread that has yielded resumes in the first available CPU VP, which is not necessarily the one in which it began.

Memory Management

Virtual processors save information about threads in shared memory. Shared memory is an operating system feature that allows Informix Dynamic Server threads and processes to share data. Shared memory enables the database server to reduce overall memory use because the virtual processors do not need to maintain private copies of the data.

Because a virtual processor saves information about the state of the thread in shared memory, the thread can be accessed by any virtual processor.

DataBlade API memory allocation functions, such as mi_alloc(), allocate memory in the shared memory pool. Standard C memory allocation functions, such as malloc(), allocate memory on the data segment or heap of the virtual processor, which cannot be accessed after the thread migrates. Memory allocated by malloc() might overwrite memory addresses that will be needed by the database server.

Warning: Do not use standard C memory allocation functions with Informix Dynamic Server; they can cause incorrect results. Always use DataBlade API memory allocation functions to manage memory in your user-defined routines.

User-Defined Virtual Processors

Although invoking a routine in the CPU VP is faster, if your routine is not well-behaved within the Informix database server architecture, assign it to a user-defined virtual processor.

The following sections discuss:

When to Use a User-Defined Virtual Processor

A user-defined routine is considered poorly behaved, within Informix database server architecture if it has one or more of these characteristics:

If a CPU VP executes a poorly behaved user-defined routine, the database server is likely to behave erratically or fail. User-defined virtual processors eliminate the need to yield the processor regularly and allow direct file system access.

Important: User-defined virtual processors allow I/O blocking system calls, but not other types of unsafe system calls. See "Avoid Unsafe System and Library Calls" for more information on unsafe system calls.
Assign a user-defined routine to a nonyielding user-defined virtual processor class if the routine is not thread-safe. User-defined routines that use a nonyielding virtual processor class run serially, and each routine runs to completion before the next one begins. A routine is not thread-safe if it yields or accesses the database while keeping its state in global or static variables, or if it communicates with external resources but prevents the virtual processor from servicing another thread while waiting for a response.

If your routine uses global or static variables, assign it to a nonyielding user-defined virtual processor class that has a single member virtual processor.

Creating User-Defined Virtual Processors

To create user-defined virtual processor classes, set variables in the ONCONFIG configuration file. The ONCONFIG configuration file contains configuration information for Informix Dynamic Server. The ONCONFIG file is located in the $INFORMIXDIR/etc/$ONCONFIG directory.

To create a user-defined virtual processor

    1. Open the ONCONFIG file in a text editor.

    2. Locate the VPCLASS variable.

    3. Specify the parameters for the VPCLASS variable.

    4. Save and close the ONCONFIG file.

The following example creates the XYZclass virtual processor class:

The class name must be 18 or fewer alphanumeric characters and must be unique. The class name is case insensitive. The first three characters of the class name should be the new object prefix for your DataBlade module. The class name must be the same as the class name you entered in BladeSmith when you defined user-defined routines (see "User-Defined Virtual Processor Class Name").

You can see the new virtual processor in the onstat -g glo command output as a new process.

Important: When you create a virtual processor class, delete the SINGLE_CPU_VP variable or set it to 0 in the ONCONFIG file.
The following sections discuss setting the number of virtual processors for a class and creating nonyielding virtual processors. When you specify multiple parameters for the VPCLASS variable in the ONCONFIG file, separate each parameter with commas; do not use spaces. See the INFORMIX-Universal Server Administrator's Guide for information on other VPCLASS parameters.

Specifying the Number of Virtual Processors in a Class
To specify the number of instances of virtual processors in a class, set the num=num_VPs parameter, where num_VPs is the number of virtual processor instances. The default number of user-defined virtual processor instances is 1.

The following example creates three virtual processors in the XYZclass class:

See the INFORMIX-Universal Server Administrator's Guide for information on determining how many virtual processors in a specific class you need and how to alter the number of virtual processors in an existing class.

Specifying a Nonyielding Virtual Processor Class
To specify that the virtual processor class is nonyielding, set the noyield parameter. The noyield parameter is appropriate for routines that contain global or static variables or make blocking I/O calls. For routines that use global or static variables, assign one virtual processor to the noyield class.

The following example creates one nonyielding virtual processor in the ABCclass class:

Assigning a User-Defined Routine to a Virtual Processor Class
In BladeSmith, you assign a routine to a virtual processor class using the New Routine wizard. Using this wizard, you mark the routine as poorly behaved and specify the class name of the virtual processor in which the routine runs. See "User-Defined Virtual Processor Class Name" for more information.

Important: You must create the user-defined virtual processor before you can call a routine that runs in the user-defined virtual processor.




DataBlade Developers Kit User's Guide, version 3.6
Copyright © 1998, Informix Software, Inc. All rights reserved.