{"id":5,"date":"2013-11-12T01:22:30","date_gmt":"2013-11-12T06:22:30","guid":{"rendered":"http:\/\/www.scalemysql.com\/blog\/?p=5"},"modified":"2013-11-12T18:05:31","modified_gmt":"2013-11-12T23:05:31","slug":"introduction-to-handlersocket","status":"publish","type":"post","link":"https:\/\/www.scalemysql.com\/?p=5","title":{"rendered":"Introduction to Handlersocket"},"content":{"rendered":"<p>(originally published 07\/08\/13)<\/p>\n<p>other handlersocket entries:<\/p>\n<p><strong>part II<\/strong> &#8211;  <a href=\"http:\/\/www.scalemysql.com\/blog\/2013\/11\/12\/handlersocket-syntax-perl\/\" title=\"handlersocket examples\">handlersocket syntax Perl\/PHP<\/a><\/p>\n<p><strong>part III<\/strong> &#8211;  <a href=\"http:\/\/www.scalemysql.com\/blog\/2013\/11\/12\/handlersocket-syntax-examples\/\" title=\"handlersocket examples\">handlersocket examples &#8211; Perl<\/a><\/p>\n<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<\/p>\n<p>There is very little practical documentation on the web regarding all of the functionality behind handlersocket, this series of posts is an attempt to shed a little more light on what you can do with this fantastic protocol, heavy on the syntax of basic and meatier examples.<\/p>\n<p><strong>Why would I want to use HandlerSocket?<\/strong><\/p>\n<p>HandlerSocket is essentially a protocol to bypass much of the work done by a traditional SQL call, and particular useful for simple queries where the relative percentage of work done is preparing and executing the statement itself is considerable compared to the work and time of retrieving the data. In that case, the work per query for Handlersocket is a fraction of an SQL request. Additionally, the connections are very light in comparison, and so it\u2019s feasible to have many more concurrent connections. Considering these factors, in an extremely high volume environment, largely consisting of simple key lookups, it can help scale load many times.<\/p>\n<p>For a great deal more information on HandlerSocket,<\/p>\n<p><a title=\"http:\/\/yoshinorimatsunobu.blogspot.com\/2010\/10\/using-mysql-as-nosql-story-for.html\" href=\"http:\/\/yoshinorimatsunobu.blogspot.com\/2010\/10\/using-mysql-as-nosql-story-for.html\" target=\"_blank\">http:\/\/yoshinorimatsunobu.blogspot.com\/2010\/10\/using-mysql-as-nosql-story-for.html<\/a><\/p>\n<p><strong>Comparison to prepared statements<\/strong><\/p>\n<p>Certainly a valid question, prepared statements bypass the most costly part of the process as well, the parsing, which puts the performance in the same ballpark, however there is still open\/closing lock\/unlock and running the query execution plan to consider, making HandlerSocket somewhat faster. It also consumes quite a bit less memory consumption (particularly if the result set is large), and can handle multiple threads per connection and can serve requests in bulk, resulting in many more simultaneous requests served. Additionally, HandlerSocket give you the flexibility to keep queries dynamically built in your code instead of defining them in a server side prepared statement.<\/p>\n<p>You can find a detailed comparison on performance here,<\/p>\n<p><a title=\"http:\/\/www.mysqlperformanceblog.com\/2011\/03\/16\/where-does-handlersocket-really-save-you-time\/\" href=\"http:\/\/www.mysqlperformanceblog.com\/2011\/03\/16\/where-does-handlersocket-really-save-you-time\/\" target=\"_blank\">http:\/\/www.mysqlperformanceblog.com\/2011\/03\/16\/where-does-handlersocket-really-save-you-time\/<\/a><\/p>\n<p><strong><br \/>\nInstallation<\/strong><\/p>\n<p>I\u2019m not going to cover installation here, but there are two main ways,<\/p>\n<p>1) download and install separately <a title=\"https:\/\/github.com\/DeNADev\/HandlerSocket-Plugin-for-MySQL\" href=\"https:\/\/github.com\/DeNADev\/HandlerSocket-Plugin-for-MySQL\" target=\"_blank\">https:\/\/github.com\/DeNADev\/HandlerSocket-Plugin-for-MySQL<\/a><\/p>\n<p>2) it comes with Percona server (Percona server is mysql with many custom enhancements and extras) <a title=\"http:\/\/www.percona.com\/software\/percona-server\/\" href=\"http:\/\/www.percona.com\/software\/percona-server\/\" target=\"_blank\">http:\/\/www.percona.com\/software\/percona-server\/<\/a><\/p>\n<p>Some parts of the installation document will be relevant for both cases,<\/p>\n<p><a title=\"https:\/\/github.com\/ahiguti\/HandlerSocket-Plugin-for-MySQL\/blob\/master\/docs-en\/installation.en.txt\" href=\"https:\/\/github.com\/ahiguti\/HandlerSocket-Plugin-for-MySQL\/blob\/master\/docs-en\/installation.en.txt\" target=\"_blank\">https:\/\/github.com\/ahiguti\/HandlerSocket-Plugin-for-MySQL\/blob\/master\/docs-en\/installation.en.txt<\/a><\/p>\n<p>For it to be accessible through a language (Perl, PHP), you\u2019ll need to download the client for that as well, links below.<\/p>\n<p><strong>Configuration settings<\/strong> (done in My.cnf)<\/p>\n<p>The ports<\/p>\n<p>9999 = read and write<br \/>\n9998 = read<\/p>\n<p>9998 is faster for reads, about 20-30%. Of course it is also secures read only environments.<\/p>\n<pre>loose_handlersocket_port = 9998\r\n loose_handlersocket_port_wr = 9999<\/pre>\n<p>Authorization<\/p>\n<p>Very simple to use and optional, set plain text passwords for each port.<\/p>\n<pre>handlersocket_plain_secret=&lt;secret_for_reads&gt;\r\n handlersocket_plain_secret_wr=&lt;secret_for_readwrites&gt;<\/pre>\n<p><strong>Ways to access HandlerSocket<\/strong><\/p>\n<p>* Natively through telnet or nc<\/p>\n<p>* C++ -&gt; libhsclient folder at <a title=\"https:\/\/github.com\/ahiguti\/HandlerSocket-Plugin-for-MySQL\" href=\"https:\/\/github.com\/ahiguti\/HandlerSocket-Plugin-for-MySQL\" target=\"_blank\">https:\/\/github.com\/ahiguti\/HandlerSocket-Plugin-for-MySQL<\/a><\/p>\n<p>* Perl -&gt; perl-Net-HandlerSocket folder at<a title=\" https:\/\/github.com\/ahiguti\/HandlerSocket-Plugin-for-MySQL\" href=\" https:\/\/github.com\/ahiguti\/HandlerSocket-Plugin-for-MySQL\" target=\"_blank\"> https:\/\/github.com\/ahiguti\/HandlerSocket-Plugin-for-MySQL<\/a><\/p>\n<p>3rd party<\/p>\n<p>PHP<\/p>\n<ul>\n<li><a title=\" http:\/\/code.google.com\/p\/php-handlersocket\/\" href=\" http:\/\/code.google.com\/p\/php-handlersocket\/\" target=\"_blank\"> http:\/\/code.google.com\/p\/php-handlersocket\/<\/a><\/li>\n<li><a title=\"http:\/\/openpear.org\/package\/Net_HandlerSocket\" href=\"http:\/\/openpear.org\/package\/Net_HandlerSocket\" target=\"_blank\">http:\/\/openpear.org\/package\/Net_HandlerSocket<\/a><\/li>\n<\/ul>\n<p>Java<\/p>\n<ul>\n<li><a title=\"http:\/\/code.google.com\/p\/handlersocketforjava\/\" href=\"http:\/\/code.google.com\/p\/handlersocketforjava\/\" target=\"_blank\">http:\/\/code.google.com\/p\/handlersocketforjava\/<\/a><\/li>\n<\/ul>\n<p>Python<\/p>\n<ul>\n<li><a title=\"http:\/\/pypi.python.org\/pypi\/python-handler-socket\" href=\"http:\/\/pypi.python.org\/pypi\/python-handler-socket\" target=\"_blank\">http:\/\/pypi.python.org\/pypi\/python-handler-socket<\/a><\/li>\n<li><a title=\"https:\/\/code.launchpad.net\/~songofacandy\/+junk\/pyhandlersocket\" href=\"https:\/\/code.launchpad.net\/~songofacandy\/+junk\/pyhandlersocket\" target=\"_blank\">https:\/\/code.launchpad.net\/~songofacandy\/+junk\/pyhandlersocket<\/a><\/li>\n<\/ul>\n<p>Ruby<\/p>\n<ul>\n<li><a title=\"https:\/\/github.com\/winebarrel\/ruby-handlersocket\" href=\"https:\/\/github.com\/winebarrel\/ruby-handlersocket\" target=\"_blank\">https:\/\/github.com\/winebarrel\/ruby-handlersocket<\/a><\/li>\n<li><a title=\"https:\/\/github.com\/miyucy\/handlersocket\" href=\"https:\/\/github.com\/miyucy\/handlersocket\" target=\"_blank\">https:\/\/github.com\/miyucy\/handlersocket<\/a><\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>(originally published 07\/08\/13) other handlersocket entries: part II &#8211; handlersocket syntax Perl\/PHP part III &#8211; handlersocket examples &#8211; Perl &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211; There is very little practical documentation on the web regarding all of the functionality behind handlersocket, this series of posts is an attempt to shed a little more light on what you can do with [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-5","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/www.scalemysql.com\/index.php?rest_route=\/wp\/v2\/posts\/5","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.scalemysql.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.scalemysql.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.scalemysql.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.scalemysql.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5"}],"version-history":[{"count":14,"href":"https:\/\/www.scalemysql.com\/index.php?rest_route=\/wp\/v2\/posts\/5\/revisions"}],"predecessor-version":[{"id":235,"href":"https:\/\/www.scalemysql.com\/index.php?rest_route=\/wp\/v2\/posts\/5\/revisions\/235"}],"wp:attachment":[{"href":"https:\/\/www.scalemysql.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.scalemysql.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.scalemysql.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}