Mysql handle socket
Upcoming SlideShare
Loading in...5
×
 

Like this? Share it with your network

Share

Mysql handle socket

on

  • 3,603 views

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

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

Statistics

Views

Total Views
3,603
Views on SlideShare
3,441
Embed Views
162

Actions

Likes
0
Downloads
23
Comments
0

17 Embeds 162

http://philipzhong.blogspot.com 120
http://philipzhong.blogspot.in 17
http://philipzhong.blogspot.kr 4
http://philipzhong.blogspot.ru 3
http://philipzhong.blogspot.ro 3
http://www.slashdocs.com 2
http://philipzhong.blogspot.com.br 2
http://philipzhong.blogspot.jp 2
http://philipzhong.blogspot.sg 1
http://philipzhong.blogspot.com.au 1
http://philipzhong.blogspot.fr 1
http://philipzhong.blogspot.tw 1
http://philipzhong.blogspot.co.uk 1
http://philipzhong.blogspot.ie 1
http://philipzhong.blogspot.no 1
http://philipzhong.blogspot.de 1
http://philipzhong.blogspot.nl 1
More...

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Mysql handle socket Presentation Transcript

  • 1. MYSQL Handler Socket Philip zhong 5 .10 .2011
  • 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 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. 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> install plugin handlersocket soname handlersocket.so;
  • 8. Handler Socket configuration parameter
  • 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(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. 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. 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, 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. 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. Best Practice for java client
  • 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. 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/201 0/10/using-mysql-as-nosql-story-for.html• https://github.com/ahiguti/HandlerSocket- Plugin-for-MySQL