8000 use libmc instead of memcached · lcppcl/code@f4a10b9 · GitHub
[go: up one dir, main page]

Skip to content

Commit f4a10b9

Browse files
committed
use libmc instead of memcached
1 parent ed23b4a commit f4a10b9

12 files changed

+37
-58
lines changed

Dockerfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ RUN echo "deb-src http://mirrors.aliyun.com/ubuntu/ trusty-backports main restri
1717
RUN apt-get update
1818

1919
RUN apt-get install curl python -yq
20-
RUN curl -O https://raw.githubusercontent.com/dongweiming/code/master/scripts/install_code.sh
20+
RUN curl -O https://raw.githubusercontent.com/douban/code/master/scripts/install_code.sh
2121
RUN /bin/bash install_code.sh
2222
RUN rm -rf install_code.sh
23+
EXPOSE 8000
24+
WORKDIR /code

README.md

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Douban CODE
88

99
Dependency
1010
----------
11-
- libmemcached <http://douban-code.github.io/pages/python-libmemcached.html>
11+
- libmc <https://github.com/douban/libmc>
1212
- Python 2.7+
1313
- pip >= 1.4.1
1414

@@ -18,20 +18,25 @@ Docker Installation
1818
You can use [code](https://registry.hub.docker.com/u/dongweiming/code/)
1919

2020
```
21-
docker pull dongweiming/code
21+
$docker pull dongweiming/code
2222
```
2323

2424
or just build locally(recommended):
2525

2626
```
27-
cd code
28-
docker build -t code .
27+
$cd code
28+
$docker build -t code .
2929
```
3030

3131
And launch a bash shell inside the container:
3232

3333
```
34-
docker run -t -i code /bin/bash
34+
$docker run -d -p 8080:8000 code gunicorn -w 2 -b 0.0.0.0:8000 app:app # start app
35+
5cf0d1f6a421c53d54662df77dd142978d24b8c76fd72ce1c106506458e1304a
36+
$boot2docker ip
37+
192.168.59.103
38+
# go web http://192.168.59.103:8080
39+
$docker run -t -i code /bin/bash
3540
```
3641

3742
Quick Installation
@@ -84,7 +89,7 @@ mysql -uroot -D valentine < vilya/databases/schema.sql
8489
virtualenv venv
8590
. venv/bin/activate
8691
pip install cython # should install first
87-
pip install -U setuptools # python-libmemcached require updated setuptools
92+
pip install -U setuptools
8893
pip install -r requirements.txt
8994
gunicorn -w 2 -b 127.0.0.1:8000 app:app # web & git http daemon
9095
```

requirements.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@ redis==2.8.0
77
wsgiauth==0.1
88
pytz==2013.8
99
Werkzeug==0.9.4
10+
-e git+https://github.com/qingfeng/misaka@2fbe52692e8f304eea9d8925fd2a857916ff0ea5#egg=misaka
1011
mikoto==0.0.4
1112
-e git+https://github.com/douban/douban-utils.git@5ca697545da191dab3fbe308e6b6776d8da83bd5#egg=DoubanUtils
1213
-e git+https://github.com/douban/douban-sqlstore.git@d7136b7cac1075f0b285e8c763af2e85124f8b76#egg=DoubanSQLStore
13-
-e git+https://github.com/douban/douban-mc.git@f594ab28af464f25a54263d1cc312e895e65b1f4#egg=DoubanMC
14+
-e git+https://github.com/dongweiming/douban-mc.git@5a0a21cdb73a448eb09a1b657ad80d4941ddb404#egg=DoubanMC
1415
-e git+https://github.com/douban/douban-orz.git@208b48177dc847ef2afdadfda302868c39797bdf#egg=ORZ
1516
-e git+https://github.com/douban/douban-quixote.git@72fd1b6f1224519709df2c031afc4bd9dbe611e4#egg=Quixote
1617
-e git+https://github.com/douban/pygit2.git@c7b13237e9934b5620cf0c351ae7eaea7d14ffc3#egg=pygit2
1718
-e git+https://github.com/douban/ellen.git@e092eddd933a4676c53f016d11782897807f873a#egg=ellen
18-
-e git+https://github.com/douban/python-libmemcached.git@71fb66d473bbab82c2b6ddb410a386dd84417fa3#egg=python_libmemcached
19+
-e git+https://github.com/douban/libmc.git@06b27e8bf2ae7f75d9817ba917f705c471e45028#egg=libmc

scripts/archlinux.sh

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#!/usr/bin/env bash
1+
#!/usr/bin/env bash
22

3-
#Get generic function
3+
#Get generic function
44
. common.sh
55

66
echo "Install needed package.This may take some time..."
@@ -14,9 +14,6 @@ echo "Setup memcached port to 11311..."
1414
sudo sed -i "s/memcached -l/memcached -p 11311 -l/" /usr/lib/systemd/system/memcached.service
1515
sudo systemctl start memcached
1616

17-
echo "Install libmemcached..."
18-
install_libmemcached
19-
2017
# Use virtualenv2
2118
sudo mv /usr/bin/virtualenv /usr/bin/virtualenv.bak
2219
sudo ln -s /usr/bin/virtualenv2 /usr/bin/virtualenv

scripts/centos.sh

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@ echo "Setup memcached port to 11311..."
1414
sudo sed -i "s/PORT=11211/PORT=11311/" /etc/init.d/memcached
1515
sudo /etc/init.d/memcached start
1616

17-
echo "Install libmemcached..."
18-
install_libmemcached
19-
2017
echo "Install code..."
2118
install_code
2219

scripts/common.sh

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,6 @@ modify_sudo_time() {
33
sudo sed -i 's/env_reset/env_reset, timestamp_timeout=240/g' /etc/sudoers
44
}
55

6-
install_libmemcached() {
7-
#check libmemcached has installed
8-
if [ ! -f /usr/local/bin/memping ] ; then
9-
curl -L https://github.com/xtao/douban-patched/raw/master/libmemcached-douban-1.0.18.tar.gz |tar zx
10-
cd libmemcached-1.0.18
11-
./configure && make && sudo make install
12-
cd ..
13-
rm -rf libmemcached-1.0.18
14-
echo "/usr/local/lib" | sudo tee -a /etc/ld.so.conf
15-
sudo /sbin/ldconfig
16-
fi
17-
}
18-
196
check_virtualenv() {
207
which virtualenv > /dev/null 2>&1
218
if [ $? != 0 ];then
@@ -34,7 +21,7 @@ setup_database() {
3421
read -p "Please input Mysql ${user}'s password(default is ''):" passwd
3522
echo "drop database if exists valentine" | mysql --user=${user} --password=${passwd}
3623
echo "create database valentine" | mysql --user=${user} --password=${passwd}
37-
if [b $? -ne 0 ]; then
24+
if [ $? -ne 0 ]; then
3825
exit 1
3926
fi
4027
(echo "use valentine"; cat vilya/databases/schema.sql) | mysql --user=${user} --password=${passwd}
@@ -47,10 +34,10 @@ install_code() {
4734
setup_database
4835
test "$CODE_ENV" != "unset" && check_virtualenv
4936
pip install cython # should install first
50-
pip install -U setuptools # python-libmemcached require updated setuptools
37+
pip install -U setuptools
5138
pip install -r requirements.txt
5239
}
5340

5441
start_app() {
55-
gunicorn -w 2 -b 127.0.0.1:8000 app:app # web & git http daemon
42+
test "$CODE_ENV" != "unset" && gunicorn -w 2 -b 127.0.0.1:8000 app:app # web & git http daemon
5643
}

scripts/fedora.sh

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@ echo "Setup memcached port to 11311..."
1515
sudo sed -i "s/PORT=11211/PORT=11311/" /etc/sysconfig/memcached
1616
sudo service memcached restart
1717

18-
echo "Install libmemcached..."
19-
install_libmemcached
20-
2118
echo "Install code..."
2219
install_code
2320

scripts/gentoo.sh

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,6 @@ sudo sed -i 's/PORT=\"11211\"/PORT=\"11311\"/g' /etc/conf.d/memcached
3030
sudo /etc/init.d/memcached restart
3131
$end
3232

33-
$echo "Install libmemcached..."
34-
install_libmemcached
35-
$end
36-
3733
$echo "Install code..."
3834
install_code
3935
$end

scripts/opensuse.sh

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@ echo "Setup memcached port to 11311..."
1515
sudo sed -i 's/MEMCACHED_PARAMS=\"/MEMCACHED_PARAMS=\"-p 11311 /' /etc/sysconfig/memcached
1616
sudo /etc/init.d/memcached restart
1717

18-
echo "Install libmemcached..."
19-
install_libmemcached
20-
2118
echo "Install code..."
2219
install_code
2320

scripts/ubuntu.sh

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@ echo "Setup memcached port to 11311..."
1414
sudo sed -i "s/11211/11311/g" /etc/memcached.conf
1515
sudo /etc/init.d/memcached restart
1616

17-
echo "Install libmemcached..."
18-
install_libmemcached
19-
2017
echo "Install code..."
2118
install_code
2219

vilya/config.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import os
44
from os.path import dirname, abspath
55

6+
from libmc import MC_HASH_MD5
7+
68
DEVELOP_MODE = False
79

810

@@ -20,14 +22,14 @@
2022
SESSION_COOKIE_NAME = 'code_user'
2123

2224

23-
MEMCACHED = {
24-
'servers': ["127.0.0.1:11311", ],
25-
'new_servers': [],
26-
'backup_servers': [],
27-
'disabled': False,
28-
'local_cache': True,
29-
'log_every_actions': False,
30-
'slave_servers': [],
25+
MEMCACHED_HOSTS = ['127.0.0.1:11311']
26+
MEMCACHED_CONFIG = {
27+
'do_split': True,
28+
'comp_threshold': 0,
29+
'noreply': False,
30+
'prefix': None,
31+
'hash_fn': MC_HASH_MD5,
32+
'failover': False
3133
}
3234

3335
DOUBANDB = {

vilya/libs/store.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
# -*- coding: utf-8 -*-
22

33
import logging
4+
5+
import libmc
46
CABA from MySQLdb import IntegrityError, connect
57
from ORZ import OrzField, OrzBase, setup
6-
from douban.mc import mc_from_config, create_decorators
8+
from douban.mc import create_decorators
79
from douban.sqlstore import store_from_config
8-
from vilya.config import MEMCACHED, MYSQL_STORE
10+
from vilya.config import MEMCACHED_HOSTS, MEMCACHED_CONFIG, MYSQL_STORE
911

1012
logging.getLogger().setLevel(logging.DEBUG)
1113

@@ -21,7 +23,7 @@
2123

2224

2325
def get_mc():
24-
return mc_from_config(MEMCACHED, use_cache=False)
26+
return libmc.Client(MEMCACHED_HOSTS, **MEMCACHED_CONFIG)
2527

2628

2729
def stub_cache(*args, **kws):
@@ -31,7 +33,6 @@ def stub_cache(*args, **kws):
3133
pcache = pcache2 = listcache = cache_in_obj = delete_cache = cache = stub_cache
3234
globals().update(create_decorators(mc))
3335

34-
3536
def mc_gets(mc_key, getter, ids):
3637
'''helpler for gets function'''
3738
results = mc.get_multi([mc_key % i for i in ids])

0 commit comments

Comments
 (0)
0