Free, Open-source, Cross-platform Web Servers. : Apache Vs Ngix


  • (+) widely used for many years.
  • (+) lots of modules have been written to expand its functionality.
  • (-) slows down under heavy load because of the need to spawn new processes, thus consuming more computer memory.
  • (-) It creates new threads that must compete with others for access to memory and CPU (may cause deadlocks).
  • (-) It refuses new connections when traffic reaches the limit of processes configured.
  • (-) It relies on processes and threads.


  • (+) it was written to address some of the performance and scalability issues associated with Apache.
  • (+) It was written to address the C10K problem (the ability to handle 10.000 connections, given the limitations of the operating systems).
  • (+) It’s event-driven and asynchronous.
  • (+) the use of cache loader and cache manager processes to read data from disk and load it into the cache and expire it from cache when directed.
  • (-) missing modules needed to work with back end application servers and run scripting languages.
  • (-) Things that ‘just work’ out of the box with Apache may need additional research and configuration under nginx. Control panels and automatic configuration tools may not be available for nginx yet.

According to source [1], Apache is known for its power (more modules available to work with back end applications and to run scripting languages)  and Nginx for speed (serves static content quicker). So if your website uses predominately languages such Python or Ruby then Apache should be the choice. Otherwise, if PHP is the main language and high load and speed are two important features and your website serves mainly static content than Ngix is the right choice.Source [2] e [3] chooses Apache because it is a more mature web server, more robust and it has more documentation (therefore, is more easy to learn). Apache provides lot more functionality than Nginx. It supports a much wider range of Operating Systems.Across all sources the right answer is a combination of both or some kind of cluster with multiple web servers, load balancers and the use of cache and its management.

Personally I am going to use Apache, because my aim is to learn how to develop websites using PHP and I will not have (at least for now) the problem of high load and excessive consume of resources. Also, I am choosing Apache over Ngix because currently is the most used in the open-source world and therefore I will have access to more documentation and features.





(note: Some of this text is extracted directly from the sources).


Java : Remove all occurrences of char from string

So if you wish to remove all occurences of a certain char from a string you just need to use the String in-built function  – replace(char,emptyChar).

For example, I wish to replace all occurences of ‘:’ from

String str = “bc:14:01:b0:3a:b8”;

To do so I replace the char ‘:’ with the empty one “” like this:

str = str.replace(“:”, “”);

And I get the desired output:


Yup, Is this simple ;).

The Power of a simple SET…

Recently, I installed a new local MySQL Server with the purpose to log debug messages.

But because I had to log a lot of messages disk space became an issue. So I decided to create an event to clear these messages hourly. 

I spent a lot of time trying to understand why the code worked fine in a single execution, but when the same code was inside the event it was not working when the schedule was met. 

After some reasearch I found out that by default event_scheduler global variable is OFF. 

After enabling it, the event started to work.

You just need to execute the line:

SET GLOBAL event_scheduler = ON;


Amazon EC2 we got a problem! Instance reachability check failed After Windows Update

The day started awesomly.

I logged in into my amazon EC2 instance, that I use at work, for beta testing the software before production, and everything was ok.

Then evil Windows came into play and greeted me with a message for updating the system.

So I did! And everything went wrong! 

The Problem:

After rebooting I was no longer able to connect to this ec2. Sign in to amazon aws console to see the ec2 status and found the message:

“Cannot load details for ami-#########. You may not be permitted to view it”. 

I then went to the Status Checks and I found out another helpfull message (not!):

“These checks monitor your software and network configuration for this instance.
Instance reachability check failed at August 25, 2014 10:20:00 AM UTC+1 (8 minutes ago)”.

After poking around amazon forum I found out that the problem was due to a driver bug (AWS PV Driver Version 7.2.0).

The Solution:

1. Move affected instance to C3 instance type.
2. Uninstall AWS PV Driver Version 7.2.0 via Programs and Features and reboot when prompted
3. Download the 7.2.0 AWS PV Driver Installer from:
4. Install AWS PV 7.2.0 and reboot when prompted
5. Move instance back to non-c3 type.

