You are currently browsing the Batista R. Harahap posts tagged: nginx


Compiling nginx 1.4.0 With SPDY on CentOS 6

Just a few days ago, the latest version of nginx at 1.4.0 was released to the public. The version bump adds a lot of new capabilities for your web stack. The most interesting for me was support for SPDY 2 protocol.

Excerpts from Chromium SPDY’s page reads below:

As part of the “Let’s make the web faster” initiative, we are experimenting with alternative protocols to help reduce the latency of web pages. One of these experiments is SPDY (pronounced “SPeeDY”), an application-layer protocol for transporting content over the web, designed specifically for minimal latency.  In addition to a specification of the protocol, we have developed a SPDY-enabled Google Chrome browser and open-source web server. In lab tests, we have compared the performance of these applications over HTTP and SPDY, and have observed up to 64% reductions in page load times in SPDY. We hope to engage the open source community to contribute ideas, feedback, code, and test results, to make SPDY the next-generation application protocol for a faster web.

In order for SPDY to work, one will need an SSL certificate and OpenSSL 1.0.1c at least to compile and run a website successfully with nginx. SPDY needs NPN enabled with OpenSSL and CentOS only provides 1.0.0. According to a blog post here, we can just add a repo to get OpenSSL to work nicely.

Here are the steps needed to compile nginx with SPDY support:
$ rpm -ivh --nosignature http://rpm.axivo.com/redhat/axivo-release-6-1.noarch.rpm
$ yum --enablerepo=axivo update openssl
$ cd /opt/src
$ wget http://nginx.org/download/nginx-1.4.0.tar.gz
$ tar xfz nginx-1.4.0.tar.gz
$ cd nginx-1.4.0
$ ./configure --with-pcre --with-http_ssl_module --with-http_spdy_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_stub_status_module --prefix=/usr/local/nginx
$ make -j4
$ make install

Now that the steps above are through, it’s time enable SPDY with your websites assuming that you already have a working nginx configuration with SSL enabled. It’s actually really simple, the full explanation is located at nginx’s SPDY documentation.

server {
listen 443 ssl spdy;
ssl_certificate server.crt;
ssl_certificate_key server.key;
...
}

Now test your website at spdycheck.org to see if your SPDY implementation is successful. Cheers!

Spontaneous Writing Episode II

The second episode of Spontaneous Writing is now in session continuing from this previous session. For tonight, my iTunes is happily playing songs by Tohpati in his rather old solo album. By the way, from what I’ve been trying to do the past few weeks, it seems that only when I got home will then writing moments will be abundant for my fingers. Can’t seem to do this while at the office.

Since it’s still warm and huggable, the first topic will definitely be about Urbanesia and its unprecedented outcome this past few months. Just got home from a long 2 weeks marathon at the office. I must say the last 2 weeks were one of those times when redefining moments just happen without no specific reasonings. My last piece of spontaneous writing noted December 2010 as one of those times and yet it happened again early this year.

In a more technical way, all of our preparation to ready Urbanesia for 2011 were making results faster and better than what we expected them to be. Since we are migrating every models we had to retrieve data from our newly crafted API, Sofvia our application server were flooded with a high number of locally inbound HTTP requests. Load averages soar high looking from our Munin graphs.

The most obvious reason for this to happen is because we just migrated on of our application server to Biznet’s Cloud Computing platform. We took a spin with the lowest spec available which is a 1 core, 1 GB RAM, 100 GB SAN Storage and 100 Mbps shared International Bandwidth. Freshly installed CentOS and wiped everything not needed due to the resource constraints. We knew it wouldn’t be ideal to make it a full fledged application server so instead we made it to be a full fledged proxy server for our international traffic. Geo targeted DNS with Bind was executed so the local and international is routed accordingly.

With the changes above, Googlebots scour our website like never before. Just 18 days after its premier, our stats show that in January 2011, Googlebots downloaded a whooping 217 GB worth of data from our website. The amazing thing is with nginx in our Biznet cloud server, the load average never even touched 1.0. Memory usage was also amazingly lean with no swap space at all. It’s great to know all those gigabytes of data is served by a tiny server.

With all that traffic, the strain was with Sofvia. We had to optimize a step further. This time we physically separated our CDN with our application server. It’s a bit risky for us because we didn’t have any network shared filesystem implemented yet but again because of needs, we implemented what’s necessary and to our expectations memory usages dropped significantly from Sofvia. Sofvia now has more breathing space for us to optimize. Sofvia is now purely an application server and doing only that. The migration is almost complete for Sofvia.

