Home | Previous Page | Next Page   Improving UDR Performance > Memory Considerations >

Stack-Size Considerations (Ext)

The database server allocates local storage in external routines from shared memory. This local storage is called the thread stack. The stack has a fixed length. Therefore, an external routine must not consume excessive stack space, either through large local-variable declarations or through excessively long call chains or recursion.

Warning:
An external routine that overruns the shared-memory region allocated for its stack overwrites adjacent shared memory, with unpredictable and probably undesirable results.

In addition, any nonstack storage that a thread allocates must be in shared memory. Otherwise, the memory is not visible when the thread moves from one VP to another.

The routine manager of the database server guarantees that a large stack region is available to a thread before it calls a user-defined function, so stack exhaustion is generally not a problem.

C Language Support

For C UDRs, you can dynamically allocate stack space. In addition, the DataBlade API provides memory-management routines that allocate space from shared memory rather than from process-private memory. If you use the DataBlade API, memory visibility is not a problem.

End of C Language Support

By default, the routine manager allocates a stack size for a UDR with the size that the STACKSIZE configuration parameter specifies. If STACKSIZE is not set, the routine manager uses a default stack size of 32 kilobytes. To determine how much stack space a UDR requires, monitor the UDR from the system prompt with the following onstat utility:

onstat -g sts

Use the onstat -g sts option to obtain information on stack-size use for each thread. The output includes the following fields:

You can use the output of the threads that belong to user sessions to determine if you need to alter the maximum stack size configured for a user session. To alter the maximum stack size for all user sessions, change the value of the STACKSIZE configuration parameter. To alter the maximum stack size for a single user session, change the value of the INFORMIXSTACKSIZE environment variable. For more information, see the configuration parameter STAGEBLOB in the IBM Informix: Administrator's Reference and the environment variable INFORMIXSTACKSIZE in the IBM Informix: Guide to SQL Reference.

For more information on the onstat utility and the -g sts option, see the IBM Informix: Administrator's Reference.

If the stack size is not sufficient for your UDR, you can specify its stack size with the STACK routine modifier in the WITH clause of the CREATE FUNCTION or CREATE PROCEDURE statement. When you specify a stack size for a UDR, the database server allocates the specified amount of memory for every routine invocation of the routine. If a routine does not need a larger stack, do not specify a stack size.

Home | [ Top of Page | Previous Page | Next Page | Contents | Index ]