Caching data and writing to a memory table

What would be the best way to quickly store the hash / session in one of these three ways?

Method 1: Create a memory table in MySQL that stores the hash and timestamp when the record was created. The MySQL event automatically deletes all records older than 20 minutes. This should be pretty fast, because all the data is stored in memory, but the overhead of connecting to the database server can ruin this advantage.

Method 2: I create an empty file with a hash as its name and create a cronjob that automatically deletes all files older than 20 minutes. This can become slow due to all read operations on the hard disk.

Method 3: Since it will be related to PHP, and we use the Zend Framework, I could use Zend_Cache and store the hash with a lifetime of 20 minutes.

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

Do you have experience in such scenarios? I would appreciate your experience and solutions for this.

+4
source share
4 answers

If performance is a problem, I would do without memcached. All major Internet sites rely on memcached for caching, otherwise, for server tasks or even for storing and blocking a session.

Memcached is the way to go if you ask me

+1
source

Do not reinvent the wheel - use memcache. Either this, or measure the performance of MySQL compared to Memcache. Remember that db access is usually always a bottleneck in high-performance environments.

0
source

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

  • Keep it in your computer if you can (your option 3)
  • Put it on the disk, but keep it in memory if you can (your option 2, if you use file-based sessions, you can use $ session, as someone pointed out)
  • Use database

Do you have a lot of data? Use memcached.

0
source

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

0
source

All Articles