Upload
walter-traspadini
View
617
Download
5
Embed Size (px)
DESCRIPTION
How to implement a session control system scalable and reliable with an open source stack.
Citation preview
SimultaneousAccess Control
with a full open source stack
Walter Traspadini @uollter
non conventional architecture (?)
why redis ?
why flask ?
Redis.io
Salvatore Sanfilippo@antirez
Sponsored by
Open Source
key-value store
no-sql ?((made in italy)
Who is using Redis
Redis.io
keys can expire
master-slave
in memory dataset persistence
Data Structure
- String
- Integer (mainly for counting)
- List
- Set
- Ordered set
- Hash stored list
Don't do this !!
rs = redis.Redis()
rs.keys('*')- time complexity O(n)- 10^6 keys database in 40 msec.
- IT MAY RUIN PERFORMANCES
Best practicesSADD SERVICES [QOL, S24, PROF]
HSET SERVICE:QOL expire 60HSET SERVICE:QOL max_count 1HSET SERVICE:QOL:bob max_count 3
ZADD ACTIVITY:QOL:bob:20121010 '14:50 Login' 1450ZADD ACTIVITY:QOL:bob:20121010 '15:15 Logout' 1515
ZRANGE ACTIVITY:QOL:bob:20121010 1200, 1600 O(log(N) + M) (N: # of elements in the sorted set. M: # of element returned)
list
objects
scores
Flask
> micro-framework for python
> builtin server
> RESTful request dispatching
> WSGI compliant
> integrated support for unit testing
...... easy .....
code [email protected]('/logout/<username>/<service>/<label>' , methods=['GET'])@jsonp.jsonpdef logout(username, service, label, device_type=None): user.sessions = g.r_server.get('USER:%s:%s:%s' %(username, service, label))) if user.sessions and int(user.sessions) > 0: g.r_server.delete(user.key()) return jsonify({'user': user.to_json(), 'error': messages.OK_NO_ERROR}) return jsonify({'error': messages.NOT_LOGGEDIN_ERROR, 'user': user.to_json()})
..... siac .... api .....
/chack_access/EntroBol04/QOL/<fingerprint>
MMMD5 ( browser capabilities + browser plugins )
cf4ceeb4398b80132eeceadea0a2f9ee
/logout/EntroBol04/QOL/<fingerprint>
headache
> does redis scale ?
> which is the failover policy ?
> what about clustering ?
my early prototype .......
SIAC
REDISMASTER
REDISSLAVE
spreecast http://www.spreecast.com/
Apache ZooKeeper
Centralized service for maintaining:configuration information, naming, distributed synchronization
.. the final solution .. <3 production
Redis
Redis Redis
SIAC SIAC
ZooKeeperCluster Monitor
Monitor
Redis Redis
redis_failover ... for python ...
https://github.com/uolter/redis_failover
....share the code Luke ....
continuous integration as a service
want to learn more ....
> Redis: http://redis.io> Video redis: http://vimeo.com/21539227> Flask: http://flask.pocoo.org> Spreecast & Redis Failover: http://engineering.speecast.com/spreecast-redis-failover> ZooKeeper: http://zookeeper.apache.org
Walter Traspadini http://bit.ly/uolter @uollter