如何加快ORACLE本地OCI的调用速度

C/C++访问数据库——Oracle之OCI篇 <br />Linux下使用C/C++访问数据库——Oracle之OCI篇  一、什么是OCI?开发基于Oracle数据库的应用程序,我们可以选择多种工具,不仅可以用一般的数据库开发技术,诸如ADO(ActiveX Data Objects)、ODBC(Open DataBase Connectivity)等等,同时,也可以用Oracle公司提供的专门的开发工具,诸如Pro C_C++,OCI(Oracle Call Intedace)等等。比较这几种方式,前者因为是通用技术,开发起来比较容易,但是有一个致 阅读详情

 此文摘自 developers.sun.com 写的很精采, 我自己试用了一下, 性能果然有所提高
Skip Masthead Linksdevelopers.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:
  1. Introduction
  2. Identifying the Problem
  3. The Workaround: Cache oraus.msb in Memory
  4. Building cache_oraus.so
  5. How to Use cache_oraus.so
  6. 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
  7. Performance Improvement
      7.1  Without LD_PRELOAD and cache_oraus.so
      7.2  With LD_PRELOAD and cache_oraus.so
  8. Caveat
  9. Conclusion
  10. Acknowledgments
  11. References
        A.  Appendix: Test Programs and Wrappers
               A1.  README
               A2.  cache_oraus.c
               A3.  test.c
               A4.  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 interest are the 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 be preloaded before an application begins execution. To make use of this technique, we need to build a shared library that will interpose on the open(), fcntl(), lseek(), read(), and close() calls.

4. 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 dl

64-bit:

cc -G -o cache_oraus.so -fast -xarch=v9a cache_oraus.c -l dl

5. How to Use cache_oraus.so

The following environment variables need to be set to use the caching mechanism:

export LD_PRELOAD=./cache_oraus.so
export oraus_msb_file=/ora/app/oracle/product/8.1.7/rdbms/mesg/oraus.msb

This can be set in a shell script used to start the client application.

6. How the Caching Works

The caching works by interposing the open(), fcntl(), lseek(), 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, int oflag, mode_t mode) {
 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/mesg/oraus.msb";
 }
STEP 3
 if (strcmp(path, 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));
}
STEPSDescription
1Use 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  ret;
 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 (fildes == 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));
}
STEPSDescription
1Use 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 then executed (STEP R2). So an I/O call is now transformed to a simple memcpy() call. A close() on the cached file descriptor is ignored so that the cached file descriptor can be reused.

off_t lseek(int fildes, off_t offset, int whence) {
 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, whence));
}
STEPSDescription
L1Use 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));
}
STEPSDescription
R1Use 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 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 (fildes == k_bm_fd) {
  return 0;
  }
STEP C3
  return ((*fptr)(fildes));
}
STEPSDescription
C1Use 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 percent-to-15 percent gain in performance.

7.1 Without LD_PRELOAD and cache_oraus.so
TypeTime in Seconds
Real5.633
User0.010
Sys0.014

Table 6: ptime test.sh

Back to Top

7.2 With LD_PRELOAD and cache_oraus.so
TypeTime in Seconds
Real0.462
User0.010
Sys0.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

  1. Nagendra Nagarajayya, S.R. Venkatramanan, "Fast Sockets, An Interprocess Communication Library to Boost Application Performance"
  2. Sun Product Documentation site
  3. Oracle MetaLink (for news, problems, and bugs)
  4. 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 "AS IS." Sun makes no warranties of any kind whatsoever with respect to the Sample Code.

ALL EXPRESS OR 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 PUNITIVE DAMAGES HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY ARISING OUT OF THE USE OF OR INABILITY 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
the path to the oraus.msb file using the ENV variable, "oraus_msb_file".
If the env is not specified, the  following path is used,
/oracle/app/oracle/product/8.1.7/rdbms/mesg/oraus.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.msb
Note:
 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 reading the contents properly,
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, 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 PUNITIVE DAMAGES HOWEVER CAUSED 
AND REGARDLESS OF THE THEORY OF LIABILITY ARISING OUT OF THE USE OF OR INABILITY 
TO USE THE SAMPLE CODE, EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <dlfcn.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <assert.h>
#include <sys/mman.h>
#include <sys/int_types.h>
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 ret;
 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 (fildes == 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 whence) {
 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 (fildes == 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, whence));
}
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, "fildes = %d k_bm_fd = %d /n", fildes, k_bm_fd);
*/
 if (fildes == 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/mesg/oraus.msb";
 }
 if (strcmp(path, 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 (fildes == k_bm_fd) {
/*  fprintf(stderr, "close the file %d/n",k_bm_fd);
*/
  return 0;
  }
  return ((*fptr)(fildes));
}
See README file for details on how 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 <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
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 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);
*/
 }
 
}
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_PRELOAD=/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 <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
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_PRELOAD=/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 -o 
    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 -o 
    cache_open_calls.so cache_open_calls.c -ldl
