Do not use LOB in Oracle(OLTP) -- record an optimization experience

简介:

Front knowledge

LOB in Oracle

LOB is used in Oracle to store text logger than 4000. 
We don't use Oracle in a OLTP system. 
Conside of RT and IO, we choose some other ways to provide log text. For example, CDN.

LOB in cx_Oracle

As mentioned in Some tricks when using cx_Oracle, we must convert LOB to string for each line we fetched.

  self._cursor.execute(sql, *args)
    def fix_lob(row):
        def convert(col):
            if isinstance(col, cx_Oracle.LOB):
                return str(col)
            else:
                return col

        return [convert(c) for c in row]

  return [fix_lob(r) for r in self._cursor]

But it will bring out a significant cost of CPU time in Python, which you chould see later.

Profile

I use CProfile to profile my Python code. It's very easy to use.

  import CProfile
  CProfile.run("unittest....")

This is part of my profile.

      ncalls  tottime  percall  cumtime  percall filename:lineno(function)
      209391 1286.084  0.006 1286.559    0.006   DB.py:116(convert)
      4630   346.679   0.075  346.679    0.075   {method 'executemany' of 'cx_Oracle.Cursor' objects}
      4654   90.788    0.020   90.788    0.020   {method 'commit' of 'cx_Oracle.Connection' objects}

200k times call of convert cost 2000+ sec. Is't because Python LOB=>str is very slow. 
4k times of commit and executemany because of the lag between two servers.


目录
相关文章
|
Oracle 关系型数据库 Linux
Linux下oracle数据库spfile参数配置文件丢失问题解决,“ORA-32001: write to SPFILE requested but no SPFILE is in use“问题处理
Linux下oracle数据库spfile参数配置文件丢失问题解决,“ORA-32001: write to SPFILE requested but no SPFILE is in use“问题处理
878 0
Linux下oracle数据库spfile参数配置文件丢失问题解决,“ORA-32001: write to SPFILE requested but no SPFILE is in use“问题处理
|
SQL Oracle 关系型数据库
PostgreSQL Oracle 兼容性 之 - PL/SQL record, table类型定义
背景 Oracle PL/SQL是非常强大的一门SQL编程语言,许多Oracle用户也使用它来处理一些要求延迟低且数据一致性或可靠性要求很高的业务逻辑。 PostgreSQL也有一门非常高级的内置SQL编程语言,plpgsql。与Oracle PL/SQL语法极其类似,但是还是有一些不一样的
5411 0
|
Oracle 关系型数据库 网络安全
|
Oracle 关系型数据库 数据库连接
|
Oracle 关系型数据库 Linux
How to use udev for Oracle ASM in Oracle Linux 6 怎样使用udev在linux 6系统上使用asm
<p><br></p> <p></p> <div id="content" class="bigfont mycontent" style="zoom:1; line-height:23px; font-size:14px; margin:18px 28px; font-family:'lucida Grande',Verdana,'Microsoft YaHei'; clear:bo
2077 0