`
dreambyheart
  • 浏览: 29889 次
  • 性别: Icon_minigender_1
  • 来自: 北京
最近访客 更多访客>>
社区版块
存档分类
最新评论

TimesTen学习笔记1(转载ITPUB的帖子)

阅读更多
我最初的了解了TimesTen的一些知识是在ITPUT论坛里面。下面我把论坛里面的内容转贴到我这里,如果需要看原文,可以点击下面的链接。

timesten系列一:简介
     http://www.itpub.net/thread-1034746-1-1.html

timesten系列二:如何安装timesten
     http://www.itpub.net/thread-1035392-1-1.html

timesten系列三:如何安装创建自己的data store
     http://www.itpub.net/thread-1035425-1-3.html

timesten系列四:应用程序如何访问timesten
     http://www.itpub.net/thread-1035428-1-3.html

timesten系列五:如何定义cache,和后台oracle数据库同步数据
     http://www.itpub.net/thread-1035438-1-3.html

timesten系列六:定义复制,实现timesten的高可用性
     http://www.itpub.net/thread-1035491-1-3.html

timesten系列七:配置高可用性的TT,同时实现cache以及和后台oracle集
     http://www.itpub.net/thread-1035515-1-3.html

timesten系列八:性能对比测试
     http://www.itpub.net/thread-1037968-1-1.html



timesten系列一:简介


为什么现在内存型数据库越来越流行,关注者和使用者越来越多呢???
关键原因就是大家对随着IT系统的逐渐大规模使用,数据量越来越大,支撑的用户也越来越多,导致系统越来越慢,用户不满意! 如果你在去网上银行做一个转账操作,折腾了2分钟后,告诉你,无法转账,然后你在执行一次,还是2分钟后,告诉你系统无法完成转账,我相信你会崩溃的。
所以大家对it系统的实时性和可控的响应时间要求越来越高了,因为客户需要。。

现在有了需求,而且这些需求是现有的基于磁盘存储的关系型数据库无法满足的,所以出现了内存型数据库。
比如最出名的timesten,当然还有韩国的altibase,以及eXtremeDB等等。。

为什么内存型数据库能够那么快,能够保证响应时间呢,满足客户需要呢?
我们来看看这组数据,看看内存型数据库 timesten到底有何绝招:
timesten平均修改记录时间 30*百万分之一秒
timesten平均读取记录时间 10*百万分之一秒
比oracle快11到40倍

有感觉了吧,快10倍以上哦,真的很快哦。所以现在timesten在电信,金融等对系统实时性要求很高的行业应用越来越多,
连上海证交所也用了timesten .

既然都是数据库,为什么timesten能够快那么多呢??
1.整个数据都在内存中,不用考虑数据在磁盘上的情况
2.专门针对内存的访问类型做了优化
3.没有oracle里面buffer cache管理的额外负担
4.因为不需要考虑数据在磁盘上,需要从磁盘取数据的种种情况,代码就更加简洁,所以快
5.更少的程序代码和指令,所以快。。
6.程序能够直接通过内存直接访问timesten,不需要tcp/ip的开销了,当然更快了

timesten除了上面提到的优异的性能外,还有几项绝活
1.能够和oracle后台数据库做无缝集成,数据可以在timesten和oracle直接双向流动,可以做到实时
2.timesten可以做成多节点并行提供服务的模式,数据在多个timesten之间直接实现实时或者非实时的传输,
进一步提高了系统的扩展性和可靠性。

timesten主要适用在下面几种场景
1.实时交易系统,比如证券交易,银行网上交易
2.实时查询报表系统,比如电信账单,保险公司的保费收入等等

timesten系列二:如何安装timesten


timesten支持在linux,unix,windows上面运行,最新的版本是 7.0.5 ,下面我们将以在
oracle enterprise linux 5.0 上面为例说明如何安装 timesten,真的很简单,比装oracle简单

安装目录 /oracle/timesten
操作系统版本 oracle enterprise linux 5.0 32bit
需要把SELINUX关闭
timesten instance名字为tt70

1.修改内核参数
修改/etc/sysctl.conf文件,加上如下列
kernel.shmmax=2147483648
kernel.sem = "250 32000 128 100"
net.ipv4.tcp_rmem="4096 4194304 4194304"
net.ipv4.tcp_wmem="98304 4194304 4194304"
net.ipv4.tcp_mem="98304 4194304 4194304"
net.core.rmem_default=65535
net.core.wmem_default=65535
net.core.rmem_max=4194304
net.core.wmem_max=4194304
net.ipv4.tcp_window_scaling=1
net.ipv4.ip_local_port_range="1024 65000"
然后执行 sysctl -p ,使修改生效

2.为了能够连接到oracle做同步,请安装oracle 10.2的客户端
oracle以oracle用户,dba组安装
3.添加用户
useradd -g dba -u 505 timesten
4.用root用户登陆os
然后执行下面的操作,为timesten保存安装信息用
mkdir /etc/TimesTen
chmod 775 /etc/TimesTen
chgrp timesten /etc/TimesTen
5.设置用户.bash_profile
export CLASSPATH=/oracle/timesten/TimesTen/tt70/lib/ttjdbc14.jar:$CLASSPATH
export PATH=/oracle/timesten/TimesTen/tt70/bin:$PATH
export ORACLE_HOME=/oracle/product/10.2.0/db_1
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$ORACLE_HOME/network/lib:/oracle/timesten/TimesTen/tt70/lib:$LD_LIBRARY_PATH
注意:LD_LIBRARY_PATH 一定要包含上面的几个目录,否则cache 会出问题

下载地址 :
http://download.oracle.com/otn/t ... 0500.linux86.tar.gz
然后 解开 timesten安装包
tar xvzf timesten70500.linux86.tar.tar

cd linux86/
./setup.sh

后面会提示输入路径,名称,端口等,一路回车,就ok了,具体的安装提示,请看下面:
NOTE: Each TimesTen installation is identified by a unique instance name.
      The instance name must be a non-null alphanumeric string, not longer
      than 255 characters.

Please choose an instance name for this installation? [ tt70 ]
Instance name will be 'tt70'.
Is this correct? [ yes ]

Please select a product :

  [1] Oracle TimesTen In-Memory Database
  [2] Oracle In-Memory Database Cache

Which product would you like to install? [ 1 ]

Of the three components:

  [1] Client/Server and Data Manager
  [2] Data Manager Only
  [3] Client Only

Which would you like to install? [ 1 ]
Where would you like to install the tt70 instance of TimesTen? [ /home/timesten ] /oracle/timesten
The directory /oracle/timesten does not exist.
Do you want to create it? [ yes ]
Where would you like to create the daemon home directory? [ /oracle/timesten/TimesTen/tt70/info ]
The directory /oracle/timesten/TimesTen/tt70/info does not exist.
Do you want to create it? [ yes ]
Installing into /oracle/timesten/TimesTen/tt70 ...
Uncompressing ...


The TimesTen Demo applications can take up to 64 Mbytes of disk space.
Depending on how your system is configured, you may not want to create the
DemoDataStore directory in the default location,
/oracle/timesten/TimesTen/tt70/info/DemoDataStore

Where would you like to create the DemoDataStore directory? [ /oracle/timesten/TimesTen/tt70/info ]
Creating /oracle/timesten/TimesTen/tt70/info/DemoDataStore ...

NOTE: All installations that replicate to each other must use the same daemon
      port number that is set at installation time. The daemon port number can
      be verified by running 'ttVersion'.

The default port number is 17000.

Do you want to use the default port number for the TimesTen daemon? [ yes ]
The daemon will run on the default port number (17000).

Processing /oracle/timesten/TimesTen/tt70/PERL/perl.tar ...

Would you like to enable datastore access control? [ no ]
The daemon logs will be located in /oracle/timesten/TimesTen/tt70/info
Would you like to specify a different location for the daemon logs? [ no ]

NOTE: It appears that you are running version 4.1 of the g++
      compiler. TimesTen ships with multiple sets of client libraries and server
      binaries : one built with g++ 3.2.3, one with g++ 3.4.6, and one with
      g++ 4.1.0. The installer has created links to the 4.1.0 library in the
      <install_dir>/lib directory and to the 4.1.0 server binary in the
      <install_dir>/bin directory. If you want to use a different compiler,
      please modify the links to point to the desired library and server binary.

Installing server components ...
Would you like to log all server Connects/Disconnects? [ yes ]
What is the TCP/IP port number that you want the TimesTen Server to listen on? [ 17002 ]
Starting the daemon ...
TimesTen Daemon startup OK.

Installing client components ...
What is the name of the host running the TimesTen server? [ rac01 ]
What is the TCP/IP port number that the TimesTen server is listening on? [ 17002 ]
What is the name of the instance running the TimesTen server? [ tt70 ]
Creating new /oracle/timesten/TimesTen/tt70/info/sys.ttconnect.ini
Extracting 3rd party tools ...
Would you like to install the documentation? [ yes ] no
Documentation not installed.
To manually install the documentation, run the command 'setup.sh -installDoc'


NOTE: The TimesTen daemon startup/shutdown scripts have not been installed.

Run the script '/oracle/timesten/TimesTen/tt70/bin/setuproot' as root.
This will move the TimesTen startup script into its appropriate location.

The startup script is currently located here :
  '/oracle/timesten/TimesTen/tt70/startup/tt_tt70'.

End of TimesTen installation.
为了添加随着OS启动而启动timesten daemon的脚本,需要按照提示,用root用户执行下面的脚本:
/oracle/timesten/TimesTen/tt70/bin/setuproot

很简单,就完成了安装了,看看timesten启动之后的进程情况:

ps -ef  |grep timesten
timesten  2200     1  0 18:45 ?        00:00:00 /oracle/timesten/TimesTen/tt70/bin/timestend -initfd 13
timesten  2203  2200  0 18:45 ?        00:00:00 /oracle/timesten/TimesTen/tt70/bin/timestensubd
timesten  2204  2200  0 18:45 ?        00:00:00 /oracle/timesten/TimesTen/tt70/bin/timestensubd
timesten  2205  2200  0 18:45 ?        00:00:00 /oracle/timesten/TimesTen/tt70/bin/timestensubd
timesten  2206  2200  0 18:45 ?        00:00:00 /oracle/timesten/TimesTen/tt70/bin/timestensubd
timesten  2208  2200  0 18:45 ?        00:00:00 /oracle/timesten/TimesTen/tt70/bin/ttcserver
系统安装完成之后,会有一个缺省的data store(这个概念和oracle的schema概念差不多),叫 TpcbData_tt70
我们现在就连接到这个data store来看看,看看timesten工作是否正常。

ttIsql TpcbData_tt70      (注释:ttIsql 是一个和oracle sqlplus差不多的命令行交互控制工具)

[timesten@rac01 info]$ ttIsql TpcbData_tt70

Copyright (c) 1996-2008, Oracle.  All rights reserved.
Type ? or "help" for help, type "exit" to quit ttIsql.
All commands must end with a semicolon character.



connect "DSN=TpcbData_tt70";
Connection successful: DSN=TpcbData_tt70;UID=timesten;DataStore=/oracle/timesten/TimesTen/tt70/info/DemoDataStore/TpcbData;DatabaseCharacterSet=US7ASCII;ConnectionCharacterSet=US7ASCII;WaitForConnect=0;DRIVER=/oracle/timesten/TimesTen/tt70/lib/libtten.so;Authenticate=0;PermSize=16;TypeMode=0;
(Default setting AutoCommit=1)
Command> tables;
  SYS.CACHE_GROUP
  SYS.COLUMNS
  SYS.COLUMN_HISTORY
  SYS.COL_STATS
  SYS.DUAL
  SYS.INDEXES
  SYS.MONITOR
  SYS.OBJ_ACC_RIGHT
  SYS.PLAN
  SYS.SEQUENCES
  SYS.SYNONYMS
  SYS.SYS_ACC_RIGHT
  SYS.TABLES
  SYS.TABLE_HISTORY
  SYS.TBL_STATS
  SYS.TCOL_STATS
  SYS.TINDEXES
  SYS.TRANSACTION_LOG_API
  SYS.TTABLES
  SYS.TTBL_STATS
  SYS.USERS
  SYS.VIEWS
  SYS.XLASUBSCRIPTIONS
  TTREP.REPELEMENTS
  TTREP.REPLICATIONS
  TTREP.REPNETWORK
  TTREP.REPPEERS
  TTREP.REPSTORES
  TTREP.REPSUBSCRIPTIONS
  TTREP.REPTABLES
  TTREP.TTSTORES
31 tables found.


在来做一个创建表的测试

Command> create table test(id number(2));
Command> insert into test values(1);
1 row inserted.
Command> commit;
Command> select * from test;
< 1 >
1 row found.

TT的语法和oracle几乎是一样的,特别是dml和ddl,所以,如果有oracle的基础,就很容易了。

ok,TT工作正常,安装顺利结束。
如何启动停止timesten呢?(以后就简称timesten为TT)
启动TT
ttDaemonAdmin -start
停止TT
ttDaemonAdmin -stop

TT的所有配置文件都放在 install_dir/info目录下
TT产生的日志也都在  install_dir/info
在完成上面的安装任务之后,因为我们需要TT存放我们应用的数据,我们就要配置自己的data store了(理解为oracle里面的schema)。
在做这个任务之前,需要厘清一个概念,DSN=data source name ,这个是标准的ODBC的用语,用来描述一个可以提供odbc连接的数据库服务器,
在timesten里面,所有的连接都是通过odbc的,就算是jdbc也是通过odbc连接到到TT上的。

在TT里面,有两种DSN
1.系统一级的DSN定义在服务器端,定义该data store的文件存放位置,以及其他的一些控制参数,比如是否需要log,是否打开checkpoint等等。  
2.客户端的DSN,用来描述一个远端服务器上的data store,客户端程序用来连接到服务器


首先我们在刚才装好的TT服务器上定义个两个DSN,一个系统一级的,一个用户一级的

打开 $INSTALL_DIR/info/sys.odbc.ini
在[ODBC Data Sources] 下面添加如下两行 ,定义我们这个data store需要的driver
wzy_tt70=TimesTen 7.0 Driver
wzyCS_tt70=TimesTen 7.0 Client Driver 
然后在 该文件的最后,添加如下内容:
#定义系统一级的DSN 的名字
[wzy_tt70]
#定义驱动
Driver=/oracle/timesten/TimesTen/tt70/lib/libtten.so
#定义文件存放位置,数据文件和log都是放在info/wzy目录下,以 wzy 为前缀开始的
DataStore=/oracle/timesten/TimesTen/tt70/info/wzy/wzy
#定义数据库的字符集
DatabaseCharacterSet=WE8ISO8859P1
#定义是否需要用户授权认证
Authenticate=0
#定义内存大小
PermSize=64
TempSize=16
#定义用户一级的DSN
[wzyCS_tt70]
#服务器的地址
TTC_SERVER=LocalHost_tt70
#服务器data store的系统一级的DSN 名字,对应上面定义的 名字
TTC_SERVER_DSN=wzy_tt70
然后我们创建 wzy这个目录
mkdir wzy

到目前为止,一个data store已经创建成功了。

我们来测试一下

[timesten@rac01 info]$ ttIsql wzy_tt70

Copyright (c) 1996-2008, Oracle.  All rights reserved.
Type ? or "help" for help, type "exit" to quit ttIsql.
All commands must end with a semicolon character.



connect "DSN=wzy_tt70";
Connection successful: DSN=wzy_tt70;UID=tt;DataStore=/oracle/timesten/TimesTen/tt70/info/wzy/wzy;DatabaseCharacterSet=WE8ISO8859P1;ConnectionCharacterSet=US7ASCII;DRIVER=/oracle/timesten/TimesTen/tt70/lib/libtten.so;OracleId=rac1;Authenticate=0;PermSize=64;TempSize=16;TypeMode=0;
(Default setting AutoCommit=1)


Command> create table test (id number(2));
Command> insert into test values(10);
1 row inserted.
Command> commit;
Command> select * from test;
< 10 >
1 row found.

成功!
看看 wzy目录下,产生了什么

[timesten@rac01 info]$ cd wzy
[timesten@rac01 wzy]$ ls -alt
total 223372
drwxrwxr-x 2 timesten timesten     4096 Aug  7 19:12 .
-rw-rw-rw- 1 timesten timesten 11982420 Aug  7 19:12 wzy.ds0
-rw-rw-rw- 1 timesten timesten  3178496 Aug  7 19:12 wzy.log0
-rw-rw-rw- 1 timesten timesten 12021760 Aug  7 19:10 wzy.ds1
drwxr-xr-x 5 timesten timesten     4096 Aug  7 19:10 ..
-rw-rw-rw- 1 timesten timesten      184 Aug  5 22:47 wzy.inval

我们看到已经生了一些数据文件和日志文件。

timesten系列四:应用程序如何访问timesten


由于现在基于j2ee的应用越来越多,我就以java为例,说明如何通过jdbc连接到上一节我们建立好的data store.

首先我们需要定义classpath,加上如下的timesten的jdbc
/oracle/timesten/TimesTen/tt70/lib/ttjdbc14.jar::.:/oracle/product/10.2.0/db_1/jdbc/lib/ojdbc14.jar


然后通过如下的程序代码进行访问

import java.sql.*;
import javax.sql.*;
public class Tttest{
public static void main(String args[])
{
//远程连接需要的url,程序和TT不在一台服务器。需要按照上节的方法,提前定义好DSN
String URL = "jdbc:timesten:client:dsn=wzyCS_tt70";
//本地连接需要的url,程序和TT在同一台服务器
//String URL = "jdbc:timesten:direct:dsn=wzy_tt70";

Connection con = null;
try {
//加载TT的驱动程序
Class.forName("com.timesten.jdbc.TimesTenDriver");
} catch (ClassNotFoundException ex) {ex.printStackTrace();
}
try
{
//获得连接
con = DriverManager.getConnection(URL);
System.out.println("connected");
//创建jdbc 语句
java.sql.Statement st=con.createStatement();
//执行sql 查询操作
java.sql.ResultSet rs=st.executeQuery("select * from test");
while (rs.next())
{
//取出结果集
System.out.println(rs.getString("id"));
}

//关闭连接
con.close();
// Handle any errors
} catch (SQLException ex) {
ex.printStackTrace();}
}
}


如果TT工作正常,DSN定义正常,我们就能看到java程序输出 结果了。
除了刚开始的url和driver不一样以外,其他的都是标准的jdbc语法,很简单,也很强大。

timesten系列五:如何定义cache,和后台oracle数据库同步数据


TT最典型的应用,就是TT后台连接一个oracle数据库,TT只保留少量的最需要的数据以提供最快的访问速度,尔后台oracle数据库则用来保留所有的数据,在TT需要的时候,可以从oracle里面自动抽取数据到TT,当然,TT里面的数据也可以自动同步到oracle,这个功能,是目前其他内存型数据库暂时无法提供的,或者不可能做到这么好的,毕竟TT和oracle是同一家公司的产品,当然能够更好的无缝集成了。


在TT里面,cache有下面几种类型
1.read only
数据从oracle 自动刷新到 TT里面,TT里面无法做修改。
典型应用是在TT里面保存只读的产品信息,用户信息等等,定期从oracle刷新该信息
2.异步写
数据在TT里面更新,异步传递到oracle 。
这种比较适合在TT上面做事务性操作,然后同步到oracle
3.同步写
数据在TT里面更新,同步传递到oracle 。
这种比较适合在TT上面做事务性操作,然后同步到oracle
4.人工管理的cache
在这种模式下,数据可以同时在TT和oracle里面更新,自动同步到对方。
这种方式最灵活,但是需要考虑数据冲突的问题,比如同时在oracle和TT上面修改统一条记录,怎么处理。
当然TT提供了基于时间戳的处理机制。

同步的原理是在oracle上面更新的数据会通过trigger捕获记录下来,然后通过cache agent定期来获取这些信息同步到TT。
而TT上的同步则是通过分析TT的操作日志来获得做了那些DML操作,然后通过cache agent同步到oracle .
由于我们第一次安装TT的时候,没有安装 cache  connect to oracle ,所以还无法实现和oracle的通信,
所以首先我们需要做得就是安装 cache  connect to oracle .

如果在配置cache之前,没有安装oracle client,请先安装好oracle client 。
TT支持如下版本的oracle client
9.2.0.8  or above
10.1.0.5 or above
10.2.0.1 or above

很简单的操作步骤,还是执行 setup.sh
./setup.sh -installCache  ,然后安装提示,一路next下去,就ok了,详细信息请看下面的log


[timesten@rac01 linux86]$ ./setup.sh -installCache

There is 1 TimesTen instance installed locally :

1) tt70 (TimesTen7.0.5.0.0)

NOTE: There is only one instance which can be upgraded.

Instance Name          : tt70
Product Installed      : TimesTen7.0.5.0.0
Installation Directory : /oracle/timesten/TimesTen/tt70
BitLevel               : 32
Component Installed    : Client/Server and DataManager
Daemon Port            : 17000

Would you like to upgrade this instance? [ yes ]

Extracting Cache Connect to Oracle ...

The following variables have been set in the file :
/oracle/timesten/TimesTen/tt70/bin/ttThunk

ORACLE_HOME=/oracle/product/10.2.0/db_1
LD_LIBRARY_PATH=/oracle/timesten/TimesTen/tt70/lib:/oracle/product/10.2.0/db_1/lib32:/oracle/product/10.2.0/db_1/network/lib32:/oracle/product/10.2.0/db_1/lib:/oracle/product/10.2.0/db_1/network/lib

Would you like to enable the Cache Connect to Oracle Administrator? [ yes ]
What TCP/IP port number would you like Cache Connect to Oracle Administrator to listen on? [ 17004 ]

NOTE: To access the TimesTen Cache Connect to Oracle Administrator
      go to the url: http://localhost:17004/cache


Restarting the daemon ...
TimesTen Daemon stopped.
TimesTen Daemon startup OK.
End of TimesTen installation.
然后检查timesten 用户的.bash_profile文件,确认 ORACLE_HOME是否设置为正确的oracle client的安装目录,
确认LD_LIBRARY_PATH ,一定要包含
$ORACLE_HOME/lib:$ORACLE_HOME/network/lib


然后在oracle上面创建 用户,以便TT用来连接到oracle
sqlplus '/as sysdba'
create user tt identified by tt;
grant connect,resource to tt;

然后修改我们创建的wzy_tt70 data store的系统级DSN(info/sys.odbc.ini),加上如下信息
#oracle数据库用户名
UID=tt
#oracle数据库连接sid
OracleId=rac1 
#oracle数据库密码
OraclePwd=tt

修改后的完整DSN如下(注意:DatabaseCharacterSet必须和oracle的一致):
[wzy_tt70]
Driver=/oracle/timesten/TimesTen/tt70/lib/libtten.so
DataStore=/oracle/timesten/TimesTen/tt70/info/wzy/wzy
DatabaseCharacterSet=WE8ISO8859P1
Authenticate=0
PermSize=64
TempSize=16
UID=tt
OracleId=rac1
OraclePwd=tt
在oracle client端的tnsnames.ora 里面添加一个名字叫rac1(对应上面定义的OracleId)的别名,如下

RAC1 =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = rac01)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = rac)
      (INSTANCE_NAME = rac1)
    )
  )

在oracle里面创建一个测试表
sqlplus tt/tt@rac1
create table t1(id number(2) primary key);

开始创建cache group ,
ttIsql wzy_tt70
Command>call ttCacheUidPwdSet('tt','tt');    #设置连接到oracle的用户名和密码
Command>call ttCacheStart;                        #启动cache


创建一个read only的语法如下

CREATE READONLY CACHE GROUP readcache AUTOREFRESH INTERVAL 1 SECONDS FROM t1 (id number(2) not null primary key); 

注意:from t1后面是跟oracle里面需要同步的表的名字,一定要有同样的列和字段类型,而且一定要有pk或者非空的唯一性索引字段

一个只读的cache group创建好了,然后从oracle里面load一次数据,用如下语法:
LOAD CACHE GROUP readcache COMMIT EVERY 256 ROWS;

然后在oracle里面insert数据,看看是否能在TT里面出现。
创建一个同步的cache group语法如下:
CREATE SYNCHRONOUS WRITETHROUGH CACHE GROUP update_t1
FROM  t1 (id number(2) not null primary key); 

其他的都和创建read only的语法一样。。。

那我们最关心的应该还是创建一个用户管理的cache group,因为只有用户管理的cache group ,才能实现
双向的数据同步,数据可以在oracle上面修改,也可以在TT上修改,都能及时同步到对方。
创建一个用户管理的cache group语法如下:

        CREATE USERMANAGED CACHE GROUP update_anywhere_t1
        AUTOREFRESH
        MODE INCREMENTAL
        INTERVAL 5 SECONDS
        FROM t1(id number(2) primary key,PROPAGATE);

其他的操作和read only一样,比如创建完成之后,需要第一次load数据 。

其中:MODE INCREMENTAL 说明我们从oracle里面是用增量的方式同步数据(会在oracle上面自动创建trigger和额外的表来记录oracle dml的信息),INTERVAL 5 SECONDS 定义每5S从oracle同步一次信息, 尔 PROPAGATE 则定义 TT的dml操作需要同步到 oracle  。。。
如何查看cache agent是否起来了呢? 通过ttStatus命令可以看到很多信息。



[timesten@rac01 info]$ ttStatus
TimesTen status report as of Thu Aug  7 19:46:01 2008

Daemon pid 29374 port 17000 instance tt70
TimesTen server pid 29395 started on port 17002
No TimesTen webserver running

------------------------------------------------------------------------
Data store /oracle/timesten/TimesTen/tt70/info/DemoDataStore/TpcbData
There are no connections to the data store
Replication policy  : Manual
Cache agent policy  : Manual
------------------------------------------------------------------------
Data store /oracle/timesten/TimesTen/tt70/info/wzy/wzy
There are 10 connections to the data store
Data store is in shared mode
Shared Memory KEY 0x1a009307 ID 294916
Type            PID     Context     Connection Name              ConnID
Cache Agent     13199   0x0834c3a0  Handler                           3
Cache Agent     13199   0x083dbb30  Timer                             4
Cache Agent     13199   0x0843cbe8  Aging                             5
Process         5356    0x0985c040  wzy_tt70                          1
Subdaemon       29392   0x0937b760  Worker                         2042
Subdaemon       29392   0x09425378  Flusher                        2043
Subdaemon       29392   0x09484788  Checkpoint                     2044
Subdaemon       29392   0x094d3b90  Aging                          2045
Subdaemon       29392   0x09522f98  HistGC                         2046
Subdaemon       29392   0x095723a0  Monitor                        2047
Replication policy  : Manual
Cache agent policy  : Manual
TimesTen's Cache agent is running for this data store
------------------------------------------------------------------------
timesten系列六:定义复制,实现timesten的高可用性


如果只有一台TT放在前面提供服务,就算它再快,可能你也要考虑一下,这一台TT出问题了怎么办?
TT的解决方案就是通过类似ORACLE data guard技术的复制,实现高可用性。
在TT里面,源TT称为master,而目标TT称为 subscriber 。

在TT里面,可以定义如下一些类型的高可用性环境
1.一台TT为主,另外一台只做数据复制
当主TT出现问题的时候,另外一台接管业务
2.一台TT为主,另外一台TT为active standby
当主TT出现问题的时候,另外一台接管业务,这种模式用得最多,也是TT推荐的模式
3.两台TT同时对外提供服务,但是只分别提供部分表的操作
比如TT A提供表一的操作,同时把表一的修改同步到TT B
而TT B则提供表二的操作,同时把表二的修改同步到TT A
4.两台TT同时对外提供同样的服务
同一张表可以同时在TT A 和TT B上面提供服务

在所有的高可用性模式下,TT都可供了三种数据同步模式
1.完全异步
这种模式下,事物在master 直接提交,由 replication agent根据日志异步完成同步工作
这种模式提高了最高的性能模式。
2.半同步模式
这种模式下,事物在master 提交时,由 replication agent 把修改信息复制到 subscriber ,等 subscriber 确认收到这些修改后,
事物在master上才能提交。
3.完全同步模式
这种模式下,事物在master 提交时,由 replication agent 把修改信息复制到 subscriber ,等 subscriber 确认收到这些修改后,并且在subscriber 应用完成这些事物并提交后,事物在master上才能提交。
这种模式提高了最高的保护模式。

这和oracle的data guard保护模式几乎一致。

同步的原理是 master和 subscriber 都通过replication agent  ,根据日志的信息,相互同步。
复制的单位可以是一张表,几张有主外键关系的表,或者整个data store .

创建复制,非常的简单,以如下环境为例说明
主机 rac01安装了TT ,data store放在 /oracle/timesten/TimesTen/tt70/info/wzy ,文件以wzy开头,DSN=wzy_tt70
主机 rac02安装了TT ,data store放在 /oracle/timesten/TimesTen/tt70/info/wzy ,文件以wzy开头,DSN=wzy_tt70

首席检查rac01和rac02的 /etc/hosts文件,加上对rac01,rac02的解析
如下:
10.0.0.1 rac01
10.0.0.2 rac02
我们以test_r表为例说明,首先在两台TT的data store上面建立该表
ttIsql wzy_tt70
Command> create table test_r(id number(2) primary key);

然后登陆rac01
执行如下操作:从rac01复制到rac02
创建单向的复制
登陆rac01的wzy_tt70 data store
ttIsql wzy_tt70
Command>CREATE REPLICATION reptest ELEMENT TABLE test_r   MASTER wzy on "rac01" SUBSCRIBER wzy on "rac02";

注意:MASTER 和 SUBSCRIBER  后面跟的都是 data store对应的文件名的前缀! 比如
datastore的配置是
/oracle/timesten/TimesTen/tt70/info/wzy/dstest,那么就应该是dstest .


然后在rac01和rac02上面 启动 replication agent
ttAdmin -repStart wzy_tt70

在rac01的wzy_tt70上面生成一些记录,现在就能够同步到rac02的wzy_tt70了。
简单吧?
如何检查replication agent已经起来,而且活动正常呢?
通过ttRepAdmin命令

[timesten@rac01 info]$ ttRepAdmin -showStatus wzy_tt70

Replication Agent Status as of: 2008-08-07 21:41:17

DSN                         : wzy_tt70
Process ID                  : 7009 (Started)
Replication Agent Policy    : manual
Host                        : RAC01
RepListener Port            : 16938 (AUTO)
Last write LSN              : 0.3186408
Last LSN forced to disk     : 0.3186408
Replication hold LSN        : 0.3183424

Replication Peers:
   Name                     : WZY
   Host                     : RAC02
   Port                     : 32677 (AUTO) (Connected)
   Replication State        : STARTED
   Communication Protocol   : 24

TRANSMITTER thread(s):
For                     : WZY
   Start/Restart count   : 1
   Send LSN              : 0.3185200
   Transactions sent     : 0
   Total packets sent    : 9
   Tick packets sent     : 5
   MIN sent packet size  : 48
   MAX sent packet size  : 119
   AVG sent packet size  : 58
   Last packet sent at   : 21:41:16
   Total Packets received: 9
   MIN rcvd packet size  : 48
   MAX rcvd packet size  : 68
   AVG rcvd packet size  : 60
   Last packet rcvd'd at : 21:41:16

RECEIVER thread(s):
For                     : WZY
   Start/Restart count   : 1
   Transactions received : 0
   Total packets sent    : 8
   Tick packets sent     : 0
   MIN sent packet size  : 48
   MAX sent packet size  : 68
   AVG sent packet size  : 60
   Last packet sent at   : 21:41:14
   Total Packets received: 8
   MIN rcvd packet size  : 48
   MAX rcvd packet size  : 119
   AVG rcvd packet size  : 59
   Last packet rcvd'd at : 21:41:14
timesten系列七:配置高可用性的TT,同时实现cache以及和后台oracle集


这种模式应该是最有价值的
两台TT同时对外提供服务,TT直接通过复制实现数据同步,
同时每个TT都通过cache agent把变化的数据传递到后台的ORACLE,这种架构应该是我们最关心的,也是最有用的。


如何配置呢?


以如下环境为例说明
主机 rac01安装了TT ,data store放在 /oracle/timesten/TimesTen/tt70/info/wzy ,文件以wzy开头,DSN=wzy_tt70
主机 rac02安装了TT ,data store放在 /oracle/timesten/TimesTen/tt70/info/wzy ,文件以wzy开头,DSN=wzy_tt70

数据库为一RAC,分别装在rac01和rac02,SID分别为rac1和rac2

1.在oracle上面建立需要同步的表
sqlplus tt/tt@rac1
create table t1(id number(2) primary key);

2.配置rac01和rac02的oracle client的tnsnames.ora,
加上
RAC1 =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = rac01)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = rac)
      (INSTANCE_NAME = rac1)
    )
  )

3.配置rac01和rac02上得wzy_tt70,最后如下

[wzy_tt70]
Driver=/oracle/timesten/TimesTen/tt70/lib/libtten.so
DataStore=/oracle/timesten/TimesTen/tt70/info/wzy/wzy
DatabaseCharacterSet=WE8ISO8859P1
Authenticate=0
PermSize=64
TempSize=16
UID=tt
OracleId=rac1
OraclePwd=tt

4.在rac01和rac02的TT上面分别创建到oracle的cache
ttIsql wzy_tt70
Command>call ttCacheUidPwdSet('tt','tt');
Command>call ttCacheStart;
Command>CREATE USERMANAGED CACHE GROUP update_anywhere_t1
>AUTOREFRESH
>State off
>MODE INCREMENTAL
>INTERVAL 5 SECONDS
>FROM t1(id number(2) primary key,PROPAGATE);

注意:AUTOREFRESH  的        State  一定要设置为 off,因为我们同时打开了两台TT的写和复制功能,就不能自动把oracle的变化同步到TT了,所以在这种情况下,就不建议在oracle上面做事物操作了。

5.在rac01和rac02的TT上面分别创建到复制

ttIsql wzy_tt70
Command> CREATE REPLICATION reptest
>ELEMENT e_1 TABLE t1  MASTER wzy on "rac01" SUBSCRIBER wzy  on "rac02"
>ELEMENT e_2 TABLE t1  MASTER wzy on "rac02" SUBSCRIBER wzy  on "rac01"


6.启动rac01和rac02上面的replication agent

ttAdmin -repStart wzy_tt70


7.在rac01上面的TT从oracle load data
LOAD CACHE GROUP update_anywhere_t1 COMMIT EVERY 256 ROWS;


完工了,一个具有最高可用性的,而且最有实际价值的TT架构就完成了。。。
timesten系列八:性能对比测试


通过前面的系列介绍,相信大家对怎么安装TT,怎么配置TT都比较熟悉了。其实大家最感兴趣的还是TT的性能到底有多强
那么下面将通过对比测试来看看TT的几种连接方式下(直接内存访问,TCP/IP C/S方式,还有打开log和checkpoint)
的性能到底怎么样。。。


测试方法(相对简单,不够完善,希望大家不要扔鸡蛋,毕竟是利用闲暇时间测的):
通过一个java程序,直接连接TT,一次性插入10万条记录(每次测试前,先truncate 表),然后提交,记录从获得jdbc语句之后到执行完成提交所需的时间。

测试分类如下,每个测试5次,取平均时间(单位千分之一秒):
1.通过直接内存访问方式连接,无log,无checkpoint  ,自动commit,平均 1103
2.通过tcp/ip方式连接,无log,无checkpoint  ,自动commit,平均  25339
3.通过直接内存访问方式连接,有log,有checkpoint  ,自动commit,平均 1919
4.对oracle进行同样的操作,由于操作时间太长,放弃..... ,实在太长了
5.通过直接内存访问方式连接,无log,无checkpoint  ,自动commit off,平均 560


结论:
TT客户端通过直接连接方式,直接通过共享内存交换信息,速度是通过tcp/ip的方式的25倍。
如果打开log和checkpoint,性能基本下降1倍。

如果设置autocommit off (缺省是每条语句执行完成,自动commit),性能在提高约一倍!!!
测试的java程序如下:
import java.sql.*;
import javax.sql.*;
public class Bench{
public static void main(String args[])
{
String URL = "jdbc:timesten:client:dsn=wzyCS_tt70";
//String URL = "jdbc:timesten:direct:dsn=wzy_tt70";

Connection con = null;
try {
Class.forName("com.timesten.jdbc.TimesTenDriver");
} catch (ClassNotFoundException ex) {ex.printStackTrace();
}
try
{
con = DriverManager.getConnection(URL);
System.out.println("connected");
java.sql.Statement st=con.createStatement();
java.sql.PreparedStatement  prest=con.prepareStatement("insert into w values(?)");
long  begin_date=java.util.Calendar.getInstance().getTimeInMillis();
for (int i=1;i<100000;i++)
{
prest.setInt(1,i);
prest.executeUpdate();
}

con.commit();


long  end_date=java.util.Calendar.getInstance().getTimeInMillis();

long con_time=end_date-begin_date;
System.out.println("totaol time="+con_time);

con.close();
} catch (SQLException ex) {
ex.printStackTrace();}
}
}
测试配置
1.通过直接内存访问方式连接,无log,无checkpoint
配置如下
sys.odbc.ini

PermSize=64
TempSize=16
Logging=0
DurableCommits=0
CkptFrequency=0
CkptLogVolume=0
LockLevel=1

sys.ttconnect.ini

Network_Address=ttShmHost

ttendaemon.options
-serverShmIpc
-serverShmSize 128M
2.通过tcp/ip方式连接,无log,无checkpoint
配置如下
sys.odbc.ini

PermSize=64
TempSize=16
Logging=0
DurableCommits=0
CkptFrequency=0
CkptLogVolume=0
LockLevel=1

sys.ttconnect.ini

Network_Address=10.0.0.1
3.通过直接内存访问方式连接,有log,有checkpoint
配置如下
sys.odbc.ini

PermSize=64
TempSize=16
#Logging=0
#DurableCommits=0
#CkptFrequency=0
#CkptLogVolume=0
#LockLevel=1

sys.ttconnect.ini

Network_Address=ttShmHost

ttendaemon.options
-serverShmIpc
-serverShmSize 128M
分享到:
评论
3 楼 changkunyang 2010-01-12  
你好,我现在遇上一个问题。
我在windows下配置的tt客户端和环境变量,但是我用java程序访问的时候老是报java.lang.NullPointerException异常,我看了一下是因为得不到数据源。一直没找到原因,不知道这个问题最可能出现错误的地方在哪?
2 楼 dreambyheart 2008-12-23  
在定义客户端的时候应该是已经设定到了 odbc的client里面了吧?windows下面是这样的,在“数据源(ODBC)”-->“Oracle TimesTen Client DSN Setup“里面。
1 楼 chen4059 2008-12-15  
String URL = "jdbc:timesten:client:dsn=wzyCS_tt70";
远程连接的ip和port在哪里设置?

相关推荐

Global site tag (gtag.js) - Google Analytics