php - How can I improve the performance of my social networking site using memcached? -


I would like to apply memcached to my social network site. When you have a social network, most data will change a lot.

For example, if I had to store 10,000 friends of a user in the cache, at any time he would add a friend, it would be easy to update the cache, but at any time Someone else will need to be added as a friend. This alone has a lot to update on the Buddy List.

There are also user blogs and bulletins that are posted non-stop with new people and you can see only those people that you have created by user friend list, so I think That it would be very difficult to cache.

I can probably cache some profile information which only when the user updates his profile, but it will create a cache record for each user, if there are more than 100,000 users who are very caching Is this a good idea?

I would say that it is a good idea to cache where possible ... .. most of the time You will be able to draw items faster than conventional RDBMS with memcached (especially if you have complex complications and such). I currently use such a strategy with great success, and here it is that I have learned from experience:

  1. If possible, the cash indefinitely Until, and when any changes are made, type a new value. Do not try to remove a clear, because you can cause a running position with more than one concurrent access to the data to update the cache. This also applies by locking if an item is not present in the cache to prevent the above problem (Maccapped "add" + a while in the loop)

  2. In the background Refresh the cache if possible, using the queue. My implementation currently uses multi-threaded pearl processes running in the background + beanstock, thus preventing interval time on the frontend.

  3. If possible, use the memcad millelty, actually add many different memcatch calls.

  4. Stair your cache, when checking an item, first check a local array, then a memkatch, then a script for the same item is db Cache result in local array after first access to prevent memcached kill in execution several times. EDIT: To clarify, if a script language is to be used, such as PHP, then the local array can only exist for existing script execution Example:

      class itemcache {personal $ Cached_items = array (); Private $ memcachedobj; Public function getitem ($ memcache_key) {if (isset ($ this-> cached_items [$ memcache_key])) {return $ this- & gt; Cached_items [$ memcache_key]; } Otherwise ($ result = $ this-> get memcadb-> get ($ memcache_key)) {$ this-> Cached_items [$ memcache_key] = $ results; Return result; } Else {// db query here $ dbresult $ - as-> memcachedobj-> Set ($ memcache_key, $ dbresult, 0); $ This- & gt; Cached_items [$ memcache_key] = $ dbresult; Return $ dbresult; }}  
  5. Write wrapper function to implement upper caching strategy # 4.

  6. Use a compatible key structure in Memcached, such as. 'Userinfo_ {user.pk}' where user.pk is the user's primary key in rdbms.

  7. If your data requires post processing, then it will save some cycles on every hit of that data by placing it in the cache before processing where possible.


Comments

Popular posts from this blog

c# - ListView onScroll event -

PHP - get image from byte array -

Linux Terminal Problem with Non-Canonical Terminal I/O app -