Mysql handle socket

3,716 views

Published on

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

Published in: Technology, Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
3,716
On SlideShare
0
From Embeds
0
Number of Embeds
227
Actions
Shares
0
Downloads
28
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Mysql handle socket

  1. 1. MYSQL Handler Socket Philip zhong 5 .10 .2011
  2. 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. 3. Why using Handler Socket
  4. 4. item with handlesocket without 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. 5. How to build Handler Socket Plug-in
  6. 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. 7. mysql> install plugin handlersocket soname handlersocket.so;
  8. 8. Handler Socket configuration parameter
  9. 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. 10. Handler Socket java client program
  11. 11. Dependent Packageshs4j-0.1.jarlog4j-1.2.8.jarslf4j-api-1.5.6.jarslf4j-log4j12-1.3.0.jar
  12. 12. 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)
  13. 13. 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)
  14. 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. 15. 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;
  16. 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 values final String[] values3 = new String[9]; values3[0] = guid; values3[1] = "1"; ……• session.insert(values)• hsClient.shutdown();
  17. 17. Best Practice for java client
  18. 18. • 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
  19. 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. 20. Helpful sites
  21. 21. • http://code.google.com/p/hs4j/• http://yoshinorimatsunobu.blogspot.com/201 0/10/using-mysql-as-nosql-story-for.html• https://github.com/ahiguti/HandlerSocket- Plugin-for-MySQL

×