[TYPO3-dev] Idea: use shared memory as cache

Dmitry Dulepov [typo3] dmitry at typo3.org
Wed Sep 12 10:35:41 CEST 2007


Martin Kutschker wrote:
> The Core reads some small values like configured domains from the DB 
> (sys_domain) and from the disk. This values could be put in a cache. I 
> think that a file cache with serialized data will improve things, but 
> why not go further and use the memory for it?
> 
> So I propose to create a caching system that is based on the shmop_* 
> functions ("Shared Memory Functions").
> 
> Note that these functions need a locking mechanism to avoid concrrent 
> writes. A logical approach would be to use the sem_* functions 
> ("Semaphore, Shared Memory and IPC Functions") but these are not 
> available on Windows. So we need either a fallback to eg file based 
> locking. I think that it's safe to use the very first byte of the shared 
> memory segment as a semaphore. Writing only one byte should be atomic.
> 
> Comments?

Well, you still can have thread concurency there. Two threads may read 
first byte, see it as zero, think they can set it to 1 now, set and 
corrupt the rest because they think they own memory now. This is a 
typical scenario on Win32.

Actually, it is very strange that PHP do not release semaphores on 
Windows. It is very easy to implement them in Win32. I remember I even 
made once a PHP extension to enable these functions on Windows... But 
that was years ago and I have no sources any more.

-- 
Dmitry Dulepov
TYPO3 freelancer / TYPO3 core team member
Web: http://typo3bloke.net/
Skype: callto:liels_bugs




More information about the TYPO3-dev mailing list