tags:

views:

353

answers:

2

Hello, I want to store information (sessions and a lot of strings) in RAM and I don't know if I should use a tmpfs or a memcached server. Someone did some benchmark and knows which one is faster? It's needed for some ajax scripts that requests informations every 1-5 seconds per user who is logged in, like a webchat in PHP. So PHP has to connect to memcache quite often.

The advantage of using tmpfs whould be that I can create a lot of files and have a structur (dirs), while I only have a key-value system in memcached, but there i could use arrays or objects to store information. CPU load whould be interesting, too, if there is any difference.

Thanks.

A: 

I don't really know about speed, but here are a couple of things to consider about memcached :

  • memcached is based on a cluster-type architecture : you can add as many physical servers as you want, install a memcached daemon on it, and you have more memory in your cluster
    • which means there is virtually no limit to the amount of data you can cache, using memcached : just add a couple of servers if you need more memory
    • on the other hand, with tmpfs, you're limited by the amount of RAM available on each server
  • memcached is a caching mecanism ; it's not made to store data ; which means :
    • when there is not enough memory left to store a new item, the old items are removed from the cache
    • each item has a lifetime ; when it's expired, the item is deleted from the cache
  • memcached is shared : you can have several PHP servers accessing a single memcached cluster
  • There are many existing libraries based on memcached, or created to access memcached
    • including some session mecanism for PHP
    • and several caching libraries
  • neither memcached nor tmpfs are made for persistence -- if you need your data to persist (i.e. still be available even after a reboot), you need to use something like a database.


In the end, not sure about tmpfs, but I would probably use memcached, at least when it comes to :

  • sessions
  • caching

Why ? Because it's :

  • mature -- used a lot, there are many libraries, ...
  • and scalable
Pascal MARTIN
Thanks for your answer. I'm using a MySQL database to store user information and need memcached or tmpfs for (temp) storing chat msgs, because I don't want to run a db query every ajax request ;).I'm not sure on how I should store this in memcache. The chat has multiple rooms and users should only see msgs they are supposed to see. I could use multiple key-value pairs.I think memcache is better for my project :).
D.Unknown
Humph ; not sure a non-persistent mecanism is the best choice, in this situation : if you want to keep an history of conversation, for instance, using a DB would be much better ;;; about *"not hitting the DB for each Ajax request"*, the chat idea, and Ajax request : you should search for "comet" : basically, it's a way of not having clients send frequent Ajax requests to the server, but have the server push updates to the clients *(there's been many questions about comet on stackoverflow ; maybe some might help ;-) )*.
Pascal MARTIN
I know comet, but don't know if it would help here. The script would still have to query db / memcache for new messages, since php instances can't communicate. I also tried to write an own web server to solve this (http://stackoverflow.com/questions/2357596/http-stream-server-threads ) but I'm not good enough in C#/C++ to do this.
D.Unknown
A: 

Actually you can use memcacheDB for what you need.

SoniX