Hosting websites on an AWS EC2 micro instance

A few months ago, I signed up for an account with Amazon Web Services to take advantage of the first year free usage on EC2.

It was a great learning experience as I get to configure everything in detail.

With shared hosting, someone else does the setup and maintenance for you. You can configure a few things in detail but you can’t have full control. It’s like public transport, you cannot change the parts in the vehicle, but you can choose where you want to sit, but you have to share the ride with a lot of strangers.

And it sucks if you have to share it with a serial fartist. i.e. Some silly person who took down the whole server with poorly written codes that take up lots of CPU, or whose website is the target of a DDOS attack and all other websites on the same server got brought down with it.

There’s also co-location and dedicated hosting but those are not affordable to the average web developer.

Then comes the age of cloud computing.

You get full control of a server at the cost slightly higher than shared hosting. You have dedicated CPU and RAM resources so no other server on the same physical machine as you can affect you. (Though I’m not sure what happens if those servers get DDOSed).

Long story short, my shared hosting account with DreamHost was expiring and so I migrated my remaining sites to my AWS micro instance server and here’s the things that happened and what you need to do if you want to run multiple websites on a micro instance as well.

At first, I did not configure my Apache and MySQL installations to work on low RAM machines (micro instances get only 613MB of RAM). They came with the default configuration settings that are meant for dedicated machines that have higher amounts of RAM.

A micro instance does not have a swap file configured. You have to do it yourself and here’s a simple guide:

Switch to root and follow these steps to add the swap space –

Type the following command with count being equal to the desired block size:
dd if=/dev/zero of=/swapfile bs=1M count=1024

Setup the swap file with the command:
mkswap /swapfile

To enable the swap file immediately but not automatically at boot time:
swapon /swapfile

To enable it at the boot time, add the following entry into /etc/fstab:
/swapfile swap swap defaults 0 0

 

Source: Adding swap space to Amazon EC2 Linux Micro Instance to Increase the Performance

Next, edit your apache config file and look for the Server-Pool Size Regulation section.

Most likely you are using the prefork MPM. Reduce the MaxClients to about 10. This varies depending on how much RAM each process takes. From my observations, my httpd processes take up about 40M of RAM at most. So I use 10, which allows me to have 10 running httpd proccesses all taking up 400M of RAM.

It would also be a good idea to reduce the MaxRequestsPerChild to something around 1000 in case of memory leaks. Situations where a process takes up more than 40M of RAM and keeps growing.

Better explanation here.

Without the above. My apache kept spawning child processes so much that it used up all available RAM and my MySQL process got killed off frequently. That means all my sites that are database driven are immediately crippled.

On a related note, back when I was a child, I loved how I could change parts on those Tamiya cars which gave me the illusion that it would run faster. Looks like my fetish for performance tuning is still there.

Erik’s guide to planning social gatherings in Singapore

You love to meet up with your friends and chat over dinner or drink.

You think organizing a meetup is as easy as creating an event in Facebook, adding people to it and just wait for the day to come.

And one day before the event, you check the event page on Facebook only to find that no one has responded or put their attendance as maybe.

What went wrong?

Nothing. It’s simply in Singaporean’s blood to “bo-chup” (don’t care attitude).

1) Decide a default location and time.

If you ask everyone about their opinions, you would most likely get none. And if you get opinions, great! Change it accordingly.

Those who do not respond are usually fine with any place.

2) Plan in advance. At least 2 weeks or even better, 4.

Most people usually have plans made for the week and the next.

Planning in advance shows that you really want to meet up with those invited. It’s like how people would book advance tickets for a show/performance they like as soon as the sales for those tickets begin.

And if you get the excuse that you’re planning way too soon, ignore it. It only goes to show that that person wants to reserve his/her time on that day for something else, and values that event more than meeting up with you.

3) When confirming attendance, call them or SMS them.

