Professional Documents
Culture Documents
Cng ngh Memcached( c s dng rng ri trong cc d n cng ty) Redis(Phn I) K thut Open Authentication(Phn II) SSO(Single Sign On) Big4(Facebook, Yahoo, Twitter, Google)
I. Redis
Redis l mt cch lu tr d liu kiu key/value, n thc thi trn server ANSI C, redis cung cp nhiu cch lm vic khc nhau thc hin mt vic n gin : lu tr value(aaa) ti key(redis), trong vi cc keys ch h tr kiu string th vi values s h tr nhiu kiu nh dng khc nhau nh : Strings, Lists, Sets, Sortedsets(zsets), Hashes. V mi mt loi kiu nh dng khc nhau s c mt tp hp cc command lm vic vi n nh: Thm mi, loi b mt phn t trong values... khc nhau. C th xem Redis nh l mt cu trc d liu (data structures) cp cao trn my server, khi mt ngi dng redis ch cn cung cp mt interface Abstract Data Types(kiu d liu tru tng), t ngi dng khng phi chy cc data structures hay cc thut ton trn data structures m c th thc thi cc command ca data type . Redis is free software released under the very liberal BSD license. Written in C(C99 standard). Redis c nhng c im ging nh Memcached nh: Lu Key value (Key value store). Tt c data c lu trn Memory(RAM) Key c th ht hn(expire) hoc khng Nhanh(Fast), nh nhng(light-weight)
Nhng Redis c nhiu c im, chc nng khc mng li li ch khi s dng v trin khai. Bao gm: Persistence Multiple databases Queryable keyspace Support for interger counters Higher level data structures Atomic operations Ability to paginate lists without mutating them Master-slave replication Optional VM feature
Created an index on the key column of the table Each server had SET and GET requests as a different test at same concurrency
Team Ming
Team Ming
I.2. c im ca Redis
I.2.1. Persistence, higher level data structures
Redis ly v np d liu trn Memory(RAM), nhng ti mt thi im th d liu c th c lu tr trn disk(Data in memory, but saved on disk). C 2 kiu persistence c supported: Semi persistent mode (Snapshotting): Thi gian lu tr data trn Memory v Disk l khng ng b
Team Ming
Sau mi N s thay i hoc N thi gian no th data mi c lu tr trn disk. Do vic lu tr data l khng ng b nn data c th b mt khi server gp s c(restart or start) Fully persistent mode (Append Only File) Mi s thay i c vit thm vo mt tp tin. M hnh ny c gi l Append only file, mi command nhn s thay i th c vit thm vo file c nh dng l ASAP. Nhng command ny s c chy li khi server restart hoc start np li d liu ln memory.
LPUSH/PPUSH: Thm vo u/cui ca danh sch. LPOP/RPOP: Return v remove phn t u/cui ca danh sch. RPOPLPUSH: Return v remove phn t cui ca source list v y vo u ca destination list GETSET: Np mt key vi mt gi tr mi v tr v gi tr c. MGET/MSET: Ly/np nhiu key vi nhiu data. SMOVE: Chuyn mt value t one set to another. .. Rt nhiu tnh nng u vit v chuyn bit na c redis h tr.
I.2.4. Replication
Redis h tr m rng master-slave nu chng ta mun s an ton hoc m rng, co gin trong vic lu tr data. Slaves can be used for scalability or redundancy Mt master c th c nhiu slave Slaves c th nhn nhiu kt ni ca salve khc Slave c th kt ni li khi b outage
Team Ming
Redis v Memcache u c u nhc im ring, nhng nu kt hp c Redis v Memcache song hnh trong cng vic th l mt iu l tng.
43.12% <= 0 milliseconds 96.82% <= 1 milliseconds 98.62% <= 2 milliseconds 100.00% <= 3 milliseconds 81.234.77 requests per second
Team Ming
10
II.3.2 Lung s lc
SP v Consumer thng nht b consumer_key v consumer_secret 1. Consumer Service Provider Consumer s dng nh danh consumer gi yu cu ly request_token ti SP, bo mt phin lm vic bt u. SP kim tra nh danh consumer, tr li request_token ngu nhin (oauth_key, oauth_secret). 2. Consumer user Consumer chuyn ngi dng ti trang ng nhp ca SP 3. User - SP User ng nhp bng ti khon ca mnh SP vi thng bo cho php dch v consumer ly thng tin. Ngi dng tip theo s c chuyn v trang i sn ca consumer (callback) vi m oauth_verifier(SP sinh ngu nhin) chng nhn rng ngi dng (ng nhp v) ng chia s thng tin.
Team Ming
11
4. Consumer-SP Tip theo bc 3 th SP gi v cho consumer mt m gi l oauth_verifier thng bo cho Consumer bit l user ng nhp xong trn SP. Consumer gi yu cu ly access_token, s dng cc nh danh consumer, request_token v oauth_verifier chng thc. Lc ny, consumer s phi gi li oauth_verifier thng bo cho SP l consumer nhn c thng bo user ng nhp trn SP. SP kim tra, tr v cho consumer access_token c sn trong h thng hoc to mi. 5. Consumer-SP Vi cc api SP cung cp, consumer s dng b thng tin nh danh consumer (key v secret) v access_token gi yu cu ti SP ly thng tin ngi dung cn thit. Di y l hnh v m t lung OAuth trn:
Team Ming
12
13
ln, th vin c# thiu nhng param nh ngha thm Vn gy nhiu li nht trong qu trnh thc hin OAuth.
One of the most frustrating things about working with OAuth is getting back an error that the signature is invalid (http://support.mashery.com/docs/tips_and_tricks/OAuth) The signature base string is often the most difficult part of OAuth for newcomers to construct. (http://dev.twitter.com/pages/auth)
Team Ming