Mysql handle socket

Download Mysql handle socket

Post on 22-Jun-2015

3.082 views

Category:

Technology

0 download

Embed Size (px)

DESCRIPTION

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

TRANSCRIPT

<ul><li> 1. MYSQL Handler SocketPhilip zhong 5 .10 .2011</li></ul> <p> 2. 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 3. Why using Handler Socket 4. item with handlesocketwithout handlesocketProcess=16 and QPS:130429 QPS:95291request=1000000*16 Mysql server Mysql server Cpu(s): 29.0%us, 20.6%sy Cpu(s): 71.2%us, 20.8%syProcess=32 and QPS:268294 QPS:103165request=1000000*32 Mysql server Mysql server Cpu(s): Cpu(s): 58.1%us, 27.8%sy 71.1%us, 21.1%syProcess=64 and QPS:291960 QPS:104180request=1000000*64 Mysql server Cpu(s): Mysql server Cpu(s): 58.8%us, 28.7%sy 71.3%us, 22.3%sy 5. How to build Handler Socket Plug-in 6. ./autogen.sh./configure -- prefix=/home/oracle/mysql5.1.55/lib/mysql/pl ugin --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 /pluginmakemake install 7. mysql&gt; install plugin handlersocket soname handlersocket.so; 8. Handler Socket configurationparameter 9. 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 10. Handler Socket java client program 11. Dependent Packageshs4j-0.1.jarlog4j-1.2.8.jarslf4j-api-1.5.6.jarslf4j-log4j12-1.3.0.jar 12. Java Key methods(1) public HSClientImpl(InetSocketAddressinetSocketAddress, int poolSize) public IndexSession openIndexSession(Stringdbname, String tableName,String indexName,String[] columns) public IndexSession openIndexSession(intindexId, String dbname,StringtableName, String indexName, String[]columns) 13. Java Key methods(2) public boolean insert(String[] values) public int delete(String[] keys) public int delete(String[] keys, FindOperatoroperator) public int delete(String[] keys, FindOperatoroperator, int limit,int offset) public int update(String[] keys, String[] values,FindOperator operator) 14. 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() 15. Create the MYSQL tablescreate table mt_data( guid varchar(18) not null, orgidint(9) not null, tabidint(9) not null, namevarchar(128) not null, IsDeleted char(1) not null, createtime datetime not null, modifytime datetime not null, .... primary key(guid,orgid)) ENGINE=InnoDB CHARSET=utf8; 16. 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 valuesfinal String[] values3 = new String[9];values3[0] = guid;values3[1] = "1"; session.insert(values) hsClient.shutdown(); 17. Best Practice for java client 18. HSClient is thread-safe, so you must use it asSINGLETON object in your application. Open index is an expensive operation, soreuse an opened index id as much as possible. IndexSession is thread-safe,so please reuse anopened IndexSession as much as possible. Use IndexSession rather than HSClient Use ModifyStatement to insert/update data 19. ModifyStatement example codeModifyStatement 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); 20. Helpful sites 21. http://code.google.com/p/hs4j/ http://yoshinorimatsunobu.blogspot.com/2010/10/using-mysql-as-nosql-story-for.html https://github.com/ahiguti/HandlerSocket-Plugin-for-MySQL</p>