I’ve never seen a successful meetup planned using Facebook unless it’s a small group of very very close friends, or you’re someone so important that people want to be around you 24/7 and even when you go to the toilet.

Start confirming at least a week before so you know the group size and make reservations at the restaurant accordingly.

For those who sound unsure, tell them that you are making reservations at a certain date and you need to hear an answer from them by then.

4) Expect late-comers and prepare for it.

Despite Singapore being so small it takes less than an hour to travel from one end of the country to the other by car, people will still be late. But they’re not entirely to be blamed. Our “world-class transport system” has to have world-class failures too sometimes.

Plan your meetup in such a way that those who arrive on time won’t have to wait for those who are late.

If it’s a dinner meetup, go into the restaurant first with whoever is already there and start ordering and chat.

Or meet up at a game center first where people can play some games while waiting.

The last few movie gatherings I did for my anime club, we gathered at a fastfood restaurant so we can have dinner and chat before the movie starts.

Troublesome isn’t it? But after everything’s over, everyone will appreciate you for putting in all that effort to get them together. That alone is rewarding enough.

Robin Hood Taxes

I once wondered why governments need to make things so complicated with complex tax systems and all that.

When the government gave out relief on GST to citizens a while ago, I thought to myself, “If you’re going to give the money back anyway, why not abolish GST in the first place?”

The answer came to me today as I studied the Singapore Budget 2012.

It’s like the Robin Hood style of stealing from the rich to give to the poor. But in this case, taxing the rich more, taxing the poor less.

And to do this, taxes are enforced for most financial transactions and then tax reliefs are given to people based on the size of their homes (rich people usually live in larger homes). Not 100% accurate but the gist of it is somewhere there.

Japan 2010 – Day 3

Woke up around 11am. P made breakfast and it was delicious.

After breakfast, P and S sent me off at the train station near their home. I made my way back to the hotel to unload the clothes I bought the day before and set off to Harajuku park.

It was a Sunday and there’s a lot of people here at this huge park. Very different from the parks in Singapore.

You can hear people practicing their music in less crowded areas. Kids playing football. Teens making dance videos. A large group of old people playing ukuleles.

I headed down to Roppongi next, to check out an exhibition at the Mori Art Museum. I’m not into arty stuff. I just enjoy looking at things.

Last event of the day was to check out a matsuri at Asakusa. It’s crowded. Lots of stalls along the way. I bought lots of food here and brought them back to my hotel room for dinner. It was too much so I kept the remaining food for breakfast for the next day.

2012

Ha, I can’t remember clearly what new year resolutions I made last year. But I think it’s something along the lines of working harder for more money, and take up a part-time degree course.

I did work harder than I was in 2010. But I never got around to getting that degree because I was given a chance to work overseas for a year and I was keen on taking up that offer.

Then I got approached with a job offer, with same pay but much better working environment, more challenging work.

Maybe in a year or 2 after things are stable with this new job, I will look into studying part-time again.

With freelance work and a new job taking up most of my time, I doubt I have enough spare time to pursue other things.

So this year, I shall focus on my Japanese language skills.

I took the N2 JLPT test on 2011 Dec. The results won’t be out till a few months later. If I pass, I might try for N1 this year.

The problem I’m concerned is even if I can get an N1 certification, it only means that I can understand Japanese well.

I know very well I can’t make up sentences in conversations well enough yet.

Also in my Japan trip in 2010, when I met up with my Japanese friends there, I had a hard time understanding what they are trying to say when they speak among themselves.

Native speakers speak very fast and are very different from what you hear on Japanese dramas and animes. From what I’ve heard, people who appear on TV and voice actors have undergone training in their speaking.

Hopefully the current SGD – JPY exchange rate recovers back to what it was 4 years ago. Currently it’s 1 SGD – 59 JPY.

Seeing photos of my friend’s trip there makes me want to go back there again.

Hmmm… It’s there where the real JLPT is.