Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

用客户端set的时候报错,telnet上去是正常的

72 views
Skip to first unread message

amyth0s

unread,
Feb 3, 2012, 11:02:58 AM2/3/12
to BeanDB
您好,我下载的0.5.3版,用客户端set值的时候报如下错,不知道是哪里没设置好麽?
$beansdb -p 7900 -H /beansdb/testdb -v
all ready.
Bug: conn 8 should not be NULL
Failed to write, and not due to blocking: Bad file descriptor

proxy启动如下:
$python proxy.py -l localhost -p 7321
server listening on localhost:7321

修改了proxy.py里面的main()函数里的cfg如下:
cfg = {"localhost:7900":range(16)}
store = Client(cfg, 16)

telnet上去却是正常的
$telnet localhost 7900
Trying ::1...
Connected to localhost.
Escape character is '^]'.
get @
VALUE @ 0 120
0/ 0 0
1/ 0 0
2/ 0 0
3/ 0 0
4/ 33827 3
5/ 0 0
6/ 23174 2
7/ 0 0
8/ 0 0
9/ 0 0
a/ 0 0
b/ 0 0
c/ 0 0
d/ 0 0
e/ 0 0
f/ 0 0

END
get @4
VALUE @4 0 46
hello 60024 1
helle 53485 2
avatar_01 16337 1

END
get avatar_01
VALUE avatar_01 0 16
avatar_body_text
END

然后再发第二次的时候proxy报如下错,连接断掉了
$python proxy.py -l localhost -p 7321
server listening on localhost:7321
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/eventlet/hubs/hub.py", line
336, in fire_timers
timer()
File "/Library/Python/2.7/site-packages/eventlet/hubs/timer.py",
line 56, in __call__
cb(*args, **kw)
File "/Library/Python/2.7/site-packages/eventlet/greenthread.py",
line 192, in main
result = function(*args, **kwargs)
File "proxy.py", line 153, in handler
if store.set(key, buf, flag, rev):
File "proxy.py", line 106, in set
for addr in self.get_hosts_by_key(key)]
File "proxy.py", line 97, in _set
line = reader.readline()
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/
lib/python2.7/socket.py", line 447, in readline
data = self._sock.recv(self._rbufsize)
error: [Errno 54] Connection reset by peer

Davies Liu

unread,
Feb 5, 2012, 8:50:17 PM2/5/12
to bea...@googlegroups.com
看起来你是在Mac系统中碰到问题吧,那个Python的异常看起来是连接意外关闭,
是不是有什么外部原因(比如防火墙)导致连接强制关闭?

能不能描述一个能复现这个问题的方法?包括所处的环境等。

2012/2/4 amyth0s <beyon...@gmail.com>:

--
- Davies

amyth0s

unread,
Feb 6, 2012, 10:53:35 AM2/6/12
to BeanDB
确实是mac,我吧mac的防火墙关掉,现在能发文本了,但是2M多的图片还是set失败,报了下面错误:

Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/eventlet/hubs/selects.py",
line 52, in wait
listeners.get(fileno, noop).cb(fileno)
File "/Library/Python/2.7/site-packages/eventlet/greenthread.py",
line 192, in main
result = function(*args, **kwargs)
File "proxy.py", line 153, in handler
if store.set(key, buf, flag, rev):
File "proxy.py", line 106, in set
for addr in self.get_hosts_by_key(key)]
File "proxy.py", line 94, in _set
writer.write(value)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/
lib/python2.7/socket.py", line 324, in write
self.flush()
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/
lib/python2.7/socket.py", line 303, in flush
self._sock.sendall(view[write_offset:write_offset+buffer_size])
error: [Errno 32] Broken pipe
Removing descriptor: 9


On Feb 6, 9:50 am, Davies Liu <davies....@gmail.com> wrote:
> 看起来你是在Mac系统中碰到问题吧,那个Python的异常看起来是连接意外关闭,
> 是不是有什么外部原因(比如防火墙)导致连接强制关闭?
>
> 能不能描述一个能复现这个问题的方法?包括所处的环境等。
>
> 2012/2/4 amyth0s <beyond.s...@gmail.com>:

Davies Liu

unread,
Feb 6, 2012, 11:00:21 AM2/6/12
to bea...@googlegroups.com
python 的 memcached 客户度有 1M 的大小限制,要改一下源代码。

2012/2/6 amyth0s <beyon...@gmail.com>:

--
- Davies

amyth0s

unread,
Feb 6, 2012, 11:12:41 AM2/6/12
to BeanDB
这是测试的客户端

from pylibmc.client import Client
from pylibmc.pools import ClientPool
#from core.database import BeansDB
import sys

class MC(object):
def __init__(self, mc_addrs, pool_size=16, binary=False):
mc = Client(mc_addrs, binary=binary)
self.mc_pool = ClientPool(mc, pool_size)

def get(self, key):
with self.mc_pool.reserve() as mc:
return mc.get(key)

def get_multi(self, keys):
with self.mc_pool.reserve() as mc:
return mc.get_multi(keys)

def set(self, key, data, rev=0):
with self.mc_pool.reserve() as mc:
return bool(mc.set(key, data, rev))

def delete(self, key):
with self.mc_pool.reserve() as mc:
return bool(mc.delete(key))

class BeansDB(object):

@staticmethod
def createDB():
if not hasattr(BeansDB, '_mdb'):
BeansDB._mdb = MC(['localhost:7321'])

@staticmethod
def mdb():
return BeansDB._mdb

if __name__ == '__main__':
BeansDB.createDB()
if sys.argv[1] == 'img':
f = open('/Users/amythos/Pictures/DSC_0655.JPG', 'r')
fimg = f.read()
BeansDB.mdb().set(sys.argv[2], fimg)
else:
BeansDB.mdb().set(sys.argv[1], sys.argv[2])

amyth0s

unread,
Feb 6, 2012, 10:25:51 PM2/6/12
to BeanDB
嗯,我晚上回去改一下试试,谢谢Davies大侠 :)

On Feb 7, 12:00 am, Davies Liu <davies....@gmail.com> wrote:
> python 的 memcached 客户度有 1M 的大小限制,要改一下源代码。
>
> 2012/2/6 amyth0s <beyond.s...@gmail.com>:
Reply all
Reply to author
Forward
0 new messages