Skip to content

Instantly share code, notes, and snippets.

@MOON-CLJ
MOON-CLJ / add_loggging.md
Last active February 2, 2018 04:44
libmc discuss:use plog

希望发起对douban/libmc#75 的讨论,pr内容可以先不看,我下面会简单介绍。

需求

1,首先引入对multi thread logging 的支持。对于dae-go这种有自己的pool实现,里面放了golibmc的Client。这样一来 多个goruntine可能会拿多个Client同时操作。需要有线程唯一的mutex来保证log不会串。同理对于python多线程程序(或gevent)来讲 如果要用libmc也会面临类似问题。引入plog能够解决这一点。

https://github.com/SergiusTheBest/plog/blob/master/include/plog/Appenders/ConsoleAppender.h#L28

@MOON-CLJ
MOON-CLJ / libmc_discuss_recv_error.md
Last active February 6, 2018 13:55
libmc discuss: 内部项目遇到的大量的recv error

现象:

dae-go的一个项目elves,通过elves的sentry发现,通常(最近观察到的都是)在AM 1:00 到AM: 9:00 会出现大量的recv error,elves的开发者一直在追问是什么情况。

elves的用法如下

	begin := time.Now()
	if rated, err = mc.IncrUint64(key, 1); err != nil && err.Error() == LIBMC_CACHE_MISS_ERROR {
		rated = 1
chenlijun@redis00 /tmp/test_warn $ python tmp.py
see each key the first time
File "tmp.py", line 5, in <module>
func1("aaa")
File "/tmp/test_warn/app_code.py", line 5, in func1
get1(val)
File "/tmp/test_warn/fake_libmc.py", line 14, in get1
warnings.warn(val)
File "/tmp/test_warn/fake_libmc.py", line 7, in warn_with_traceback
traceback.print_stack(file=log)
@MOON-CLJ
MOON-CLJ / tmux-cheatsheet.markdown
Created January 23, 2017 03:58 — forked from MohamedAlaa/tmux-cheatsheet.markdown
tmux shortcuts & cheatsheet

tmux shortcuts & cheatsheet

start new:

tmux

start new with session name:

tmux new -s myname
@MOON-CLJ
MOON-CLJ / gist:7905654
Created December 11, 2013 05:51
8块硬盘同时读取,本地访问
125046514 function calls in 233.965 seconds
Ordered by: standard name
ncalls tottime percall cumtime percall filename:lineno(function)
1214379 6.203 0.000 9.627 0.000 __init__.py:6368(__init__)
1214379 2.753 0.000 8.325 0.000 __init__.py:6379(_get_document)
@MOON-CLJ
MOON-CLJ / search_3_4.diff
Last active December 29, 2015 12:49
本地database直接访问 有cache和没cache(100万,大于10s的差异才被保留)
- 141990135 function calls in 4517.825 seconds
+ 141990135 function calls in 305.731 seconds
- 15732127 35.384 0.000 41.229 0.000 __init__.py:6549(__init__)
+ 15732127 27.876 0.000 32.483 0.000 __init__.py:6549(__init__)
class TermListItem(object):
def __init__(self, iter, term):
self._iter = iter
self.term = term
self._wdf = None
@MOON-CLJ
MOON-CLJ / iter_all_docs_1_3.diff
Last active December 28, 2015 21:29
本地database直接访问vs本地database tcp访问
--- 1.txt 2013-11-20 21:24:35.000000000 +0800
+++ 3.txt 2013-11-20 21:24:35.000000000 +0800
@@ -1,4 +1,4 @@
- 309378992 function calls in 596.173 seconds
+ 309378996 function calls in 9818.898 seconds
Ordered by: standard name
@@ -33,7 +33,7 @@
1 0.000 0.000 0.000 0.000 __init__.py:2732(ExpandDecider)
@MOON-CLJ
MOON-CLJ / iter_all_docs_1_2.diff
Last active December 28, 2015 21:29
无cache与有cache 区别不大
--- 1.txt 2013-11-20 21:24:35.000000000 +0800
+++ 2.txt 2013-11-20 21:24:35.000000000 +0800
@@ -1,4 +1,4 @@
- 309378992 function calls in 596.173 seconds
+ 309378992 function calls in 592.411 seconds
Ordered by: standard name
@@ -89,13 +89,13 @@
1 0.000 0.000 0.000 0.000 __init__.py:705(NetworkError)
@MOON-CLJ
MOON-CLJ / gist:6028017
Last active December 19, 2015 22:29
python Lookup instance attribute
In [88]: class C:
....: def foo(self):
....: pass
....: foo = classmethod(foo)
....:
In [89]: C.__dict__
Out[89]:
{'__doc__': None,
'__module__': '__main__',
@MOON-CLJ
MOON-CLJ / gist:6019306
Last active December 19, 2015 21:19
name mangling in python
In [29]: class foo():
....: def __init__(self):
....: self.__x = 1
....:
In [30]: r1 = foo()
In [31]: r1.__x
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)