views:

166

answers:

4

Which would be the best way to achieve a fast hash / session storage with one of these three ways?

Way 1: Create a memory table in MySQL that stores a hash and a timestamp when the entry was created. A MySQL event automatically deletes all entries older than 20 minutes. This should be pretty fast because all data is stored in memory, but the overhead of connecting to the database server might destroy this benefit.

Way 2: I create an empty file with the hash as its filename and create a cronjob that automatically deletes all files older than 20 minutes. This can become slow because of all the read operations on the HDD.

Way 3: Since this is going to be PHP related and we use the Zend Framework I could use the Zend_Cache and store the hash with a time-to-live of 20 minutes.

I don't want to use Memcached or APC for this, because I think that is a big overhead for just some small hashes.

Do you have any experience with similar scenarios? I would appreciate your experience and solutions for this.

A: 

Don't reinvent the wheel - use memcache. Either that, or measure your MySQL performance vs. Memcache. Remember that db access is usually always a bottleneck in high-perf environments anyway.

Chris Kaminski
+1  A: 

If performance is an issue i would defenately go with memcached. All big internet sites rely on memcached for either caching otherwise server intensive tasks or even session storage and locking mechanisms.

Memcached is the way to go if you ask me

ChrisR
I don't use Memcached though. I decided for APC because it is that much data.
Sebastian Hoitz
A: 

Do you consider also scaling issues with all these approaches? How many hashes do you talk about? How many megabytes of data you talk about?

  1. Hold it in memory of your computer if you can (your variant 3)
  2. Put it on the disk, but hold it in memory if you can (your variant 2, if you use file-based sessions, you can use $session as someone pointed out)
  3. Use database

Do you have a lot of data? Use memcached.

Jiri
A: 

As others have said, use memcached. If PHP supported database connection pools, like Java for instance, I would recommend MySQL, but PHP being what it is, memcached is the only real answer.

Fred Garvin