cc -fast -xarch=v9a -xcode=abs64 -xdepend -xvector -xstrconst -xprefetch -G -o 
    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 
< name=A10>
A10. Cache_open_calls.c
/*
 Date: April 18, 02
 Author: Nagendra Nagarajayya
 Description: Caches open, and close calls to oraus.msb file 
*/
#include <stdio.h>
#include <unistd.h>
#include <dlfcn.h>
#include <string.h>
#include <stdlib.h>
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/oracle/product/8.1.7/rdbms/mesg/oraus.msb") == 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 (fildes == 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. His interests include multithreading, concurrency and parallelism, HA, distributed computing, networking, and the Java and Solaris platforms.

Navicat与Oracle数据库交互的OCI.dll配置指南 Oracle Instant Client提供了一种快捷方便的方式,允许用户通过oci.dll与Oracle数据库进行交互。相较于传统的Oracle安装方式,使用Instant Client有以下几个明显优势:轻量级安装:Instant Client的安装包体积较小,安装过程快速简便,不会占用过多系统资源。灵活性高:它允许开发者快速切换不同版本的oci.dll,方便进行版本控制和兼容性测试。易于维护:Instant Client的配置相对简单,可以轻松集成到各种应用程序中。 阅读详情

相关推荐

oci导出工具,oracle数据导出工具

用于oracle数据导出的工具,蛮好用的

oracle数据库oci接口慢怎么处理,如何加快ORACLE本地OCI的调用速度数据库教程 -电脑资料...

oracle|速度此文摘自 developers.sun.com 写的很精采, 我自己试用了一下, 性能果然有所提高 developers.sun.comTechnical Articles & Tips Cache OCI Calls to Improve Performance of 32-Bit or 64-Bit Oracle ClientsBy Nagendra Nagaraja...

weixin_33384949的博客 608

OCI连接oracle数据库(c++)实现

OCI连接oracle数据库(c++)实现 已经封装好的c++实现的Oci

ORACLE-TIPS:Oracle登陆慢的原因及解决方法

PL/SQL登陆oracle慢的原因: 一般是由于监听日志(listener.log)文件过大导致的. 文件所在位置:$ORACLE_HOME\diag\tnslsnr\机器名\listener\trace 我本机的文件位置:E:\app\Q\diag\tnslsnr\DESKTOP-VGT86L\listener\trace 解决方法: 1.关闭oracle的监听服务. 2.将listener.log文件备份后清除(可将原文件直接重命名为listener-bak)。 3.开启监听服务后即可登陆oralce

qq_24940709的博客 1912

如何使用Ray和PyTorch训练模型

用户编写训练函数 → 定义单机训练逻辑。通过扩缩容配置 → 指定需要多少资源(Worker 数量、CPU/GPU)。训练器整合训练函数和配置 → 自动将训练函数分发到多个 Worker 上并行执行。Worker 运行训练函数 → 在分布式环境中完成模型训练。通过这种模式,Ray Train 实现了对分布式训练的抽象,用户只需关注单机训练逻辑,无需手动管理分布式通信和资源分配。

m0_62464865的博客 1925

法兰克仿真软件FANUC CNC Guide v25.0 安装教程及中文设置

下载地址在文末。我们公司用新到一批FANUC 系统的设备,为方便使用就装了一个 FANUC 数控系统仿真软件FANUC CNC Guide v25.0 ,还是最新版不是市面上流传的老版本。模拟学习一下。

hakesashou的博客 1万+

部署 PHP 系列: 加速用于 Oracle 的 PHP 代码运行速度

部署 PHP 系列,第 3 部分: 加速用于 Oracle 的 PHP 代码运行速度作者:Ilia Alshanetsky 加速 PHP 应用程序的简单有效技巧的指南

