How to speed up the call speed of Oracle local OCI

xiaoxiao2021-03-06  79

This article is taken from developers.sun.com very brilliant, I tried it myself, and performance has improved.

Developers.sun.com

Technical Articles & TIPS

Cache OCI Calls to Improve Performance of 32-Bit OR 64-Bit Oracle Clients

By Nagendra Nagarajayya, October 2003

CONTENTS:

Introduction Identifying the Problem The Workaround: Cache oraus.msb in Memory Building cache_oraus.so How to Use cache_oraus.so How the Caching Works 6.1 Interposition of the open () Function Call 6.2 Interposition of the fcntl () Function Call 6.3 Interposition of the lseek (), read (), and close () Function Calls Performance Improvement 7.1 Without LD_PRELOAD and cache_oraus.so 7.2 With LD_PRELOAD and cache_oraus.so Caveat Conclusion Acknowledgments References A. Appendix:.. Test Programs and Wrappers A1 README A2 cache_oraus.c A3 Test.sh A5. Test1.sh A6. Test_v.c A7. Test_v.sh A8. C.SH A9. C64.SH A10. Cache_open_calls.c 1. Introduction if you work with Oracle Clients That Make Use of oci (Oracle Call Interface), You May Have Noticed That The OCI Driver In 8.1.7.x Makes Thousands of Calls to Translate Messages from the oraus.msb file. This can degrade application performance by 5 percent or more (quite severely in some cases). This problem has been documented by Oracle under bug ID 2142623. The problem can be overcome by caching the oraus.msb file in memory, and translating the file access and system calls to user calls and memory operations. The caching solution is dynamic, and code changes are not needed. The solution can improve the performance of the Oracle client application. Recently, this solution resulted in bringing down The application runtime from 15 minutes to a few seconds at a major Customer - About 100X Times Performance Improvement. The Performance Benefits Can Be Seen In Applications Like Sqlplus and Oracle Clients (C and C

) Making use of the OCI driver. Java technology-based applications using JDBC (native driver) should also see similar benefits. 2. Identifying the Problem An Oracle client application can be trussed on the Solaris Operating System (OS) to see the calls being made to this file - "truss" is a system utility available on the Solaris platform, and it can be used to trace system calls made by an application A running Oracle client application can be trussed as follows: truss -p [oracle. Client PID] The Truss Command Will Show All The System Calls Being Made By The Application. The ones of intertreat is Open (), fcntl (), lseek (), read (), and close () Calls. These Calls Are Made By The OCI Driver Repeatedly To Translate Messages. Here Is A Truss Snippet Showing The Problem Calls: Open ("/ Oracle / App / Oracle / Product / 8.1.7 / Rdbms / Mesg / ORAUS.MSB", O_RDONLY) = 9

FCNTL (9, f_setfd, 0x00000001) = 0

Lseek (9, 0, seek_set) = 0

