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

[入库:2005年8月18日] [更新:2007年3月24日]

本文简介:选择自 coyichen 的 blog

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_b

本文关键:如何加快ORACLE本地OCI的调用速度
  相关方案
Google
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top