//longitude
103.983192 ~104.16069 $rand_longitude
= rand(103983192,104160690); $longitude
= $rand_longitude /1000000 ; $lbs
= new lbs(); $lbs->upinfo($user_id,$latitude,$longitude); $n++; mylog($n); $e_time
= microtime( true ); if (($e_time-$b_time)>=60) { exit ; } } function
mylog($content) { file_put_contents( 'upinfo.log' ,$content. "\r\n" ,FILE_APPEND); } ?> |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
<?php /** *
模拟查找附近 * *
@author name <simplephp@163.com> *
@site http: //www .wubiao.info */ include_once( 'lbs.class.php' ); $b_time
= microtime( true ); $n
= 0; while (1) { //latitude
30.59773~30.726786 $rand_latitude
= rand(30597730,30726786); $latitude
= $rand_latitude /1000000 ; //longitude
103.983192 ~104.16069 $rand_longitude
= rand(103983192,104160690); $longitude
= $rand_longitude /1000000 ; $lbs
= new lbs(); $re
= $lbs->serach($latitude,$longitude); $n++; mylog($n); $e_time
= microtime( true ); if (($e_time-$b_time)>=60) { exit ; } } function
mylog($content) { file_put_contents( 'search.log' ,$content. "\r\n" ,FILE_APPEND); } ?> |
测试环境
虚拟机,内存256M,主频2.93GHz
性能结果
模拟了100W活跃用户行为,不断更新,不断查找附近好友
//60 seconds insert
88544
//60 seconds search
117660
//成都 100W人,数据占用内存
11.97M
总结
从测试结果来看,完全能满足,微信、陌陌之类的性能要求;
尚可改进之处:
1、Geohash,可写成PHP C扩展;或者其他Geohash实现方式
2、Redis,内存消耗较大,可考虑redis集群方案
3、本文仅查出本单元格用户,提高精度,可查出周围八个单元个,求交集
4、求出结果,如需按照由远到近排序;读出Redis经纬度,利用距离公式排序方可。(可参照上一篇文字)
附redis安装方法
==============================================================
//redis
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
wget
http: //redis .googlecode.com /files/redis-2 .4.14. tar .gz make make
install // 配置 cp
redis.conf /etc/ vi
/etc/redis .conf #后台 daemonize
yes #日志 logfile
/dev/null #存储 dir
./ // 小内存,内核参数 echo
1 > /proc/sys/vm/overcommit_memory // 防火墙 vi
/etc/sysconfig/iptables -A
RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 6379 -j ACCEPT service
iptables restart // 启动 redis-server
/etc/redis .conf // 测试 redis-cli
set
foo bar OK redis-cli
get foo bar |
==============================================================
//php redis 扩展
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
// 源码 http: //pecl .php.net /package/redis // 手册 http: //redis .readthedocs.org /en/latest/ // 安装 /opt/server/php/bin/phpize . /configure
--with-php-config= /opt/server/php/bin/php-config make make
install // 配置 vi
php.ini [redis] extension
= redis.so |
//longitude
103.983192 ~104.16069 $rand_longitude
= rand(103983192,104160690); $longitude
= $rand_longitude /1000000 ; $lbs
= new lbs(); $lbs->upinfo($user_id,$latitude,$longitude); $n++; mylog($n); $e_time
= microtime( true ); if (($e_time-$b_time)>=60) { exit ; } } function
mylog($content) { file_put_contents( 'upinfo.log' ,$content. "\r\n" ,FILE_APPEND); } ?> |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
<?php /** *
模拟查找附近 * *
@author name <simplephp@163.com> *
@site http: //www .wubiao.info */ include_once( 'lbs.class.php' ); $b_time
= microtime( true ); $n
= 0; while (1) { //latitude
30.59773~30.726786 $rand_latitude
= rand(30597730,30726786); $latitude
= $rand_latitude /1000000 ; //longitude
103.983192 ~104.16069 $rand_longitude
= rand(103983192,104160690); $longitude
= $rand_longitude /1000000 ; $lbs
= new lbs(); $re
= $lbs->serach($latitude,$longitude); $n++; mylog($n); $e_time
= microtime( true ); if (($e_time-$b_time)>=60) { exit ; } } function
mylog($content) { file_put_contents( 'search.log' ,$content. "\r\n" ,FILE_APPEND); } ?> |
测试环境
虚拟机,内存256M,主频2.93GHz
性能结果
模拟了100W活跃用户行为,不断更新,不断查找附近好友
//60 seconds insert
88544
//60 seconds search
117660
//成都 100W人,数据占用内存
11.97M
总结
从测试结果来看,完全能满足,微信、陌陌之类的性能要求;
尚可改进之处:
1、Geohash,可写成PHP C扩展;或者其他Geohash实现方式
2、Redis,内存消耗较大,可考虑redis集群方案
3、本文仅查出本单元格用户,提高精度,可查出周围八个单元个,求交集
4、求出结果,如需按照由远到近排序;读出Redis经纬度,利用距离公式排序方可。(可参照上一篇文字)
附redis安装方法
==============================================================
//redis
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
wget
http: //redis .googlecode.com /files/redis-2 .4.14. tar .gz make make
install // 配置 cp
redis.conf /etc/ vi
/etc/redis .conf #后台 daemonize
yes #日志 logfile
/dev/null #存储 dir
./ // 小内存,内核参数 echo
1 > /proc/sys/vm/overcommit_memory // 防火墙 vi
/etc/sysconfig/iptables -A
RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 6379 -j ACCEPT service
iptables restart // 启动 redis-server
/etc/redis .conf // 测试 redis-cli
set
foo bar OK redis-cli
get foo bar |
==============================================================
//php redis 扩展
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
// 源码 http: //pecl .php.net /package/redis // 手册 http: //redis .readthedocs.org /en/latest/ // 安装 /opt/server/php/bin/phpize . /configure
--with-php-config= /opt/server/php/bin/php-config make make
install // 配置 vi
php.ini [redis] extension
= redis.so |