b2科目四模拟试题多少题驾考考爆了怎么补救
b2科目四模拟试题多少题 驾考考爆了怎么补救

hive hbase handler_handler:function_handlersocket(4)

电脑杂谈  发布时间:2017-01-18 10:16:30  来源:网络整理

而且数据都是保存在原来的INNODB表中的。

在HandlerSocket操作innodb数据表的时候,显然也需要open/close table。

但它只打开一次,然后会reuse。

由于open/close table非常耗时,并且会带来严重的mutex竞争,所以这种改进,极大地提升了性能。

Of course HandlerSocket closes tables when traffics become small etc so that it won’t block administrative commands (DDL) forever.

上图是memcached的原理图。

memcached主要用来缓存数据集(database records)。

因为memcached的get操作比mysql的PK查询要快得多。

如果HandlerSocket获取数据的速度比memcached还要快,那么我们就没必要再使用memcached来缓存数据集了。做做其它缓存还是可以的。比如生成出来的HTML代码,还有一些统计数据等等。

花荣注:貌似我从来没有直接把mysql的数据集扔到memcached中。一直都是把中间结果保存到里面。难道走偏了?

使用 HandlerSocket

看下面这张user表:

CREATE TABLE user (

user_id INT UNSIGNED PRIMARY KEY,

user_name VARCHAR(50),

user_email VARCHAR(255),

created DATETIME

) ENGINE=InnoDB;

在mysql中取出数据的方法如下:

mysql> SELECT user_name, user_email, created FROM user WHERE user_id=101;

+---------------+-----------------------+---------------------+

| user_name | user_email | created |

+---------------+-----------------------+---------------------+

| Yukari Takeba | yukari.takeba@dena.jp | 2010-02-03 11:22:33 |

+---------------+-----------------------+---------------------+

在HandlerSocket中怎样操作呢?

安装HandlerSocket

详细文档看这里:

大概安装步骤如下:

1 下载

2 编译 HandlerSocket客户端和服务器端程序:

./configure --with-mysql-source=... --with-mysql-bindir=... ; make; make install

3 安装插件

mysql> INSTALL PLUGIN 'HandlerSocket' SONAME 'HandlerSocket.so';

安装完毕。不需要修改mysql的源代码。

mysql需要5.1或者以后版本。

编写HandlerSocket 客户端代码

目前HandlerSocket客户端只有C++ 和 Perl的库。还没有php和C的。

#!/usr/bin/perl
 
use strict;
use warnings;
use Net::HandlerSocket;
 
#1. establishing a connection
my $args = { host => 'ip_to_remote_host', port => 9998 };
my $hs = new Net::HandlerSocket($args);
 
#2. initializing an index so that we can use in main logics.
# MySQL tables will be opened here (if not opened)
my $res = $hs->open_index(0, 'test', 'user', 'PRIMARY',
'user_name,user_email,created');
die $hs->get_error() if $res != 0;
 
#3. main logic
#fetching rows by id
#execute_single (index id, cond, cond value, max rows, offset)
$res = $hs->execute_single(0, '=', [ '101' ], 1, 0);
die $hs->get_error() if $res->[0] != 0;
shift(@$res);
for (my $row = 0; $row < 1; ++$row) {
my $user_name= $res->[$row + 0];
my $user_email= $res->[$row + 1];
my $created= $res->[$row + 2];
print "$user_name\t$user_email\t$created\n";
}
 
#4. closing the connection
$hs->close();


本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/jisuanjixue/article-27117-4.html

相关阅读
    发表评论  请自觉遵守互联网相关的政策法规,严禁发布、暴力、反动的言论

    热点图片
    拼命载入中...