Memory to good use

At my office, Everyone runs a PC with pleanty of RAM, and  uses less than 2GBs most of the day

My computer processes data stored in a database, my hard drive constantly making noises, reading and writing to that database, the raw data comes in every day, new data compared to old data… changes recorded, old data deleted, etc…

This process usually takes up 5 to 6 hours, even though i run multiple threads on 4 processors, the reason is, well the hard drive, every thread reads the data it needs to operate on, if only i had a good SSH to cut the time down to 2-3 hours, or wait, maybe i have what is better than SSD, RAM !

First, i need to informa anyone that i intend to use there PCs for a background process that they will not feel exists

Most of the users are Windows users, so i need MEMCACHED for Windows installed on there PCs, but before i install on there PCs, i will delay this operation until i implement on my own PC first (Although i have little of my 8GBs to spare unlike everyone else)

Now, let us play, First i download memcached, made sure it is usefull in PHP as well as C++

next i unzipped the data to C:\Program Files (x86)\memcached

Now open the command prompt (cmd)

cd C:\Program Files (x86)\memcached

From properties of the memcached.exe file, change properties to always run as administrator (I can’t because UAC is off and i don’t need to for that same reason)

On command prompt

memcached.exe -d install

Now, if it has been installed as a service, i should be able to see it right ? So i open services, scroll down, and there it is with startup type set to auto :)

Adding more ram to make use of 4GBs on every PC

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\memcached Server

find the ImagePath entry and change it to look something like this, adding the amount of RAM you want to use (Increase) to a number in megabytes, i want 4GB so that would be 4096MB

“C:\memcached\memcached.exe’ -d runservice -m 4096

Now when you start the service via net start “memcached Server”, it will run with 4GB of memory at it’s disposal.

Good, now what, Now we need to start memcached, Just start it from services, or run one of the following line to start it from the command line

c:\memcached\memcached.exe -d start
net start “memcached Server”

Now that it is online, let us see how it works from PHP

We need to load php_memcache.dll

edit php.ini (Mine is in my PHP directory, yours can be in the windows directory)

Uncomment (Remove ;) from

extension=php_memcache.dll

Now restart apache

Testing !

Now i need to check that memcached works from PHP on my localhost

<?php
$memcache = new Memcache;
$memcache->addServer(‘localhost’, 11211);
print “Server’s version: ” . $memcache->getVersion() . “<br />\n”;
$memcache->set(“mykey”,”A string you should obviously see in output”,false,60);
print $memcache->get(“mykey”);
?>

The magic of multiple servers is done in php by simply adding more of the (addServer) calls, they will only be opened when they are needed and there is no overhead.

But i hear you say, host1 has 4GBs of memory, and host2 has 512MB of memory, This is where you should set the weight of host1 to 8 since it is 8 times larger than the smallest server which is 0.5GB (and default weight is 1)

This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply