Featured post
mysql - What's the most scalable way to track user activity? -
i track user activity , limit activity using time constraint. example of votes per day limit enforced so. of following methods provides better solution in terms of scalability , ease of use?
- store activity info in database
- store activity info in application scope
- use entirely different method track information
method 1:
- advantages: data integrity, not important in use case.
- disadvantages: requires database interaction, stores redundant data, requires scheduled event reset values being tracked
method 2
- advantages: not require database interaction, appears easier
- disadvantages: i'm unsure of implications on application memory given large user-base track, or how easy find , manipulate struct data hundreds of keys
i'm using coldfusion mysql, if matters.
assuming care data on per-person basis, , won't getting aggregates of this, i'd suggest go key/val store supports ttl. redis sounds fits requirements pretty well.
though runs in memory, snapshot disk periodically (which mean it's fast, , if goes down, you'll back).
easy interaction, "method 2", without having worry managing large in-memory structure.
example setup
going points-per-day scenario, we'll have time-frame of 1 day, , our value simple value increments on user activity.
our key combination of user's id , current timeframe (day, in case). after have set key, set ttl, means after today up, key expire , clean up.
redis> incr user123-2011-10-09 (integer) 1 # no value found key, defaulting 1 # if key had value incremented. redis> expire user123-2011-10-09 86400 (integer) 1 # expiration of 1 day successful redis> user123-2011-10-09 "1" # current value of user key
more info on these commands (incr, get, expire, , ttl of interest you) can found on redis commands reference (complete interactive shell try these things out).
edit
this method applied number of k/v stores, i've used redis here concrete example since believe meets requirements closely.
- Get link
- X
- Other Apps
Comments
Post a Comment