The law of parallel processing

The law of parallel processing

Have you ever seen someone write bad code and try to solve the performance problem by throwing more hardware at it? Higher-level languages like Python and Java make it easier to write code, but they also make it easier to write bad code. This is because these languages do not force programmers to think about the performance of their code in the same way that lower-level languages like Assembly and C do. As a result, programmers who use higher-level languages can sometimes be lazy and write code that is not as efficient as it could be

In a recent article, I discussed the following scalability graph:

Article content

Let's discuss how you get parallel efficiency gain. A formula known as Amdahl's Law formulated by former IBM engineer Gene Amdahl discusses that the code's theoretical speedup is directly proportional to the least amount of work that can be parallelized.

Why are some technologies more optimized than others? Let’s find out. Parallel processing is the single biggest driver of computing efficiency. Imagine you land at an airport and have to move your luggage to the taxi rank.

Article content

  1. Imagine it takes 1 person 1 minute to move one trolley from the carousel to the taxi rank. If you have 1 trolley, for 10 people, it will take 10 minutes to complete. This is serial processing. 
  2. If you have ten trolleys for ten people, it will only take 1 minute to complete the task. This achieves the maximum parallel efficiency of 10X. 
  3. If five people insist on using the same red trolley, they must do their tasks sequentially. No matter how many free trolleys are available, completing them will always take 5 minutes. This results in a maximum parallel efficiency of 2X even though idle resources are available. 

Let's examine this analogy in the world of parallel databases:

Article content

Here is an example of three different types of databases processing SQL (Above picture credit Daniel Graham ). Imagine we have 100TB of data to analyze.  

  1. On the left is a serial processing database.  It chugs along at the speed of a single server, usually only a  single CPU on that server.  It is the slowest method. It is like having a single trolley for everyone at the airport.  
  2. In the middle, we see some parallel processing where multiple servers work together to do the table scans, joins, sorting, and oops. It doesn’t do sorting in parallel.  That’s a massive bottleneck in performance when terabytes of data are involved. This is like a few people insisting on the red trolley. This means resources are waiting in idle. No matter how many nodes you add to the configuration, you cannot speed it up unless you eliminate the "red trolley."
  3. On the far right is the max efficiency system, which does everything as much as possible in parallel.  This will be the fastest solution.  To go faster, we add more servers to the cluster.

In short, the more parallel efficient your system is, the better would be the system's throughput. A simple understanding of this principle can help you in writing better code. Always, the maximum parallel efficiency of your code is determined by the least amount of code that can be parallelized.


If you like, please subscribe to the FAQ on Data newsletter and/or follow Fawad Qureshi on LinkedIn.

One of those pictures looks familiar. Good explanations too... Thanks Fawad.

Thanks Fawad A. Qureshi for the article. It must be noted for the readers less familiar with the subject that some computations are intrinsically serial in nature or have an intrinsic serial fraction that can't be helped no matter how smart and mature is the database optimizer. I'd like to also point out that sometimes there are approximated algorithms that can have a better efficiency and yet be good enough for certain user cases. I recall Vertica, for example, offered both an exact and an approximate "count distinct" with very different performance profiles.

To view or add a comment, sign in

More articles by Fawad A. Qureshi

Others also viewed

Explore content categories