Hello, folks<br>
<br>
I've been continuing to test memcached and trying to go about my
problem with overwritten/lost data in memcached without the use of a
database or some other solid data source. Yes I'm stubborn. Anyway.
I've written a script that shows, IMHO, that memcached doesn't utilize
memory efficiently, either due to it's queue and class slab allocation
algorithm, or some other unknown to me reason. See the PHP script
below. I've used Apache Bench with 50000 requests on a memcached with
1Gb maxbytes. The script outputs a CSV line for each data &quot;set&quot; in
memcached. It records time, current items, total items, the key, and
the data size that was stored for that key (the amount of data is
random for each key). For my run, I noticed that at about 15K items no
more bytes were &quot;used&quot;, meaning that no more memory was allocated and
no more items can be stored, the overwriting has begun. The problem is
that bytes kept staying at 560Mb which means it's using 56% of the
allowed memory. I've read about memory space inefficiency with the
classes and such, but 50%!!! Isn't it a bit low?!!! Can we address this
issue somehow, was there anything done besides the class reasignment
script in scripts, which I'm not sure how would solve this problem
anyway? <br>
Thanks,<br>
<br>
Denis<br>
<br>
&lt;snippet&gt;<br>
<br>
&lt;?php<br>
session_start();<br>
session_regenerate_id();<br>
$sess = session_id();<br>
ignore_user_abort(true);<br>
<br>
$data_file = &quot;data.csv&quot;;<br>
$fail_file = &quot;conn_fail.log&quot;;<br>
$flag = 'a';<br>
<br>
$memcache = new Memcache;<br>
if(!$memcache-&gt;connect('<a href="http://192.168.1.253">192.168.1.253</a>', 11213)){<br>
&nbsp;if(file_exists($fail_file)){<br>
&nbsp;&nbsp; $flag = 'a';<br>
&nbsp;} else {<br>
&nbsp;&nbsp; $flag = 'w';<br>
&nbsp;}<br>
&nbsp;&nbsp; $ffh = fopen($fail_file, $flag) or die (&quot;unable to open &quot;.$fail_file);<br>
&nbsp;&nbsp; while(1) {<br>
&nbsp;&nbsp;&nbsp;&nbsp; if (flock($ffh, LOCK_EX)) {<br>
&nbsp;&nbsp;&nbsp; &nbsp;fwrite($ffh, $sess.&quot;\n&quot;) or die (&quot;failed to write to &quot;.$fail_file);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; flock($ffh, LOCK_UN);&nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp; &nbsp;break;<br>
&nbsp;&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp; }<br>
&nbsp;fclose($ffh); <br>
<br>
} else {<br>
&nbsp; for($i=rand(1,13);$i&gt;0;$i--){ // 13 is no not go over the 1MB limit<br>
&nbsp;&nbsp;&nbsp; $sess.=$sess;<br>
&nbsp; }<br>
<br>
&nbsp; $size = strlen($sess)*2; // 2 bytes per character<br>
<br>
&nbsp; $stats = $memcache-&gt;getStats();<br>
&nbsp; reset($stats);<br>
<br>
&nbsp; if($memcache-&gt;set(session_id(), $sess, false, 0)){<br>
&nbsp;&nbsp;&nbsp; if(file_exists($fail_file)){<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $flag = 'a';<br>
&nbsp;&nbsp;&nbsp; } else {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $flag = 'w';<br>
&nbsp;&nbsp;&nbsp; }<br>
<br>
&nbsp;&nbsp;&nbsp; $dh = fopen($data_file,$flag) or die (&quot;unable to open &quot;.$data_file);<br>
&nbsp;&nbsp;&nbsp; while(1) {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (flock($dh, LOCK_EX)) {<br>
&nbsp;&nbsp;&nbsp; &nbsp;fwrite($dh,
$stats['time'].&quot;,&quot;.$stats['curr_items'].&quot;,&quot;.$stats['total_items'].&quot;,&quot;.$stats['bytes'].&quot;,&quot;.session_id().&quot;,&quot;.$size.&quot;\n&quot;)
<br>
&nbsp;&nbsp;&nbsp; &nbsp; or die (&quot;failed to write to &quot;.$data_file);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; flock($fdh, LOCK_UN);&nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp; &nbsp;break;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp; fclose($dh);<br>
&nbsp; }<br>
}<br>
<br>
?&gt;<br>
<br>
&lt;\snippet&gt;<br clear="all"><br>-- <br>&quot;To a person with a hammer, all problems look like nails&quot;<br>someone on Usenet