Category Archives: Sh*ts

Load balacing – nginx and HAProxy

I had a scalability problem at work. Having about 3k customers with an average of 500 – 600 concurrent sessions and a middle aged all-in-one server, I have to balance http and https connections at least over 2 servers without changing the main IP address used by the client to start the application.

rock ssd

 

At the beginning, I evaluated Nginx, which is a well established http server (known for its outstanding capability on serving static resources) that has the capability to proxy requests to a pool of servers. I left this road quickly when I noticed that the proxy capability of Nginx does not supports (yet) sticky-sessions. In fact, when session affinity is required, Nginx can only route connection using source IP address as selection key, loosing the round-robin capability based on weight (that I need because I have server with different strength).

 

Looking for a balancer that supports weighted backend as long as affinity sessions, I foundHAProxy, which is considered the de-facto solution for this kind of problem. Again, evaluating this solution, I found something that bother me: HAProxy, in its stable version, can balance only http connection; it does not have support for https, which I need for my next version of the app.

Read more at: http://blog.towerengineering.it/2012/12/load-balancing-with-nginx-and-haproxy-1/

 

Nginx_HAProxy_Backend

 

———————-

HAProxy is really just a load balancer/reverse proxy. Nginx is a Webserver that can also function as a reverse proxy.

Here are some differences:

HAProxy:

  • Does TCP as well as HTTP proxying (SSL added from 1.5-dev12)
  • More rate limiting options
  • The author answers questions here on Server Fault 😉

Nginx:

  • Supports SSL directly
  • Is also a caching server

At Stack Overflow we mainly use HAProxy with nginx for SSL offloading so HAProxy is my recommendation.

Read more at: http://serverfault.com/questions/229945/what-are-the-differences-between-haproxy-and-ngnix-in-reverse-proxy-mode

———————-

“Nginx is becoming the standard for front end load balancing for many high traffic sites and this helps.”

I’ve used nginx as a load balancer, and it’s not pretty. All of the nginx load-balancing modules I’ve used, or seen used (I can think of at least five off the top of my head), have fallen apart under load, or not balanced intelligently, or just been plain bad. The modules I’ve used also tend to be hard to instrument, which makes working out exactly why they’re failing a bit of an adventure. I’m sure (I’d hope, at least) the load balancing modules in nginx have improved over time, but I’d still be very wary of it. In short: nginx is a kick-arse webserver, and I highly recommend it for that purpose, but as a load balancer I’d find something else.

My preference is for IPVS almost everywhere, as it runs at the IP layer and completely avoids all the ugly problems you just can’t avoid with a proxy. If you do feel the need to use a proxy, though, I would strongly recommend HAProxy over nginx. There are (narrow) circumstances in which a proxy is the best solution for the job, and I think HAProxy is the best of the bunch.

Read more at: http://www.hezmatt.org/~mpalmer/blog/2011/07/24/followup-to-ssl-session-caching-with-nginx.html

 

———————-

A example of how to configure HAProxy and Nginx
http://think-devops.blogspot.pt/2013/04/load-balancer-with-ssl-offloading-nginx.html 

Client-Side vs. Server-Side Rendering

 

Yesterday Twitter announced that it was moving away from client-side rendering back to server-side rendering in order to improve page load time. Today I found myself having to defend my position that server-side rendering will almost always be faster. I figured I’d blog about it.

I want to point out a couple things. First, I’m talking specifically about render performance and page speed. There might be other compelling advantages to thick-clients; I’m talking about performance. Secondly, I’m going to get on a high horse here and say that it worries me that developers think client-side rendering is faster. This is basic and fundamental knowledge about how the web and browsers work. Maybe I’ll be proven wrong. If I am, I’ll admit it. It’ll be embarrassing because it means that I don’t know the fundamentals. But I’ll be glad to have learned (which is why I blog).
Read more at: http://openmymind.net/2012/5/30/Client-Side-vs-Server-Side-Rendering/

Bootstrap tools and generators

Roundup of Useful Bootstrap Tools and Generators

As we have mentioned previously, Twitter Bootstrap, being a complex yet quite intuitive framework for building websites, has numerous ready-to-use themes and templates that are made for those who want to quickly prototype its project. It includes numerous features as well as third-party jquery-based extensions that all together contribute to development.

