📜 ⬆️ ⬇️

Some subtleties of Update & Insert in Handler Socket

In continuation of the article The first experience with Handler Socket & php_handlersocket some features of Update & Insert

Some time was spent using UPDATE & INSERT.
all tested on a simple table
CREATE TABLE `test`.`test` (
`keyid` varchar(45),
`value` varchar(45),
PRIMARY KEY (`keyid`)
) ENGINE=MyISAM DEFAULT CHARSET=cp1251


Simple example
$port = 9998;
$hs = new HandlerSocket($host, $port);
$retval = $hs->executeInsert(0, array( '112233090' , '12212212' ));
var_dump($retval);

* This source code was highlighted with Source Code Highlighter .

gave out bool(false);
bool(false);


It turns out, the casket opened simply:
If we watch SHOW PROCESSLIST
show processlist handlersocket
then line 17 of the State column in mode is different from all previous lines:
mode=rd
mode=wr

As mentioned in the article First experience with Handler Socket & php_handlersocket when starting up HandlerSocket 16 reading threads and one writer start. This data is set in my.cnf
loose_handlersocket_threads = 16
# the number of worker threads (for read requests)

loose_handlersocket_threads_wr = 1
# the number of worker threads (for write requests)

So, reading threads (streams) are zabindeny on port 9998, and writing on port 9999. According to this, if you are going to perform INSERT / UPDATE / DELETE operations, you should open the index on port 9999
$host = 'localhost' ;
$port = 9998;
$port_wr = 9999;

$hs = new HandlerSocket($host, $port_ wr);


* This source code was highlighted with Source Code Highlighter .

')
Similarly with the native protocol: telnet akalend.local 9998
tlnet: connect to address fe80::217:f2ff:feee:3a60: Connection refused
Trying 192.168.1.10...
Connected to akalend.local.
Escape character is '^]'.
P 0 test test PRIMARY keyid,value
0 1
0 = 1 123123
0 2 123123 asdasdasd
0 = 1 123123 0 0 D
2 1 readonly
telnet akalend.local 9998
tlnet: connect to address fe80::217:f2ff:feee:3a60: Connection refused
Trying 192.168.1.10...
Connected to akalend.local.
Escape character is '^]'.
P 0 test test PRIMARY keyid,value
0 1
0 = 1 123123
0 2 123123 asdasdasd
0 = 1 123123 0 0 D
2 1 readonly

with INSERT / UPDATE operations, we get an error readonly

telnet akalend.local 9999
Trying fe80::217:f2ff:feee:3a60...
telnet: connect to address fe80::217:f2ff:feee:3a60: Connection refused
Trying 192.168.1.10...
Connected to akalend.local.
Escape character is '^]'.
P 0 test test PRIMARY keyid,value
0 1
0 = 1 123123 1 0 D
0 1 1
0 + 2 1111 12345
0 1
Here, apparently, everything goes perfectly.

Now the code from Listing 1 will give a positive result:
bool(true)


In conclusion, a little testing of the MacX 2Gb 2.3 GHz CoreDuo didn’t sharpen anything (default settings).

100,000 records of 32 bytes were written / read in memcache, redis, memcacheDb, hs, Totyo Tyrant
in one stream, one connection, native protocol.

Results:
noSqlsetget
HS33.424.6 * / 26.3 **
Mc16.715.6
Mcdb21.417.5
redis19.419.6
TokyoTr22.122,8


Time in seconds, was carried out on average 3-5 measurements.
* - to the reading port
** - to the writing port
what else would you like to compare: membase & tarantool

Source: https://habr.com/ru/post/113039/


All Articles