对一个保存了100个对象实例的数组进行300次读写,该数组序列化后大小为232KB。
测试环境
网络服务器 | PHP版本 | 操作系统 | 硬件配置 |
---|---|---|---|
NGINX v1.0.4 | PHP-FPM v5.3.6 APC启用 | Archlinux 32bit | Intel(R) Core(TM)2 Duo CPU T9400 @ 2.53GHz Mem: 3G DDR3 Disk: 5400r/s |
测试脚本
测试数据:
```php x0 = 1234567890; $this->x1 = 1234567890; $this->x2 = 1234567890; $this->x3 = 1234567890; $this->x4 = 1234567890; $this->x5 = 1234567890; $this->x6 = 1234567890; $this->x7 = 1234567890; $this->x8 = 1234567890; $this->x9 = 1234567890; $this->x10 = 1234567890; $this->x11 = 1234567890; $this->x12 = 1234567890; $this->x13 = 1234567890; $this->x14 = 1234567890; $this->x15 = 1234567890; $this->x16 = 1234567890; $this->x17 = 1234567890; $this->x18 = 1234567890; $this->x19 = 1234567890; $this->x20 = 1234567890; $this->x21 = 1234567890; $this->x22 = 1234567890; $this->x23 = 1234567890; $this->x24 = 1234567890; $this->x25 = 1234567890; $this->x26 = 1234567890; $this->x27 = 1234567890; $this->x28 = 1234567890; $this->x29 = 1234567890; $this->x30 = 1234567890; $this->x31 = 1234567890; $this->x32 = 1234567890; $this->x33 = 1234567890; $this->x34 = 1234567890; $this->x35 = 1234567890; $this->x36 = 1234567890; $this->x37 = 1234567890; $this->x38 = 1234567890; $this->x39 = 1234567890; $this->x40 = 1234567890; $this->x41 = 1234567890; $this->x42 = 1234567890; $this->x43 = 1234567890; $this->x44 = 1234567890; $this->x45 = 1234567890; $this->x46 = 1234567890; $this->x47 = 1234567890; $this->x48 = 1234567890; $this->x49 = 1234567890; $this->x50 = 1234567890; $this->x51 = 1234567890; $this->x52 = 1234567890; $this->x53 = 1234567890; $this->x54 = 1234567890; $this->x55 = 1234567890; $this->x56 = 1234567890; $this->x57 = 1234567890; $this->x58 = 1234567890; $this->x59 = 1234567890; $this->x60 = 1234567890; $this->x61 = 1234567890; $this->x62 = 1234567890; $this->x63 = 1234567890; $this->x64 = 1234567890; $this->x65 = 1234567890; $this->x66 = 1234567890; $this->x67 = 1234567890; $this->x68 = 1234567890; $this->x69 = 1234567890; $this->x70 = 1234567890; $this->x71 = 1234567890; $this->x72 = 1234567890; $this->x73 = 1234567890; $this->x74 = 1234567890; $this->x75 = 1234567890; $this->x76 = 1234567890; $this->x77 = 1234567890; $this->x78 = 1234567890; $this->x79 = 1234567890; $this->x80 = 1234567890; $this->x81 = 1234567890; $this->x82 = 1234567890; $this->x83 = 1234567890; $this->x84 = 1234567890; $this->x85 = 1234567890; $this->x86 = 1234567890; $this->x87 = 1234567890; $this->x88 = 1234567890; $this->x89 = 1234567890; $this->x90 = 1234567890; $this->x91 = 1234567890; $this->x92 = 1234567890; $this->x93 = 1234567890; $this->x94 = 1234567890; $this->x95 = 1234567890; $this->x96 = 1234567890; $this->x97 = 1234567890; $this->x98 = 1234567890; $this->x99 = 1234567890; } } $repeat = 300; $arr = array(); for ($i = 0; $i < 100; $i++) { $arr[] = new XTest; } ?> ```APC:
```php ```文件:
```php ```Memcached:
```php addServer("127.0.0.1", 11211); $stime = microtime(true); for ($i = 0; $i < $repeat; $i++) { $mem->set('key'.$i, $arr); $mem->get('key'.$i); } $etime = microtime(true); echo $etime-$stime; ?> ```测试结果
APC | 文件 | Memcached |
---|---|---|
3.4926421642303 | 3.6572530269623 | 4.6224999427795 |
总结
- APC效率最高,Memcached效率最低
- APC和Memcached的测试结果很稳定,文件方式的耗时从开始时的4秒逐步降低并稳定在3.6秒
- 猜想:
- 在IO量较小的情况下,文件读写可能确实比通过TCP操作Memcached效率高,但是在IO量较大的情况下,文件方式会出现瓶颈,Memcached的优势会得到体现
- 对于集群应用,通过NFS共享文件缓存的效率会低于Memcached
Posted via UltraBlog.vim.