Jag har tweakat mina apache configs lite nu så att jag tror servern fungerar lite bättre. Innan lät jag den starta i princip så många processer den ville, nu begränsat jag det till 5. Den kommer inte kunna ta lite högt tryck så att när det blir jättemånga användare kan den bli väldigt långsam, men den använder inte alls lika mycket minne och sålänge jag har relativt få användare borde den vara mycket snabbare. Personligare upplever jag att allting fungerar snabbare. Hoppas ni gör det också, rapportera gärna era upplevelser i en kommentar.


tetris


Jag lade ut två applikationer (mina rails apps) till Heroku. Det är inte kritiskt att de ligger på min server, DHG applikationen får jag nog köra från min server under eventet. Men det är inga problem, den behöver ju inte ligga och ta plats där just nu bara.


tetris


Anledningen till att jag uppgraderade mjukvaran var att den var utdaterad och drog mycket minne. Jag ville lägga upp en site till och hoppades på att den nya mjukvaran skulle dra tillräckligt lite minne för att jag skulle kunna hosta en site till. Men tyvärr inte, swap usage var högt som fan och den var tvungen att skyffla runt cache minne som fan i swapen för att hålla takten uppe.

Vad jag har gjort nu är att jag har uppgraderat min slice på slicehost.com till en 512mb slice. Nu har jag ~450mb minne used i snitt, varav 400mb är cache. Men det innebär att alla sidorna bör flyta riktigt fint nu. Så långt jag har lyckats testa fungerar det skitbra. Tyvärr kostar det 18 dollar extra i månaden, och jag är inte säker på att det är värt det, så får eventuellt ta ner någon site (någon okritisk site, bloggen och wikin kommer alltid ligga uppe) eller så får jag hitta en annan hosting lösning.


tetris


So it was time to upgrade my server software. I was using lighttpd with mongrel_clusters and php5. But with all the hype of passenger and how (actually) great it is, I decided to destroy my wonderful uptime in favor of easier deployment and less memory usage. I put up one more site so the server is kind of overloaded, i have virtually no free memory, if everything becomes to slow here i will probably shut one site down. So heres what i did (the whole thing took around 6 hours):

I backed up my databases by exporting from phpmyadmin. I then tarballed my repos and my website root directory and backed them up. And i was off, reformating my wonderful uptime of:

20:08:35 up 245 days, 3:37, 2 users, load average: 0.29, 0.35, 0.20

Then began the commands:

sudo apt-get update
sudo apt-get install build-essential
sudo apt-get install mysql-server
sudo apt-get install php5-mysql
sudo apt-get install apache2

sudo apt-get install php5
sudo apt-get install php5-gd
sudo apt-get install libapache2-mod-php5
sudo apt-get install tetex-base tetex-bin dvipng

wget http://rubyforge.org/frs/download.php/45905/rubygems-1.3.1.tgz
tar -xf rubygems-1.3.1.tgz
cd rubygems-1.3.1
sudo ruby setup.rb
sudo ln -s /usr/bin/gem1.8 /usr/bin/gem

sudo gem install rails
sudo gem install rails -v=2.1.1
sudo gem install clickatell
sudo gem install capistrano
sudo gem install haml
sudo apt-get install sqlite3
sudo gem install passenger

Now i ran into some trouble, first time. Apparently installing ruby wasnt enough. I got this:

require': no such file to load -- mkmf

I got the solution thanks to this guy

So i had to install this too:

sudo apt-get install ruby1.8-dev

Trying this command again and it worked:

sudo gem install passenger
sudo gem install mysql

Now this failed. With these error messages:

Building native extensions. This could take a while...
ERROR: Error installing mysql:
ERROR: Failed to build gem native extension.

/usr/bin/ruby1.8 extconf.rb install mysql
checking for mysql_query() in -lmysqlclient… no
checking for main() in -lm… yes
checking for mysql_query() in -lmysqlclient… no
checking for main() in -lz… no
checking for mysql_query() in -lmysqlclient… no
checking for main() in -lsocket… no
checking for mysql_query() in -lmysqlclient… no
checking for main() in -lnsl… yes
checking for mysql_query() in -lmysqlclient… no
*** extconf.rb failed ***

So i had to run this, after some extensive googling and trying random things:

sudo apt-get install libmysqlclient15-dev

What i got from the internet originally was this: (and it was wrong, that package doesnt exist anymore, so i had to figure out to use 15 instead)

sudo apt-get install libmysqlclient5-dev

Then began the passenger installing

sudo passenger-install-apache2-module
sudo apt-get install apache2-prefork-dev

And ruby enterprise for less memory usage:

wget http://rubyforge.org/frs/download.php/48623/ruby-enterprise-1.8.6-20081215.tar.gz
tar -xf ruby-enterprise-1.8.6-20081215.tar.gz
cd ruby-enterprise-1.8.6-20081215
sudo ./installer

(following instructions and reinstalling everything)

passenger-make-enterprisey

Some excessive configuring of Apache with Vhosts and stuff, and this:

LoadModule passenger_module /opt/ruby-enterprise-1.8.6-20081215/lib/ruby/gems/1.8/gems/passenger-2.0.6/ext/apache2/mod_passenger.so
PassengerRoot /opt/ruby-enterprise-1.8.6-20081215/lib/ruby/gems/1.8/gems/passenger-2.0.6
PassengerRuby /opt/ruby-enterprise-1.8.6-20081215/bin/rubysudo apt-get install git

Then finally:

sudo apt-get install subversion
sudo apt-get install irb
sudo apt-get install postfix
sudo apt-get install screen irssi

Yeah i know i could have bundled this up into one big install command but i wanted to see what failed along the way. Next time i have this so i can i can do the whole command in once.


tetris


So i’ve just set up my slice on slicehost.com. It’s a 256mb slice so i’ve started to keep an eye on how much memory i’m using. Seems i had like 10 fcgi processes running with PHP, one that pulled 15% of memory, one that pulled like 7% and the rest pulling about 2% each. So this was a huge leak i thought. I only have 2 sites running on PHP so it seemed useless to have that many processes available for the sites. To limit this and reduce memory usage i changed this in my lighttpd config.


"max-procs" => 1,
"bin-environment" => (
"PHP_FCGI_CHILDREN" => "3",
)

This helped alot! It seems that lighttpd starts one process for each max-proc and 3 childrenprocesses for each max-proc. So this code results in 4 fcgi processes wich is more reasonable. I checked my sites to see if they slowed down but honestly, it just felt like they were faster. At the very least there was no difference. Once I surfed around the sites a bit the processes started pulling memory and came up to about 15% usage on one and 7% usage on the other again, but now i didn’t have 6 others pulling 2% each. This freed up around 10MB.

I now have a total of around 100-110MB free, that is, free incl. the cached memory. Which should be well and good and stand against most kinds of traffic i believe. My other 2 memory gobblers are mongrel_cluster which is pulling around 20% and MySQL which is pulling 14%. Postfix and Lighttpd are pulling just above 1% together so they are clearly not much more optimizable. I am a bit worried that mongrel is pulling 20% though. Of course most of the memory these processes use is cached, but it’s still pretty much. Anyone that can give me tips on how to further lower memory usage?


tetris