Quote:
Originally Posted by db2girl
Yes, I'm more interested in understanding how much memory is allocated dynamically and where it's allocated from - for fenced and unfenced stored procedures.
|
What exactly do you mean here? Memory allocated by DB2 or memory allocated by the stored procedure?
DB2 needs some memory to pass input parameters to the stored procedure and to provide memory for output parameters. Additionally, memory for error codes (e.g. SQLSTATE and SQLCODE) will be needed - but that is pretty small. And then some memory is needed for result sets, e.g. to hold cursors/descriptors etc. opened by the stored procedure and returned to the caller or client.
If you are interested in the memory allocated dynamically be the stored procedure, it actually depends on the programming language in which the SP is written. If it is C/C++, then you don't have any control over the memory if the SP uses language library calls like new/delete or malloc/free. In Java, all memory is used from from the java heap, unless you have something like JNI in the picture, which goes directly to the operating system's memory manager. Only if you have an SP written with LANGUAGE SQL, we are talking about DB2 heaps/memory pools.
Quote:
|
Do most customers create stored procedures as fenced or unfenced in production? I understand unfenced could crash the instance, but it seems like there are less problems (at least memory related problems) and less overhead when they're unfenced.
|
I don't know for sure what most customers do. But the overhead for fenced stored procedures is higher because you have IPC (inter process communication) involved. So you may have something like message queues or (more likely) shared memory and semaphores involved to exchange the input/output parameters between the DB2 agent and the db2 FMP. This is bound to be slower compared to direct memory access via a pointer. The overhead incurred there depends on the complexity of the stored procedure or user-defined function. At one point, we had a SP/UDF, which run very quickly. The overhead incurred by fenced execution was something like 10% of the total execution time. With an SP/UDF taking more time due to more complex calculations, more I/O, web access or whatever else, the additional communication overhead may become negligible.
p.s: One argument for using fenced vs. not-fenced SPs/UDFs is also that fenced SPs are executed in a process, which runs with different authorizations/operating system privileges. You can protect the DB2 instance/configuration that way. The stability argument became weaker in the last decade or so. For example, with DB2 LUW V7 (very long time ago), I could sometimes bring down the DB2 instance using a fenced UDF, which crashed in a very specific way at a very specific point during its execution. I was never able to reproduce this since then with DB2 V8 or later. Similarly, I couldn't easily crash the DB2 V8+ instance with a trusted (not-fenced) UDF. Thus, DB2 is doing a very good job from preventing you to crash the database system. So if you know what your SP/UDF is doing (no file access, no security holes, ...) and have applied reasonable testing you may want to go with trusted execution.