我刚刚编写了一段简单的代码来测试Redis + gevent,看看async如何帮助完成性能,我很惊讶地发现性能不佳.这是我的代码.如果你摆脱前两行来修补这段代码,那么你将看到"正常执行"时间.
在Ubuntu 12.04 LTS VM上,我看到的是时机
没有猴子补丁 - 54秒与猴子补丁 - 61秒
我的代码/方法有问题吗?这里有一个性能问题吗?
#!/usr/bin/python
from gevent import monkey
monkey.patch_all()
import timeit
import redis
from redis.connection import UnixDomainSocketConnection
def UxDomainSocket():
pool = redis.ConnectionPool(connection_class=UnixDomainSocketConnection, path = '/var/redis/redis.sock')
r = redis.Redis(connection_pool = pool)
r.set("testsocket", 1)
for i in range(100):
r.incr('testsocket', 10)
r.get('testsocket')
r.delete('testsocket')
print timeit.Timer(stmt='UxDomainSocket()',
setup='from __main__ import UxDomainSocket').timeit(number=1000)
Run Code Online (Sandbox Code Playgroud) 我最近遇到了一个免费的网络服务器gwan(http://gwan.ch),根据许多人看起来很快.我不是非常热衷于基于C的脚本,但我想用它来提供静态内容.我确实在使用gwan的./中看到了一个帖子
http://tech.slashdot.org/story/09/11/29/2133243/g-wan-another-free-web-server
有没有在生产中运行gwan的真实世界经验的人?任何最佳做法?
当我通过redis EVAL运行此代码时,它不会返回任何结果.知道为什么这不起作用吗?
redis-cli EVAL "$(cat bug.lua)" 0
Run Code Online (Sandbox Code Playgroud)
local retv = {}
retv["test"] = 1000
return retv
Run Code Online (Sandbox Code Playgroud)
如果我初始化表,那么单独打印值.
$ cat bug.lua
--!/usr/bin/env lua
local retv = {"This", "is", "a", "bug" }
retv["test"] = 1000
return retv
$ redis-cli EVAL "$(cat bug.lua)" 2 a b
1) "This"
2) "is"
3) "a"
4) "bug"
Run Code Online (Sandbox Code Playgroud) 这就是我在做的事情.当我这样做时,redis-py会爆炸.
Python 2.7.3 (default, Aug 1 2012, 05:16:07)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import redis
>>> p = redis.ConnectionPool()
>>> r = redis.Redis(connection_pool=p)
>>> p.release(r)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/redis/connection.py", line 355, in release
if connection.pid == self.pid:
AttributeError: 'Redis' object has no attribute 'pid'
>>>
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 opneSSL 编译示例应用程序,但无法让链接器进行合作。需要一双新的眼睛来看待这个可能很简单的问题。请帮忙。
我已尝试通读所有问题,但找不到问题所在。这是命令行和链接器输出
$ gcc -t -I/usr/include/openssl -L/usr/lib/x86_64-linux-gnu -o algotest -lcrypto -lssl3 -lssl algotest.c
/usr/bin/ld: mode elf_x86_64
/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crt1.o
/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crti.o
/usr/lib/gcc/x86_64-linux-gnu/4.6/crtbegin.o
-lcrypto (/usr/lib/x86_64-linux-gnu/libcrypto.so)
-lssl3 (/usr/lib/x86_64-linux-gnu/libssl3.so)
-lssl (/usr/lib/x86_64-linux-gnu/libssl.so)
/tmp/ccSLR6rb.o
-lgcc_s (/usr/lib/gcc/x86_64-linux-gnu/4.6/libgcc_s.so)
/lib/x86_64-linux-gnu/libc.so.6
(/usr/lib/x86_64-linux-gnu/libc_nonshared.a)elf-init.oS
/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2
-lgcc_s (/usr/lib/gcc/x86_64-linux-gnu/4.6/libgcc_s.so)
/usr/lib/gcc/x86_64-linux-gnu/4.6/crtend.o
/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crtn.o/tmp/ccSLR6rb.o: In function `main':
algotest.c:(.text+0x5c): undefined reference to `OpenSSL_add_all_digests'
algotest.c:(.text+0x99): undefined reference to `EVP_get_digestbyname'
algotest.c:(.text+0xdc): undefined reference to `EVP_MD_CTX_create'
algotest.c:(.text+0xfb): undefined reference to `EVP_DigestInit_ex'
algotest.c:(.text+0x13b): undefined reference to `EVP_DigestUpdate'
algotest.c:(.text+0x17b): undefined reference to `EVP_DigestUpdate'
algotest.c:(.text+0x192): undefined reference to `EVP_DigestFinal_ex'
algotest.c:(.text+0x19e): undefined reference to `EVP_MD_CTX_destroy' …Run Code Online (Sandbox Code Playgroud) 我正在尝试初始化并打印一个表.它只是不工作.知道这个代码有什么问题吗?
--!/usr/bin/env lua
local retv = {}
retv["test"] = 1000
for k,v in ipairs(retv) do
print (k,v)
end
Run Code Online (Sandbox Code Playgroud)
它什么都不打印.我确信我遗漏了一些非常基本的东西,但我无法弄清楚这一点.
我正在尝试对瓶子和瓶子进行基准测试以做出一些新的项目决定.我看到瓶子惨不忍睹,而烧瓶似乎有效.我无法相信这些框架相距甚远(是吗?!).我猜我做的事情既简单又错误.我完全搞不清楚为什么.
客户
第一步我尝试使用Wrk作为客户端来生成负载来进行基准测试.我的Wrk cmdline看起来像这样
./wrk -c 20 -d 30 -t 10 --latency http://localhost:8888/hello/world
Run Code Online (Sandbox Code Playgroud)
瓶子
Bottle示例服务器如下所示
#!/usr/bin/env python
from bottle import route, run, template
@route('/hello/<name>')
def index(name):
return template('<b>Hello {{name}}</b>!', name=name)
run(host='localhost', port=8888)
Run Code Online (Sandbox Code Playgroud)
基准的输出是
Running 30s test @ http://localhost:8888/hello/world
10 threads and 20 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 6.07s 4.44s 13.38s 55.49%
Req/Sec 184.27 311.26 1.33k 73.56%
Latency Distribution
50% 7.29s
75% 7.42s
90% 13.38s
99% 13.38s
34208 requests in 30.02s, 5.61MB read
Socket errors: …Run Code Online (Sandbox Code Playgroud)