Enough about technicalities, now the next topic will be family. I come from a Batak family and as with any Batak family, the number one thing we Bataks have in mind is family. As I come home today, I bought my Oma 3 CDs of which she wanted me to get for her to accompany her during the long hours she was on the road everyday. For the record, she is a feisty Oma, 75 years old but never looked like she’s getting any older.

I remembered as a little boy, my Oma and Opung took me and my brothers to Singapore for the new years. Me and my Opung was exhausted after a long walk around Orchard accompanying my Oma. Yes you guessed right, my Oma was not even bothered. She couldn’t care less that we are waiting in front of one of the mall she’s entering. She is still exactly in her late age today. Everytime I got to accompany her into a mall, she will most definitely have the stronger legs! It’s a blessing for all of us that age is not an obstacle for her.

She’s the kind of person who always want to be with family no matter how bad or how destructive you are at any point of your lives. She never gave up on me when I didn’t have any job, only a freelancer and even when I have nothing to give her. An inspiring icon for me and for all of us in this big family. All she wants is for all of us to be happy and I don’t know how but she managed to get the best out of me in any situation, I guess it’s her faith in Him is glowing and automatically shines. She’s an example to follow and boy my Opung was a lucky guy!

Next up is also something close to my heart. I am blessed with great friends with every phase of my life. Wherever I am, there is always a friend I can confide and tell stories vice versa. No different today, I’m surrounded with the best persons in the startup scene. They’re not just colleagues, they are more than that and I put special care and attention to each one. Okay this is about Urbanesia (again), it’s just automatic that everything I am right now is Urbanesia, it’s part of my identity. We worked smart and hard to leverage Urbanesia.

Suffice to say, everyone is supercharged for anything that’s gonna happen next. It’s like we’re starved and the hunger is pushing everyone to the limit. Selina Limman I quote saying this: “Urbanesia is not only a professional matter, it’s personal for all of us“. In my point of view, we have successfully introduced an unlimited amount of fuel which is passion. No matter what your position is, you matter to all of us, without you, we are not complete.

The prove is when night falls. When the sun is still shining, my creativity is hindered by the amount of routinity obliging me to perform everyday. I call it nurturing so when they grow up, I can happily let go each one and empower the growth they are contributing. Coming back to the main point, at night, the usual suspects still at the office will almost certainly be me and Ridhi Mahendra. Some nights, there are others but most of it will be us and beer bottles lol.

Cutting it short, Ridhi is a marketing guy and I’m the technical guy. We discuss and measure everything. With every conclusions, we reacted instantly to respond to what the data is telling us. This I tell you is not an easy thing to do, it’s an art because how dynamic the web is. One day it can conclude to A and another day it will conclude to -A. So the challenge was to be as dynamic as possible while maintaining a high level of consistency with everything we developed.

Thanks to one of the partners at East Ventures, Willson Cuaca, we have managed to scale and metric everything. It all comes down to what you know and what you don’t know. To know what you don’t already know, we’re lucky to have shortcuts like East Ventures. However, the challenge was to experience what you don’t know and excel from it to give lessons of what to do and what not to do. It’s been a roller coaster ride honestly!

The last topic is very personal because it’s about a date I’m having tomorrow :) Since my last relationship, this will be the second date I will have with the same person I might add. Hoping for a great night tomorrow to wrap off a long and fruitful 2 weeks. We’re gonna see The Green Hornet and boy this year will be full of superheroes movies, YEAYYY!!!

Okay am not gonna talk more about this date tomorrow. It’s 1.57 AM and I’m wasted. A good night sleep on a genuine bed is what I’ve been longing. So I’m off now, thanks for reading. I’m gonna wrap things up by quoting one of my own blog post.

You are you’re own StartUP

Small is NOT so small

It’s been like a few months not posting into my own blog. The 24th day of 2011 and it seems that months have passed by just like that. In the span of 24 days that have passed, every single day is cramped with all the aspects of being a startup. Just today, I went from a programmer, a cable crimper, a business partner, a troubleshooter, a mobile app consultant, a colleague to a friend for a friend, all in just one day. Multiply that by 24 and that’s exactly what’s been going on. The dynamics revolving is mind blowing.

I can’t help to wonder exactly what I’m doing right now is to look back and kinda being nostalgic to myself to figure out how so much energy can be exuded with far less sleep than ever before. Physics defines e (energy) equals m (mass) times c (speed of light) square. There is no indefinite variable there although I have to admit my mass is fluctuating but it is drastically paled to insignificance when multiplied with the square of the speed of light which is 3.6 millions meters/second. NO, the speed of light is a constant and therefore always have the same value while mass is the dynamics.

