dongmacuo1193 2014-07-31 16:39 采纳率: 0%
浏览 73

如何提高PHP OCI-Lob :: save的性能

I have a script which imports a lot of text files, processes them and then saves the data to an Oracle database. It also saves a copy of the raw data file into a BLOB column. When importing 72 files, each with around 40,000 lines of data in them (~ 3.5Mb each), the script takes well over a minute to execute.

After using xdebug to profile the script, it appears that calls to OCI-Lob::save are taking the most time (~90%). Here is the PHP code I'm using to save the BLOB - pretty standard I think:

$this->_db->setSQL('INSERT INTO IMPORTED_FILES (FILE_BLOB, FILE_NAME, LAST_MODIFIED_DATE, IMPORTED_BY, IMPORTED_DATE) VALUES
                        (EMPTY_BLOB(), :fileName, :lastMod, :userId, SYSDATE) RETURNING FILE_BLOB INTO :fileBlob');
    $blob = \oci_new_descriptor($this->_db->con);
    $this->_db->bind(":fileBlob",$blob,-1,OCI_B_BLOB);
    $this->_db->bind(':fileName',$this->_name);
    $this->_db->bind(':lastMod',$this->_lastModifiedDate);
    $this->_db->bind(':userId',$_SESSION['userid']);
    $this->_db->execute(false);
    $blob->save($this->_contents);

And the table definition:

CREATE TABLE IMPORTED_FILES
  (
    "FILE_ID" NUMBER(*,0) NOT NULL ENABLE,
    "FILE_BLOB" BLOB NOT NULL ENABLE,
    "FILE_NAME"          VARCHAR2(255 CHAR) NOT NULL ENABLE,
    "LAST_MODIFIED_DATE" VARCHAR2(255 CHAR) NOT NULL ENABLE,
    "IMPORTED_BY"        VARCHAR2(255 CHAR) NOT NULL ENABLE,
    "IMPORTED_DATE" DATE NOT NULL ENABLE,
    "REPORT" CLOB,
    CONSTRAINT "IMPORTED_FILES_PK" PRIMARY KEY ("FILE_ID") USING INDEX
    TABLESPACE "DATA_INDEX" ENABLE
  )

Is there any way to make saving BLOBs faster?

UPDATE

Not sure if this helps, but I found the following window in SQL Developer, which shows some parameters concerning the BLOB field. Can any of these settings be changed to make it more efficient?

enter image description here

  • 写回答

1条回答 默认 最新

  • douzhang1955 2014-08-02 20:57
    关注

    (This is more of an extended comment than an answer.)

    The first step, and often the most difficult one, is to find exactly what is slow. The code below runs only in the database and will tell you the best possible case for writing the data.

    drop table test1;
    create table test1(a clob);
    
    --Time to write 72 3.5MB CLOBs.
    --On my old desktop this runs in about 15 seconds.
    declare
        v_clob clob := 'A';
    begin
        --Create a 3.5MB LOB.
        for i in 1 .. 350 loop
            dbms_lob.append(v_clob, lpad('a',10000, 'a'));
        end loop;
    
        for i in 1 .. 72 loop
            insert into test1 values (v_clob);
        end loop;
        commit;
    end;
    /
    

    If that code runs in significantly less than a minute the database likely isn't the problem - look at PHP more closely or look at the network. If that code runs in just under a minute, drill down further and find exactly what the statement is waiting on. A query like this might be a good start:

    select event, v$active_session_history.*
    from v$active_Session_history
    where sql_id = 'ghwdpz6v9k2cj'
    order by sample_time desc;
    
    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题