Today we are going to take a look at other helpful assistants that were designed in order to even more lessen your efforts and save your time while the programming. We have listed useful Bootstrap tools and generators that embrace different aspects, providing integral instruments for creating marvelous web interfaces.

(…)

Read more at: http://ewebdesign.com/bootstrap-tools-generators/

 

php – directory size

I was trying to get a directory size with PHP under a *nix environment…
This is what I’v found on stackoverflow… and it works 🙂

**
 * Get the directory size
 * @param directory $directory
 * @return integer
 */
function dirSize($directory) {
    $size = 0;
    foreach(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory)) as $file){
        $size+=$file->getSize();
    }
    return $size;
}

And to get it with Kb, Mb, Gb etc….

 function formatSizeUnits($bytes)
    {
        $symbols = array('B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB');
        $exp = floor(log($bytes) / log(1024));
        @$bytes = sprintf('%.2f ' . $symbols[$exp], ($bytes / pow(1024, floor($exp))));
        return $bytes;
}

Open-Sourced H.264 Removes Barriers to WebRTC

When it comes to making collaboration technology such as high-definition video open and broadly available, it’s clear that the web browser plays an important role. The question is, how do you enable real-time video natively on the Web? It’s a question that folks are anxious to have answered.

WebRTC–a set of enhancements to HTML5–will address the issue head on. But, there is an important hurdle that must first be cleared, and that’s standardizing on a common video codec for real-time communications on the web – something the Internet Engineering Task Force (IETF) will decide next week.

The industry has been divided on the choice of a common video codec for some time, namely because the industry standard–H.264–requires royalty payments to MPEG LA. Today, I am pleased to announce Cisco is making a bold move to take concerns about these payments off the table.

We plan to open-source our H.264 codec, and to provide it as a binary module that can be downloaded for free from the Internet. Cisco will not pass on our MPEG LA licensing costs for this module, and based on the current licensing environment, this will effectively make H.264 free for use in WebRTC.
Read more: http://blogs.cisco.com/collaboration/open-source-h-264-removes-barriers-webrtc

Does Cloud Computing reduce IT costs?

“People move to the cloud for perceived cost savings and what we’re finding is it gets really expensive compared to colocation, [particularly] if you look at the three-year overall total cost of ownership of an application that is pretty constant,”
By Raj Dutt, senior VP of technology at Internap
Read more at http://virtualizationreview.com/Blogs/The-Schwartz-Cloud-Report/2013/02/Does-Cloud-Computing-Reduce-IT-Costs.aspx#

 

cloud vs colocation

I’m gonna let here some paragraphs of a nice article from serverdensity.com geeks blog, explaining their choices/ideias cloud vs rented vs colocation with their point of view is also the same that I have about getting our own servers instead of use clouds or rented servers –

Before the paragraphs from serverdensity i’m gonna let some maths that i’v made 3 weeks ago… rackspace vs our own servers (dell).

rackspace clouds with 2Gb RAM / 80Gb disk – web and sql vs colocation dell 2Gb RAM / 500Gb disk and rackspace clouds with 8Gb RAM / 320Gb disk – web and sql vs colocation dell 8Gb RAM / 500Gb disk

2GB RAM
8GB RAM

 

type
colo
web server
db server
total mo
colo
web server
db server
total mo
colo
web server
db server
total mo
Total 3yrs
rackspace
1st year
$0 /mo
$87 /mo
$153 /mo
$240 /mo
2nd year
$0 /mo
$87 /mo
$153 /mo
$240 /mo
3rd year
$0 /mo
$87 /mo
$153 /mo
$240 /mo
8 640
colocation
1st year
$250 /mo
$51 /mo
$51 /mo
$352 /mo
2nd year
$250 /mo
$0 /mo
$0 /mo
$250 /mo
3rd year
$250
$0 /mo
$0 /mo
$250 /mo
8 418
rackspace
1st year
$0
$350 /mo
$554 /mo
$889 /mo
2nd year
$0
$350 /mo
$554 /mo
$889 /mo
3rd year
$0
$350 /mo
$554 /mo
$889 /mo
$ 32 540
colocation
1st year
$250 /mo
$104 /mo
$104 /mo
$458 /mo
2nd year
$250 /mo
$0 /mo
$0 /mo
$250 /mo
3rd year
$250
$0 /mo
$0 /mo
$250 /mo
$ 9 787

Continue reading cloud vs colocation