note 61242 added to ref.shmop

From: Date: Sun, 29 Jan 2006 05:58:51 +0000
Subject: note 61242 added to ref.shmop
Groups: php.notes 
Request: Send a blank email to php-notes+get-102652@lists.php.net to get a copy of this message
I have written a script to highlight the superiority of shared memory storage. Although it doesn't use the shmop function, the underlying concept is similar. '/shm_dir/' is a tmpfs directory, which is based on shared memory, that I have mounted on the server. Below is the result on an Intel Pentium VI 2.8 server: IO test on 1000 files IO Result of Regular Directory : 0.079015016555786 IO Result of Shared Memory Directory : 0.047761917114258 IO test on 10000 files IO Result of Regular Directory : 3.7090260982513 IO Result of Shared Memory Directory : 0.46256303787231 IO test on 40000 files IO Result of Regular Directory : 117.35703110695 seconds IO Result of Shared Memory Directory : 2.6221358776093 seconds The difference is not very apparent nor convincing at 100 files. But when we step it up a level to 10000 and 40000 files, it becomes pretty obvious that Shared Memory is a better contender. Script courtesy of http://www.enhost.com <? set_time_limit(0); // Your regular directory. Make sure it is write enabled $setting['regular_dir'] = '/home/user/regular_directory/'; // Your shared memory directory. $setting['shm_dir'] = '/shm_dir/'; // Number of files to read and write $setting['files'] = 40000; function IO_Test($mode) { $starttime = time()+microtime(); global $setting; for($i = 0 ; $i< $setting['files'] ;$i++) { $filename = $setting[$mode].'test'.$i.'.txt'; $content = "Just a random content"; // Just some error detection if (!$handle = fopen($filename, 'w+')) { echo "Can't open the file ".$filename; exit; } if (fwrite($handle, $content ) === FALSE) { echo "Can't write to file : ".$filename; exit; } fclose($handle); // Read Test file_get_contents($filename); } $endtime = time()+microtime(); $totaltime = ($endtime - $starttime); return $totaltime; } echo '<b>IO test on '.$setting['files']. ' files</b><br>'; echo 'IO Result of <b>Regular</b> Directory : '.IO_Test('regular_dir') .' seconds<br>'; echo 'IO Result of <b>Shared Memory</b> Directory : '.IO_Test('shm_dir') .' seconds<br>'; /* Removal of files to avoid underestimation # # Failure to remove files will result in inaccurate benchmark # as it will result in the IO_Test function not re-creating the existing files */ foreach ( glob($setting['regular_dir']."*.txt") as $filename) { unlink($filename);$cnt ++; } foreach ( glob($setting['shm_dir']."*.txt") as $filename) { unlink($filename);$cnt ++; } ?> ---- Server IP: 216.194.113.175 Probable Submitter: 64.203.7.207 ---- Manual Page -- http://www.php.net/manual/en/ref.shmop.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+61242 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+61242&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+61242&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+61242&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+61242&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+61242&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+61242&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+61242&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+61242&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#102652) next »