Well mass is the variable and this is where energy can be increased or decreased exponentially literally. With Einstein’s theory of energy, it’s safe to say that without mass, it’s just light. The same light currently transporting zillions of gigabit traffic around the world to every connected computers globally. What’s best of all, at least for now, light is unlimited and available anywhere in the world. What the world lack is mass.

These past months, we’ve been having a 40% problem in Urbanesia. Our sudden drop of traffic is just weird. Efforts to tackle the drop were taken, from AB testing new designs to optimizing codes to be able to serve faster were done like it’s do or die. We found a really troubling fact. Our Google Analytics Javascript code is not loading as expected in most parts of Urbanesia.

With the new look, we introduced a new framework for Urbanesia. We hate inline JS and CSS, so we created a framework to parse JS and CSS, minified them and put them in separated files. The Google Analytics loader JS was one of them. We put it at the bottom like any other sane website. Well that was the problem. Most of our visitors’ Internet connection was not fast enough to grab the loader file in a way to keep up with their engagement with the website.

So with every good programming practice, we refactored the codes. Affectionally, we put the codes up top before closing the HEAD tag and pointed ga.js to load from our CDN. The result is a 40% difference! This is a big lesson for everyone in Urbanesia. With Google Analytics measuring the right numbers of traffic, our approach to enable Urbanesia to scale is now sane again.

During the process, we treated ourselves a new Cloud Server at Biznet and boy that has made another big impact towards our traffic. From the beginning of the new look for Urbanesia, we concentrated our efforts so that our application servers can be migrated to multiple servers instantly. The big roadblock was that we didn’t had a good enough API to support this. So we went on to create one of the best API to date for Urbanesia.

By having a great API, we managed to localize each parts of Urbanesia to scale with proportion. Optimizing Apache is trivial to be able to handle this many API calls/seconds. Because of Apache’s great flexibility, it became its own worst nightmare. Our Apache configuration is hand tuned slowly to cope with the changes. Thank God for nginx!

Our cloud server is a single core, 1 GB RAM server and it’s serving half of Urbanesia’s traffic with that little man namely nginx. Nginx as a proxy load balancer is amazing. Just by having 1 nginx, we boosted 300% of our concurrent traffic. With proper caching of static contents, this has been a relieve. Since we now have 2 nginx instances, we have increased our daily traffic to cope with multi Mbps traffic constantly.

In parallel, we transitioned Urbanesia from a 100% MySQL oriented website to switch to a 70% portion for MySQL and 30% portion of MongoDB. The problem with MySQL is that it can’t keep up with our increasing needs and we don’t wanna scale hardware yet. So it’s back to the applications we used. By using MongoDB, we put all of our high volumes & low value data in it. The best thing about MongoDB is that it’s really fast! The catch is MongoDB uses a lot and i mean a lot of physical memory to be able to do this. Think of of it as MySQL + Memcache on steroids. To keep MongoDB performing like this, we revamped our Database server to cope with MongoDB’s need for memory.

So as you can see, logically we have separated Urbanesia into partitions. Now we can scale Urbanesia according to the needs of each partitions. A Googler told me that “Faster loading of pages equals more revenues“. We measure revenue not necessarily in $$$. Users engagements is one of our metrics. Well the words were proven. We hit a new record this January with users engagements. The total number of reviews as of 24 January 2011 have beaten the best month of 2010 and we still have 7 days to get more reviews.

Our marketing and development team is moving with right pace both independently and as a big team. This is key to our sudden increase of performance in January 2011. We learned to work it out as a team and make decisions based on data collected. We AB Test all of our changes and introduced a heat map. The data we gained was invaluable to our efforts. Because of the nature of Urbanesia being so vast, we couldn’t just highlight everything all at once, we needed to move single minded. Reinforcing everything one step at a time.

The last 3 months of 2010 were allocated to create a rock solid foundation for 2011 and it worked out like a charm. I’m very proud to say that our team of superheroes are incredible. The dedication and affection towards Urbanesia are not like what you can expect in any other ordinary workplace. Salute to every one of us!

In closing, I learned an important lesson with scaling. Scaling is an artwork, nothing is for certain until you get to the point where every destination is mapped and prepped for dynamics. Meaning that anytime, our infrastructure must be ready for changes while maintaining a high level of stability. From a business side, well when you got the software, hardware and human resource right then you just gotten your most invaluable asset: A living and breathing product manifested in all of our work. This will pay the bills, just gotta have faith :D


photo of Batista Batista R Harahap [email protected]
Jl. Bango II/29C, Pondok Labu
Cilandak , DKI Jakarta , 12450 Indonesia
62817847023

This hCard created with the hCard creator.