mysql handle socket

23
MYSQL Handler Socket Philip zhong 5 .10 .2011

Upload: philip-zhong

Post on 22-Jun-2015

3.111 views

Category:

Technology


0 download

DESCRIPTION

Mysql5.1 handle socket testing and write the java code.

TRANSCRIPT

Page 1: Mysql handle socket

MYSQL Handler Socket

Philip zhong5 .10 .2011

Page 2: Mysql handle socket

Outline

Why using Handler Socket How to build Handler Socket Plug-in Handler Socket configuration

parameter Handler Socket java client program Best Practice for java client Helpful sites

Page 3: Mysql handle socket

Why using Handler Socket

Page 4: Mysql handle socket
Page 5: Mysql handle socket

item with handlesocket without handlesocket

Process=16 and request=1000000*16

QPS:130429Mysql server Cpu(s): 29.0%us, 20.6%sy

QPS:95291Mysql server Cpu(s): 71.2%us, 20.8%sy

Process=32 and request=1000000*32

QPS:268294Mysql server Cpu(s): 58.1%us, 27.8%sy

QPS:103165Mysql server Cpu(s): 71.1%us, 21.1%sy

Process=64 and request=1000000*64

QPS:291960Mysql server Cpu(s): 58.8%us, 28.7%sy

QPS:104180Mysql server Cpu(s): 71.3%us, 22.3%sy

Page 6: Mysql handle socket

How to build Handler Socket Plug-in

Page 7: Mysql handle socket

./autogen.sh

./configure --prefix=/home/oracle/mysql5.1.55/lib/mysql/plugin --with-mysql-source=/package/mysql-5.1.55 --with-mysql-bindir=/home/oracle/mysql5.1.55/bin --with-mysql-plugindir=/home/oracle/mysql5.1.55/lib/mysql/plugin

make

make install

Page 8: Mysql handle socket

mysql> install plugin handlersocket soname 'handlersocket.so';

Page 9: Mysql handle socket

Handler Socket configuration parameter

Page 10: Mysql handle socket

• handlersocket_port (default = '9998') • handlersocket_port_wr (default = '9999')• handlersocket_threads (default = 16, min = 1, max = 3000)• handlersocket_threads_wr (default = 1, min = 1, max = 3000)• handlersocket_sndbuf (default = 0, min = 0, max = 1677216)• handlersocket_rcvbuf (default = 0, min = 0, max = 1677216)• handlersocket_readsize (default = 0, min = 0, max = 1677216)• handlersocket_wrlock_timeout (default = 12, min = 0, max = 3600)• handlersocket_timeout (default = 300, min = 30, max = 3600)• open_files_limit = 65535• innodb_buffer_pool_size =8G

Page 11: Mysql handle socket

Handler Socket java client program

Page 12: Mysql handle socket

Dependent Packages

hs4j-0.1.jarlog4j-1.2.8.jarslf4j-api-1.5.6.jarslf4j-log4j12-1.3.0.jar

Page 13: Mysql handle socket

Java Key methods(1)

• public HSClientImpl(InetSocketAddress inetSocketAddress, int poolSize)

• public IndexSession openIndexSession(String dbname, String tableName,String indexName, String[] columns)

• public IndexSession openIndexSession(int indexId, String dbname, String tableName, String indexName, String[] columns)

Page 14: Mysql handle socket

Java Key methods(2)

• public boolean insert(String[] values)• public int delete(String[] keys)• public int delete(String[] keys, FindOperator

operator)• public int delete(String[] keys, FindOperator

operator, int limit,int offset)• public int update(String[] keys, String[] values,

FindOperator operator)

Page 15: Mysql handle socket

Java Key methods(3)

• public int update(String[] keys, String[] values, FindOperator operator,int limit, int offset)

• public ResultSet find(String[] keys)• public ResultSet find(String[] keys,

FindOperator operator, int limit,int offset)• public ModifyStatement createStatement()

Page 16: Mysql handle socket

Create the MYSQL tablescreate table mt_data( guid varchar(18) not null, orgid int(9) not null, tabid int(9) not null, name varchar(128) not null, IsDeleted char(1) not null, createtime datetime not null, modifytime datetime not null, .... primary key(guid,orgid)) ENGINE=InnoDB CHARSET=utf8;

Page 17: Mysql handle socket

Java example code fragment• HSClient hsClient = new HSClientImpl(new

InetSocketAddress("10.224.56.188", 9999), connectionPoolSize);• final String[] columns = { "guid", "orgid", "tabid", "name",

"IsDeleted", "createtime", "modifytime", "value0",

"value1", "value2", "value3", "value4", "value5", "value6",

"value7", "value8", "value9", "value10", "value11",

"value12", "value13", "value14", "value15" };

IndexSession session = hsClient.openIndexSession("meetingdb","mt_data", "PRIMARY", columns);

• Bind values

final String[] values3 = new String[9];

values3[0] = guid;

values3[1] = "1";

……• session.insert(values)• hsClient.shutdown();

Page 18: Mysql handle socket

Best Practice for java client

Page 19: Mysql handle socket

• HSClient is thread-safe, so you must use it as SINGLETON object in your application.

• Open index is an expensive operation, so reuse an opened index id as much as possible.

• IndexSession is thread-safe,so please reuse an opened IndexSession as much as possible.

• Use IndexSession rather than HSClient • Use ModifyStatement to insert/update data

Page 20: Mysql handle socket

ModifyStatement example code

ModifyStatement stmt = this.session.createStatement();

stmt.setInt(1, 0);stmt.setString(2, "dennis");stmt.setInt(4, 27);stmt.setString(5, "2010-11-28 13:24:00");stmt.update(keys, FindOperator.EQ);

Page 21: Mysql handle socket

Helpful sites

Page 23: Mysql handle socket