(source :

Java – MYSQL – Prepared Statements – Insert Batch

//create prepared statement, bind it to db connection and SQL query.
PreparedStatement = dbConnection.prepareStatement(insertTableSQL);
//For each input value set input type, input position and value.
preparedStatement.set<inputType>(<index>, <value>);
preparedStatement.set<inputType>(<index>, <value>);

//For each new row to be inserted add it to batch 
//After adding to batch all rows to be inserted. 
//It's time to call execute batch.

For a complete example please see source.


Work with Visual SVN Server & Tortoise SVN

Great tutorial on how to install, configure and use SVN

Rajib Mahmud's Blog

I work in my office with Visual SVN in our software projects and would love to have a version control at our disposal. This is useful for many reasons. If we are working with one or more developer on a joint project, if we have a desktop and a laptop and we want to work from both computers while keeping the files synchronized, or if we just want to be more organized and keep versions and backups of our work. We can also use Visual SVN to synchronize folders or documents between several computers.

Here I give the Software. Please Download these.




This article will have 2 sections One will discuss the SVN Server installation and configuration and the second part will be about how to use the SVN client.

First you have to download the Visual SVN Server Installation

Or download Visual SVN and Tortoise SVN…

View original post 1,005 more words

Perl – Forking

Today I faced a dilemma. Soon I discovered there was a name for that dilemma – thrashing.
In a project I’m currently working on I have dive deep into the multitasking/multithreading world. Bearing in mind that I was working with Perl.

To implement a multitask environment I used Forks (Parallel::ForkManager). But I thought forking was not the right solution for me.


Because In my ingenuity I created 50 forks each one responsible for parsing a stream. But soon I started having blocked threads. I thought it was because one of the threads was taking more time because it had to parse more data than the others. And because I had a wait_for_all_children(), that all the other threads already finished had to wait for the slower one to finish in order for the mother to launch another block of 50.

My wrong code:

my $pm = Parallel::ForkManager->new($nrRowsReturned);

while(there are rows to fetch){
$pm->start and next;

So I decided to ask for help on perlMonks.
Before I forget my server is running in an amazon’s EC2 m1.xlarge (4 vCPU).
People are very nice on this forum and soon I had a couple of great replies.

You can see all the answers here.

In summary:

The idea of Parallel::Forkmanager is to use the optimal number of parallel children, which is usually roughly the number of CPUs (or cores) of your machine, and not the number of tasks to be processed.

Accordingly, to this the line
my $pm = Parallel::ForkManager->new(50);
Should be changed to:
my $pm = Parallel::ForkManager->new(4);
Being 4 the maximum available cores (although due to hyper threading I can go to a max of 8).

Than as corion continue to say:

…Parallel::ForkManager, it limits your program to maximum 4 children, but if one child ends, Parallel::ForkManager will launch the next child immediately.

So my problem of only being able to run packs of 50 instead of a “courossel” of threads it’s solve. I just need to keep the flowing going. Then Parallel::ForkManager will be able to launch threads to parse each new stream as they come and other dies.

Sundialsvc4 gave me a detailed and awesome explaination on how things really work:

What BrowserUK is saying about “only 4 at a time” is anything but “an aside.” It’s the key to the whole thing.

Consider what you see going on every day in a fast-food joint. There’s a certain number of workers, and all of them are working on a queue of incoming food orders. If 1,000 orders suddenly come pouring in, then the queues will get very long, but the kitchen won’t get overcrowded. The number of workers in the kitchen, and each of their assigned tasks, is set to maximize throughput, which means that all the workers are working as fast as they can and that they are not competing with one another for resources. The restaurant doesn’t lose the ability to do its job … it just takes (predictably!) longer. (And they can tell you, within a reasonably accurate time-window, just how long it will take.)

The loss of throughput, furthermore, isn’t linear: no matter what the ruling-constraint actually is, the loss becomes exponential. If you plot the average completion-time as the y-axis on a graph, where the “number of simultaneous processes” is x, the resulting graph has an elbow-shape: it gradually gets worse, then, !!wham!! it “hits the wall” and goes to hell and never comes back. If you plot “number of seconds required to complete 1,000 requests” as the y, the lesson becomes even clearer. You will finish the work-load faster (“you will complete the work, period …”) by controlling the number of simultaneous workers, whether they be processes or threads.

The number-one resource of contention is always: virtual memory. “It’s the paging that gets ya,” and we have a special word for what happens: “thrashing.” But any ruling-constraint can cause congestive collapse, with similarly catastrophic results.

By launching 50 it means that each core is going to have a queue of approx 12 streams to be processed by each core. Only 4 simultaneously.

Because the queue is long, and gets longer because I’m always adding more in each while cycle,the available throughput,cpu and memory gets smaller, causing a bottleneck.

Then a very kind stranger added:

To abuse the fast food analogy where employees are threads, starting a new thread also involves going through HR paperwork before the new thread can do their task. (You really want the task to be more than making a single burger for customer #42 before retiring too)

Your quad-core restaurant requires a bit of time for one employee to save all their tools away before someone else can change context and use one of the four stations.

And once you run out of physical ram/floor space for threads to stand in, then you’ve got to use a bus to swap employees in and out which is horrifyingly slow.

After all the explanations my code changed to:

# max 4 processes simultaneously
my $pm = Parallel::ForkManager->new(4);
while( .. there are rows to fetch ..){
$pm->start and next;
$pm->finish; # do the exit in the child process