老夏课堂-夏曹俊的技术专栏 1002

Linux服务器上2DGS复现:从环境配置到模型训练的全流程解析

本文详细解析了在Linux服务器上复现2D Gaussian Splatting(2DGS)项目的完整流程。内容涵盖从CUDA环境检查、项目克隆、虚拟环境创建,到解决PyTorch版本与CUDA对齐、核心子模块编译等关键步骤。重点分享了使用国内镜像加速依赖安装、处理多版本CUDA共存的实用技巧,并提供了数据准备、模型训练参数调优及结果可视化的实战指南,旨在帮助开发者高效完成2DGS的复现与部署。

weixin_29248611的博客 60

oracle发邮件时间不对,oracle 发邮件错误

oracle 发邮件错误下面存储过程执行后有错误,create or replace procedure test_mail(msg_subject in varchar2,mes_context in varchar2,to_user in varchar2)isMail_Conn Utl_Smtp.Connection;Msg Varchar2(4000);Msg_Raw Ra...

weixin_32820101的博客 266

Windows安装Pytorch3d

pytorch和pytorch3d版本对应关系如下:https://github.com/facebookresearch/pytorch3d/releasescuda和NVIDIA CUB版本对应关系如下:https://github.com/NVIDIA/cub/releases?page=1本人配置如下:GPU:1050TiCUDA:11.1python:3.8。

Snakewood的博客 4289

Spring AI 实战:如何使用 MCP Server 搭建 MCP 天气查询服务

MCP(Model Context Protocol)是 Anthropic 提出的一种开放协议,它定义了AI 模型与外部世界交互的标准方式。通俗地说:大模型本身只拥有训练数据中的知识,它不知道今天的天气、无法查询你的数据库、不能调用你的内部 API。MCP 就是解决这个问题的"桥梁"——它让模型能够发现并使用外部工具(Tools),就像人用手去操作工具一样。角色职责对应依赖MCP Server暴露工具(Tool),供模型调用MCP Client连接 Server,让模型发现和使用工具本文我们先聚焦。

SmartSi 772

oracle oci的好处,oracle的oci和thin区别

我是今天看到tomcat数据源的配置时,想起来这个问题,刚开始还不晓得thin是什么东西!database.url=jdbc:oracle:thin:angel/oracle@192.168.55.11:1530:monitordb经过上网查询,得到如下结果:jdbc:oracle连接的是oracle数据库thin是一种方法angel/oracle那个angel是用户名,oracle是密码192....

weixin_28882103的博客 1382

ThingsBoard教程(十九):规则节点概览介绍

在ThingsBoard的CE V2.5.6版本中,一共有这几种类型在每一种类都有包含了多个节点,每一种类型的节点都有不同的颜色表示本篇文章做一个简单的概括,后续的文章会详细讲解每一个种类的节点如何使用,每一个节点的使用。一共有10个,使用黄色表示 过滤器节点用于消息过滤和路由。一共有9个,使用绿色 属性节点用于更新传入消息的元数据。一共三个,使用蓝色 转换节点用于更改传入消息字段,如发起者、消息类型、有效负载和元数据。一共21个,使用红色标识 动作节点根据传入的消息执行各种动作。一共9个,使用黄色表示,

知无涯 1万+

Oracle的OCI和Thin区别

Oracle的OCI和Thin区别: 1)连接 jdbc:oracle:thin:@server ip: service jdbc:oracle:oci:@service 2)从使用上来说,oci必须在客户机上安装oracle客户端或才能连接,而thin就不需要,因此

Chen_Weihappy_love的专栏 1380

线性自抗扰控制(LADRC)系统算法框图

NLADRC自抗扰控制从Simulink仿真到PLC控制实现_自抗扰控制器 simulink仿真-CSDN博客本文介绍了如何将ADRC自抗扰控制算法从Simulink仿真应用到PLC控制中,包括Simulink框图、TD微分器模型、MATLAB函数的使用、SCL控制代码,以及非线性状态误差反馈控制率的实现。提供了详细的MATLAB仿真步骤和PLC源代码链接。ADRC自抗扰控制算法(含梯形图完整源代码和算法公式)_adrc算法-CSDN博客。

RXXW_Dor的博客 1472

大数据Alluxio面试题及参考答案