READ (9, "1513" 011303 / T / T / 0/0/0/0 ".., 256) = 256

Lseek (9, 512, seek_set) = 512

READ (9, "1C88 Y R ~ m / 0/0/0/0/0/0" .., 512) = 512

Lseek (9, 1024, seek_set) = 1024

READ (9, "/ 018/0 $ / 0 7/0 @ / 0 j / 0 v" .., 512) = 512

Lseek (9, 39936, seek_set) = 39936

READ (9, "/ 0 / t0519 / 0/0/0> 051a / 0/0" .., 512) = 512

CLOSE (9) = 0

These system calls can be expensive The number of times these system calls are executed depends on the client application and the duration of the application run 3. The Workaround:.. Cache oraus.msb in Memory The workaround is to cache the contents of the oraus .msb in memory and not make these system calls. This can be done dynamically by using the LD_PRELOAD technique available on the Solaris OE. (For further information, see the References section.) LD_PRELOAD is an environment variable on Solaris that allows shared libraries to BEGINS Execution. To make use of this technique . Building cache_oraus.so The shared library can be built with the Forte C compiler (now part of the Sun ONE Compiler Collection) using the following switches: 32-bit: cc -G -o cache_oraus.so -fast cache_oraus.c -l DL64-bit: cc -g -o cache_oraus.so -fast -xarch = v9a cache_oraus.c -l dl

5. How to use cache_oraus.so the folly environment variables needed to be set to use the caching mechanism: export ld_preeload =. / Cache_oraus.so

Export oraus_msb_file = / ora / App / Oracle / Product / 8.1.7 / Rdbms / MESG / ORAUS.MSB

THELLS. 6. How The Caching Works The Caching Works by Interposing The Cairs (), read (), and close () calls. The first time the application executes one of these calls, the control is first transferred to the interposed function code. 6.1 interposition of the open () function Call Whenever a file is opened, the control is transferred to the interposed open () from cache_oraus.so . The interposed open () checks to see if the file being opened is the oraus.msb (see STEP 3 in the following code example). If so, the file is opened, and memory mapped (STEP 5.1). The descriptor returned by Open () IS Also Cached. for All Other Opens, The Control IS Transferred To The Original Libc.so (STEP 7). INT OPEN (const char * path) {static int (* fptr) () = 0;

STATIC char * msb_path;

STEP 1

IF (fptr == 0) {

FPTR = (int (*)) DLSYM (RTLD_NEXT, "Open");

IF (fptr == null) {

FPrintf (stderr, "dlopen:% s / n", dLerror ());

Return 0;

}

STEP 1.1

MSB_PATH = (char *) GetENV ("ORAUS_MSB_FILE");

}

STEP 2

IF (! MSB_PATH) {

MSB_Path = "/oracle/app/oracle/product/8.1.7/rdbms/mesesg/oraus.msb";

}

STEP 3

IF (strcmp (pat, msb_path) == 0) {

STEP 4

IF (k_bm_fd == -1) {

K_BM_FD = ((* fptr) (path, OFLAG, MODE));

IF (k_bm_fd <= 0) {

PERROR (PATH);

Exit (1);

}

STEP 5

FSTAT (k_bm_fd, & k_bm_stat_buf);

STEP 5.1

K_BM_BUF = (char *) MMAP ((CADDR_T) 0,

K_BM_STAT_BUF.ST_SIZE, (Prot_Read),

Map_shared, k_bm_fd, 0);

Assert (k_bm_buf! = map_failed);

Return k_bm_fd;

} else {

STEP 6

Return k_bm_fd;

}

}

STEP 7

Return ((* fptr) (Path, OFLAG, MODE));

}

STEPSDescription1Use dlysym () to get a pointer to the original libc.so open () call, so that we can chain to it.1.1We use an environment variable, oraus_msb_file, to find the location of the oraus.msb file.2If this variable is not set, we use a default path.3We make sure the open call is related to the oraus_msb_file. For all other open calls, we chain to the original open () call.4We make sure this is the first time we are going through this code path as we want to map the file into memory only once We open the file and cache the returned descriptor in k_bm_fd.5We get some information about the file itself, such as size.5.1The most important step:. we map the file into memory.6We have already opened the file, and we return the cache descriptor.7For all other opens, the interpose gives control back to the original libc.so open () call Table 1:. open () Call 6.2 interposition of the fcntl () Function Call A Fcntl () Call is Made to Change The File Control Parameters. The First Time FCNTL () is executed to change oraus.msb control parameters, the control is first transferred to the fcntl () in libc.so. The return value is cached, as well as returned back to the Oracle client (STEP 2). The next time fcntl ( ) is executed, if the file descriptor matches the oraus.msb file descriptor, the cached return value is returned (STEP 3). The control is not transferred to fcntl () in libc.so. int fcntl (int fildes, int cmd, INT arg) {static int R;

Static int (* fptr) () = 0;

CHAR * PATH;

STEP 1

IF (fptr == 0) {

FPTR = (int (*)) DLSYM (RTLD_NEXT, "FCNTL");

IF (fptr == null) {

FPrintf (stderr, "dlopen:% s / n", dLerror ());

Return 0;

}

}

STEP 2

IF (k_fcntl_bm_fd == -1) {

IF (Fills == K_BM_FD) {RET = ((* FPTR) (Fildes, CMD, Arg);

K_FCNTL_BM_FD = K_BM_FD;

Return Ret ;;

}

STEP 3

} else if (k_fcntl_bm_fd == fildes) {

Return Ret;

}

STEP 4

Return (* fptr) (Fildes, CMD, Arg);

}

STEPSDescription1Use dlysym () to get a pointer to the original libc.so fcntl () call, so that we can chain to it.2We make sure this is the first time we are going through this code path as we want to execute fcntl () only once. We also make a copy of the open descriptor in k_fcntl_bm_fd.3If the fildes is equal to k_fcntl_bm_fd, then we just return the cached return value.4For all other opens, the interpose gives control back to the original libc.so fcntl ( Call. Table 2: Fcntl () Call Back to Top 6.3 Interposition of the Lseek (), read (), and close () Function calls for the lseek () call, if the file descriptor matches the cached oraus.msb file descriptor , the file offset is stored instead of calling the lseek () in libc.so (STEP L2). On a read () call, if the file descriptor matches the cached oraus.msb file descriptor, the file offset stored from the lseek ( IS used to index INTO The MEMORY MAPPED ORAUS.MSB DATA. A Memcpy () Is Tan Executed (Step R2). SO An I / O Call is now Transformed to A SIMPLE MEMCPY () Call. aclose () on the cached file descriptor is ignored so what the cached file descriptor can be reused. Off_t lseek (int Fildes, OFF_T Offset, INT im "{

static off_t (* fptr) () = 0;

Step l1 if (fptr == 0) {

FPTR = (int (*)) DLSYM (RTLD_NEXT, "Lseek");

IF (fptr == null) {

FPrintf (stderr, "dlopen:% s / n", dLerror ());

Return 0;

}

}

Step L2 IF (Fildes == K_BM_FD) {

K_BM_OFFSET = OFFSET;

Return offset;

}

Step l3 return ((* fptr) (Fildes, Offset, because);

STEPSDescriptionL1Use dlysym () to get a pointer to the original libc.so lseek () call, so that we can chain to it. L2If the fildes is equal to k_bm_fd, then we keep track of the k_bm_offset so that we access this memory location. L3for All Other Opens, The Interpose Gives Control Back to The Original Libc.so Lseek () Call. Table 3: Lseek () Call Ssize_t Read (int Fildes, Void * BUF, SIZE_T NBYTE) {

Static SSIZE_T (* fptr) () = 0;

Step r1 if (fptr == 0) {

FPTR = (SSIZE_T (*)) DLSYM (RTLD_Next, "Read");

IF (fptr == null) {

FPrintf (stderr, "dlopen:% s / n", dLerror ());

Return (0);

}

}

Step r2 if (FildeS == k_bm_fd) {

Memcpy (buf, K_BM_BUF K_BM_OFFSET, NBYTE);

Return nbyte;

}

Step R3 Return ((* FPTR) (Fildes, BUF, NBYTE);

}

STEPSDescriptionR1Use dlysym () to get a pointer to the original libc.so read () call, so that we can chain to it.R2If the fildes is equal to k_bm_fd, then we use the stored k_bm_offset to access the right memory location, and do A Memcpy (). R3for All Other Other OPENS, The Interpose Gives Control Back to the Original Libc.so Read () Call. Table 4: Read () Call Int Close (int Fildes) {

Static int (* fptr) () = 0;

Step c1 if (fptr == 0) {

FPTR = (int (*)) DLSYM (RTLD_NEXT, "Close");

IF (fptr == null) {

FPrintf (stderr, "dlopen:% s / n", dLerror ());

Return 0;

}

}

Step C2 IF (Filde == K_BM_FD) {

Return 0;

}

Step c3 return ((* fptr) (FILDES));

}

STEPSDescriptionC1Use dlysym () to get a pointer to the original libc.so close () call, so that we can chain to it.C2If the fildes is equal to k_bm_fd, then we justreturn 0 to signal a successful close, but without closing the file .C3For all other opens, the interpose gives control back to the originallibc.so close () call Table 5:. close () Call Back to Top 7. Performance Improvement The performance improvement comes from not executing the system calls The multiple instances of. Open (), fcntl (), lseek (), read (), and close () to read the oraus.msb Messages Are Transformed to user-level calls. Also, The I / O Operation Becomes A Simple Memory-to-Memory transfer. To measure the performance gains, a test program mimicking an Oracle client's behavior was developed. The test program performs open (), lseek (), read (), and close () calls on the oraus.msb file 50,000 times. The Test Program Showed a Gain of About 1000%. However, In A Real Oracle Client Application, this Might Translate To About a 2 PE rcent-to-15 percent gain in performance 7.1 Without LD_PRELOAD and cache_oraus.soTypeTime in SecondsReal5.633User0.010Sys0.014 Table 6:. ptime test.sh Back to Top 7.2 With LD_PRELOAD and cache_oraus.so

TypeTime in SecondsReal0.462User0.010Sys0.013 Table 7: ptime test.sh 8. Caveat The preceding code is not multithreaded For Oracle clients that are multithreaded, the write access to the cache variables needs to be mutex protected or synchronized 9... Conclusion Caching the file oraus.msb in memory improves the performance of Oracle clients. Even though the performance gain observed in the test program is about 1000 percent, the gain when running a really big Oracle client application might not be more than 2 to 15 percent , due to other I / O contentions. This gain can be achieved without any code changes to the client application. 10. Acknowledgments I would like to thank Teresa Riege (Sun) and Thomas Yen (Kenan / BP billing platform, CSG Systems) for their contributions and help in testing this utility during the 2002 Kenan / BP study (see related article listed in References). I would also like to thank my colleagues at MDE (IPE) for supporting me during this project. I would like also To Thank Ben Humphreys, Technical Support Specialist, Sun, Who Made The 64-bit Modifications to the Code. 11. References

Nagendra Nagarajayya, SR Venkatramanan, "Fast Sockets, An Interprocess Communication Library to Boost Application Performance" Sun Product Documentation site Oracle MetaLink (for news, problems, and bugs) CSG Kenan / BP Exceeds Billing Needs of Largest Telecom Service Providers in Scalability Test Appendix : Test Programs and Wrappers The Sample Code is being made available by Sun merely as a convenience to you The Sample Code below is provided Sun makes no warranties of any kind whatsoever with respect to the Sample Code ALL EXPRESS OR. "AS IS.". IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY WARRANTY OF NON-INFRINGEMENT OR IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, ARE HEREBY dISCLAIMED AND EXCLUDED TO THE EXTENT ALLOWED BY APPLICABLE LAW. IN NO EVENT WILL SUN BE LIABLE FOR ANY LOST REVENUE , Profit or Data, Or For Direct, Special, Indirect, Consequential, Incidental, or Pubitial, Incision, OR PUNTIVE, IABILITY TO USE The Sample Code, Even if Sun Has Been Advised of the Possibility Of Such Damages. A1. Readme ** OCT 02, 03

* Nagendra Nagarajayya

* MDE / IPE (CSI)

* Sun Microsystems, Inc

*

Set ld_preload within a wrapper to cache_oraus.so, and specify

"ORAUS_MSB_FILE". "ORAUS_MSB_FILE".

If the env is not special, the folload path is buy,

/Oracle/app/oracle/product/8.1.7/rdbms/meses.mus.msb.

WARNING:

The Solution Presented Does Not Support Multi-Threaded Clients, But Should Be

Very Easy to Do So. BTW, IT Could Work As It Is With Mt Threaded Clients, But

Has Not Been Tested.

EXAMPLE:

Export LD_PRELOAD =. / cache_oraus.so

EXPORT ORAUS_MSB_FILE = / ORA / APP / ORACLE / Product / 8.1.7 / Rdbms / Mesg / ORAUS.MSBNOTE:

Cache_open_calls.c is similar to cache_oraus.c but caches Only the open calls.

IT Does Not Memory Map The Oraus.msb file.

CompiLATION INSTRUCTIONS:

-------------------------

Use the wrapper c.sh to compile cache_oraus.c. C.SH Also compiles cache_open_calls.c,

And the test programs. Use c64.sh to compile cache_oraus.c for 64 bit support.

To test the library:

--------------------

Use, ptime test.sh, and ptime test1.sh.

To verify if the library is going the contents prot

Use test_v.sh, and test_v.c

A2. Cache_oraus.c / *

Date: April 18, 2002

Author: Nagendra Nagarajayya

MDE / IPE / CSI

Sun Microsystems, Inc.

Date: October 02, 2003

Ben Humphreys

Technical Support Specialist

Sun Microsystems, Inc.

Descr: Made Changes to Source for 64 Bit Support

Description: this caches oraus.msb file in memory and transforms I / O Calls

To The File to a Read Access.

* /

/ *

The Sample Code Is Being Made Available By Sun Merely As a Convenience To You.

The Sample Code Below Is Provided "As IS." Sun Makes No Warranties of Any Kind

Whatsoever with respect to the sample code. All Express or Implied Conditions,

Representations and Warranties, include any Warranty of Non-Infringement OR

Implied Warranty of Merchantability Or Fitness for a Particular Purpose, Area

Eveby disclaimed and excluded to the extent allowed by Applicable Law. In no

Event Will Sun Be Liable for Any Lost Revenue, Profit or Data, or For Direct,

Special, Indirect, Consequential, Incidental, or Punitive Damages However Caused

And regardless of the theory of liability arising out of the use of or in ublica

To Use the Sample Code, Even IF Sun Has Been Advised of The Possibility of Such Damages. * /

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

Static int k_fcntl_bm_fd = -1;

Static int k_bm_fd = -1;

Static int k_bm_offset = 0;

Static char * k_bm_buf;

STATIC STRUCT STAT K_BM_STAT_BUF;

INT FCNTL (int Fildes, int CMD, INTPTR_T ARG) {

Static int R;

Static SSIZE_T (* fptr) () = 0;

CHAR * PATH;

IF (fptr == 0) {

FPTR = (SSIZE_T (*)) DLSYM (RTLD_NXT, "FCNTL");

IF (fptr == null) {

FPrintf (stderr, "dlopen:% s / n", dLerror ());

Return 0;

}

}

IF (k_fcntl_bm_fd == -1) {

IF (Filde == K_BM_FD) {

Ret = ((* fptr) (Fildes, Cmd, Arg);

K_FCNTL_BM_FD = K_BM_FD;

Return Ret ;;

}

} else if (k_fcntl_bm_fd == fildes) {

Return Ret;

}

Return (* fptr) (Fildes, CMD, Arg);

}

OFF_T LSEEK (int Fildes, OFF_T Offset, INT imce) {

static off_t (* fptr) () = 0;

IF (fptr == 0) {

FPTR = (OFF_T (*)) DLSYM (RTLD_Next, "Lseek");

IF (fptr == null) {

FPrintf (stderr, "dlopen:% s / n", dLerror ());

Return 0;

}

}

IF (Filde == K_BM_FD) {

K_BM_OFFSET = OFFSET;

Return offset;

}

/ * fprintf (stderr, "offset =% D k_bm_offset =% D / N", OFFSET, K_BM_OFFSET;

* /

Return ((* fptr) (Fildes, Offset, because);

}

SSIZE_T Read (int Fildes, Void * BUF, SIZE_T NBYTE) {

Static SSIZE_T (* fptr) () = 0;

IF (fptr == 0) {

FPTR = (SSIZE_T (*) ()) DLSYM (RTLD_Next, "Read"); if (fptr == null) {

FPrintf (stderr, "dlopen:% s / n", dLerror ());

Return (0);

}

}

/ * fprintf (stderr, "fills =% D k_bm_fd =% d / n", Fildes, K_BM_FD);

* /

IF (Filde == K_BM_FD) {

Memcpy (buf, K_BM_BUF K_BM_OFFSET, NBYTE);

Return nbyte;

}

Return ((* FPTR) (Fildes, BUF, NBYTE);

}

INT OPEN (const char * path, int OFLAG, MODE_T MODE) {

STATIC char * msb_path;

Static int (* fptr) () = 0;

IF (fptr == 0) {

FPTR = (int (*)) DLSYM (RTLD_NEXT, "Open");

IF (fptr == null) {

FPrintf (stderr, "dlopen:% s / n", dLerror ());

Return 0;

}

MSB_PATH = (char *) GetENV ("ORAUS_MSB_FILE");

}

IF (! MSB_PATH) {

MSB_Path = "/oracle/app/oracle/product/8.1.7/rdbms/mesesg/oraus.msb";

}

IF (strcmp (pat, msb_path) == 0) {

IF (k_bm_fd == -1) {

K_BM_FD = ((* fptr) (path, OFLAG, MODE));

IF (k_bm_fd <= 0) {

PERROR (PATH);

Exit (1);

}

FSTAT (k_bm_fd, & k_bm_stat_buf);

/ *

FPRINTF (stderr, "open the file% d / n", k_bm_fd);

* /

K_BM_BUF = (char *) MMAP ((CADDR_T) 0,

K_BM_STAT_BUF.ST_SIZE, (Prot_Read),

Map_shared, k_bm_fd, 0);

Assert (k_bm_buf! = map_failed);

Return k_bm_fd;

} else {

/ * fprintf (stderr, "re-open the file% d / n", k_bm_fd);

* /

Return k_bm_fd;

}

}

Return ((* fptr) (Path, OFLAG, MODE));

}

INT Close (int Fildes) {

Static int (* fptr) () = 0;

IF (fptr == 0) {

FPTR = (int (*)) DLSYM (RTLD_NEXT, "Close");

IF (fptr == null) {

FPrintf (stderr, "dlopen:% s / n", dLerror ());

Return 0;

}

}

IF (Filde == K_BM_FD) {

/ * fprintf (stderr, "close the file% d / n", k_bm_fd);

* /

Return 0;

}

Return ((* fptr) (FILDES);

}

See Readme File for Details on Now To Compile this Program, and the

Environment Needed to Execute The Oracle Client Program. Appendixes

A3-A6 Explain A Little More About The Test Programs.

A3. Test.c This Test Program Reads The Oraus.msb File 50,000 Times To MiMIC Oracle Client Application Behavior. #Include

#include

#include

#include

#include

#include

INT fd = 0;

INT fd1 = 0;

Char BUF [1024];

Char BUF1 [1024];

INT x1 = 0;

INT x2 = 0;

INT X3 = 0;

INT X4 = 0;

INT X5 = 0;

Int main () {

INT I;

INT R = -1;

For (i = 0; i <50000; i ) {

FD = Open ("/ ORA / App / Oracle / Product / 8.1.7 / Rdbms / Mesg / Oraus.msb", o_rdonly);

/ * fd1 = Open ("/ Oracle / App / Oracle / Product / 8.1.7 / Rdbms / Mesg / Oraus.msb_1", O_RDonly);

* /

/ * fprintf (stderr, "fd =% D fd1 =% D / N", FD, FD1);

* /

R = fcntl (fd, f_setfd);

Lseek (fd, 0, seek_set);

Read (FD, & BUF, 256);

/ *

R = fcntl (fd1, f_setfd);

Lseek (fd1, 0, seek_set);

READ (FD1, & BUF1, 256);

X1 = MEMCMP (& BUF1, & BUF, 256);

IF (x1! = 0) {

FPRINTF (stderr, "x1 DID NOT MACH% D / N", X1);

}

* /

Lseek (FD, 512, seek_set);

Read (FD, & BUF, 512);

/ *

Lseek (FD1, 512, seek_set);

READ (FD1, & BUF1, 512);

X2 = MEMCMP (& BUF1, & BUF, 512);

IF (x2! = 0) {

FPRINTF (stderr, "x2 DID Not Mach% D / N", X2);

}

* /

Lseek (FD, 1024, seek_set);

Read (FD, & BUF, 512);

/ *

Lseek (FD1, 1024, seek_set);

READ (FD1, & BUF1, 512);

X3 = MEMCMP (& BUF1, & BUF, 512);

IF (x3! = 0) {

FPRINTF (stderr, "x3 did not machine / n");

* /

Lseek (FD, 39936, seek_set);

Read (FD, & BUF, 512);

/ *

Lseek (FD1, 39936, Seek_set);

READ (FD1, & BUF1, 512);

X4 = MEMCMP (& BUF1, & BUF, 512);

IF (x4! = 0) {

FPRINTF (stderr, "x4 Did Not Mach / N);

}

* /

Close (FD);

/ *

Close (FD1);

* /

}

}

A4. Test.sh This is a wrapper to execute the test program to show the performance gains of caching the contents of oraus.msb in memory. The LD_PRELOAD and oraus_msb_file environment variables point to cache_oraus.so and the oraus.msb file. #! / BIN / BASH

Export oraus_msb_file = / ora / App / Oracle / Product / 8.1.7 / Rdbms / MESG / ORAUS.MSB

Export ld_preeload = / usr / lib / cache_oraus.so

Export LD_PRELOAD =. / cache_oraus.so

Time ./test

A5. Test1.sh this is a wrapper to execute the test program without the caching mechanism. #! / Bin / bash

Time ./test

A6. Test_v.c This Program WAS Used to Verify That The Interposed Calls Work Properly. #Include

#include

#include

#include

#include

#include

INT fd = 0;

INT fd1 = 0;

Char BUF [1024];

Char BUF1 [1024];

INT x1 = 0;

INT x2 = 0;

INT X3 = 0;

INT X4 = 0;

INT X5 = 0;

Int main () {

INT I;

INT R = -1;

For (i = 0; i <50000; i ) {

FD = Open ("/ ORA / App / Oracle / Product / 8.1.7 / Rdbms / Mesg / Oraus.msb", o_rdonly);

FD1 = Open ("/ ORA / App / Oracle / Product / 8.1.7 / Rdbms / Mesg / ORAUS.MSB_1", O_RDONLY);

/ * fprintf (stderr, "fd =% D fd1 =% D / N", FD, FD1);

* /

R = fcntl (fd, f_setfd);

Lseek (fd, 0, seek_set);

Read (FD, & BUF, 256);

R = fcntl (fd1, f_setfd);

Lseek (fd1, 0, seek_set);

READ (FD1, & BUF1, 256);

X1 = MEMCMP (& BUF1, & BUF, 256);

IF (x1! = 0) {

FPRINTF (stderr, "x1 DID NOT MACH% D / N", X1);

}

Lseek (FD, 512, seek_set);

Read (FD, & BUF, 512);

Lseek (FD1, 512, seek_set);

READ (FD1, & BUF1, 512);

X2 = MEMCMP (& BUF1, & BUF, 512);

IF (x2! = 0) {

FPRINTF (stderr, "x2 DID Not Mach% D / N", X2);

}

Lseek (FD, 1024, seek_set);

Read (FD, & BUF, 512);

Lseek (FD1, 1024, seek_set);

READ (FD1, & BUF1, 512);

X3 = MEMCMP (& BUF1, & BUF, 512);

IF (x3! = 0) {

FPRINTF (stderr, "x3 Did Not Mach / N);

}

Lseek (FD, 39936, seek_set);

Read (FD, & BUF, 512);

Lseek (FD1, 39936, Seek_set);

READ (FD1, & BUF1, 512);

X4 = MEMCMP (& BUF1, & BUF, 512);

IF (x4! = 0) {

FPRINTF (stderr, "x4 Did Not Mach / N);

}

Close (FD);

Close (FD1);

}

}

A7. Test_v.sh this is a wrapper for testing test_v.c. #! / Bin / bash

Export ld_preeload = / usr / lib / cache_oraus.so

Export LD_PRELOAD =. / cache_oraus.so

Time ./test_v

A8. C.SH #! / Bin / bash

Path = / OPT / SUNWSPRO / BIN /: $ PATH

EXPORT PATH;

cc -fast -xarch = v8plusa -xdepend-xvector -xstrconst-xprefetch -g-o

Cache_open_calls.so cache_open_calls.c-ldl

cc -fast-xdepend-xvector -xstrconst -xarch = v8plusa-xprefetch -g-

Cache_oraus.so cache_oraus.c-ldl

cc -fast -xstrconst -xvector -xdepend -xarch = v8plusa-xprefetch -o

Test Test.c-LDL

cc -fast -xstrconst -xvector -xdepend -xarch = v8plusa-xprefetch -o

Test_v Test_v.c-LDL

A9. C64.sh #! / Bin / bash

# Changes to Source Cache_oraus.c for 64 Bit Support Was Made

# by Ben Humphreys

Path = / OPT / SUNWSPRO / BIN /: $ PATH

EXPORT PATH;

Cc-Fast -xarch = V9A -XCODE = ABS64 -XDEPEND -XVECTOR -XSTRCONST -XPREFETCH -G -OCACHE_OPEN_CALLS.SO CACHE_OPEN_CALLS.C-LDL

cc -fast -xarch = v9a -xcode = abs64 -xdepend -xvector -xstrconst-xprefetch -g-g

Cache_oraus.so cache_oraus.c-ldl

cc -fast -xarch = v9a -xcode = abs64 -xstrconst -xvector -xdepend-xprefetch -o

Test Test.c-LDL

cc -fast -xarch = v9a -xcode = abs64 -xstrconst -xvector -xdepend-xprefetch -o

Test_v Test_v.c-LDL

a10. cache_open_calls.c / *

Date: April 18, 02

Author: Nagendra Nagarajayya

Description: Caches Open, And Close Calls to Oraus.msb File

* /

#include

#include

#include

#include

#include

Static int k_bm_fd = -1;

INT OPEN (const char * path, int OFLAG, MODE_T MODE) {

Static int (* fptr) () = 0;

IF (fptr == 0) {

FPTR = (int (*)) DLSYM (RTLD_NEXT, "Open");

IF (fptr == null) {

FPrintf (stderr, "dlopen:% s / n", dLerror ());

Return 0;

}

}

IF (strCMP (path, "/oracle/app/racle/product/8.1.7/rdbms/meses) == 0) {

IF (k_bm_fd == -1) {

K_BM_FD = ((* fptr) (path, OFLAG, MODE));

IF (k_bm_fd <= 0) {

PERROR (PATH);

Exit (1);

}

/ * fstat (k_bm_fd, & k_bm_stat_buf);

FPRINTF (stderr, "open the file% d / n", k_bm_fd);

* /

Return k_bm_fd;

} else {

/ * fprintf (stderr, "re-open the file% d / n", k_bm_fd);

* /

Return k_bm_fd;

}

}

Return ((* fptr) (Path, OFLAG, MODE));

}

INT Close (int Fildes) {

Static int (* fptr) () = 0;

IF (fptr == 0) {

FPTR = (int (*)) DLSYM (RTLD_NEXT, "Close");

IF (fptr == null) {

FPRINTF (stderr, "dlopen:% s / n", dLerror ()); Return 0;

}

}

IF (Filde == K_BM_FD) {

/ * fprintf (stderr, "close the file% d / n", k_bm_fd);

* /

Return 0;

}

Return ((* fptr) (FILDES);

}

About the Author Nagendra Nagarajayya has been at Sun for more than 9 years. A Staff Engineer in Market Development Engineering (MDE / IPE), he works with telco ISVs on architecture, performance tuning, sizing and scaling, benchmarking, porting, and so on HA, Concurrency and Parallelism, HA, Distributed Computing, Networking, And The Java and Solaris Platforms.

转载请注明原文地址:https://www.9cbs.com/read-121919.html

New Post(0)