Alluxio 在大数据生态里的定位是作为数据编排层,能在不同计算框架和存储系统之间起到桥梁的作用。它的核心功能在于加速数据访问,让大数据应用能够更高效地使用数据。Alluxio 把数据存储和数据处理分离开来,使计算框架可以在不考虑底层存储细节的情况下访问数据,这样就提高了系统的灵活性和可扩展性。Alluxio 和 HDFS 既存在关联又有区别。从关联方面来看,HDFS 是一种广泛使用的分布式文件系统,很多大数据应用都将其作为主要的数据存储系统。Alluxio 可以和 HDFS 集成,把 HDFS 当作底层

大模型大数据攻城狮的专栏 871

oracle thin和oci 区别

Features of ORACLE JDBC Drivers: 1.JDBC Oci 此驱动类似于传统的ODBC 驱动。因为它需要Oracle Call Interface and Net8,所以它需要在运行使用此驱动的JAVA程序的机器上安装客户端软件   2.JDBC Thin 这种驱动一般用在运行在WEB浏览器中的JAVA程序。它不是通过OCI or Net8,而是通过Java so

u012189294的专栏 2595

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

oracle9i oci driver,Oracle连接 Oracle 的OCI Driver 和 Thin Driver的区别

我是今天看到tomcat数据源的配置时,想起来这个问题,刚开始还不晓得thin是什么东西!database.url=jdbc:oracle:thin:angel/oracle@192.168.55.11:1530:monitordb经过上网查询,得到如下结果:jdbc:oracle连接的是oracle数据库thin是一种方法angel/oracle那个angel是用户名,oracle是密码192....

weixin_35448391的博客 457

廖雪峰Python教程[完整版]

廖雪峰的python教程整理的,已经排好版了,而且还是完整的,适合小白

lwip-2.0.3

lwip是瑞典计算机科学院(SICS)的Adam Dunkels 开发的一个小型开源的TCP/IP协议栈。实现的重点是在保持TCP协议主要功能的基础上减少对RAM 的占用。

初学PHP——使用OCI连接Oracle

1、让PHP支持OCI,只需如下几步: 首先,安装PHP的集成运行环境,或者理解为服务器吧,我安装的是名叫WampServer的,安装好后,从安装目录中找到php.ini文件,比如我本地的路径是D:\wamp\bin\php\php5.3.3,将php.ini中的php_oci8.dll的;去掉,也就是把注释去掉,相当于可以使用php_oci8了。 2、然后wampserver运行后,将php...

远去的渡口 1158

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

oracle的jdbc连接方式:oci和thin

    oci和thin是Oracle提供的两套Java访问Oracle数据库方式。    thin是一种瘦客户端的连接方式,即采用这种连接方式不需要安装oracle客户端,只要求classpath中包含jdbc驱动的jar包就行。thin就是纯粹用Java写的ORACLE数据库访问接口。     oci是一种胖客户端的连接方式,即采用这种连接方式需要安装oracle客户端。oci是Oracl

Thunderous的专栏 1822

Java连接Oracle两种方式thin与oci区别

java连接oracle两种方式thin与oci区别 前几天同事跑过来跟我说, 机房中的一台tomcat服务器跟oracle数据库机连接很慢,查看控制台中的hibernate日志, 基本上是一条sql出来要等个1-2秒再出第二条。但同样的程序在他自己机器上的tomcat运行,同样是连那台数据库机器,就快很多,不会出现前面的每 执行1条sql就卡一次壳的情况。 初步分析,我就想到可能是网络原因, 机...

梦凝哲雪 871

Pro*C还是OCI?

做C/C++做ORACLE开发,是PRO*C好还是OCI好? PRO*C和OCI各有特色吧! PRO*C的好处就是学习难度低,开发效率高,对于数组类型的宿主变量绑定也很方便,如果都使用批量执行的话,性能也是很高的。PRO*C在C/C++代 码中嵌入SQL,然后proc预编译器将pc文件翻译成c或cpp文件,再由GCC编译成目标文件。微软近几年推出了LINQ,相比ORACLE多年前推 出的PRO

3232
上一篇: 先学习学习: Fine-Tune Your Web Site for Windows XP Service Pack 2
下一篇: 为什么一定要装XP SP2?
coyichen
博客等级 码龄22年 0粉丝 15原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值