Make money doing the work you believe in

Most people think concurrency & parallelism are the same.

They’re not:

===

Concurrency is about switching between different tasks at once.

Parallelism is about handling many tasks at once.

===

Concurrency creates an illusion of parallel execution.

Yet the performance drops when the task count increases.

===

Why?

Because each task has to wait for its turn.

The CPU-intensive tasks run efficiently with parallelism.

But parallelism doesn't guarantee performance because tasks need coordination for independent execution.

i.e., neither alone is enough to build scalable and high-performance systems.

===

So how do you scale?

You combine them.

Here's how:

===

1. Synchronization techniques:

→ Use synchronization primitives to coordinate access to a shared resource.

→ Mutex allows only 1 thread to access the shared resource at a time.

→ Semaphore limits the number of threads accessing a shared resource at a time.

===

2. Lock-free mechanism:

→ Go programming language allows building concurrent and parallel solutions without explicit locking mechanisms.

→ Goroutines are lightweight threads that run functions concurrently or in parallel.

→ Channels are built-in thread-safe communication tools that let goroutines communicate without sharing memory.

===

3. Software architecture:

→ It's necessary to architect the system for concurrency and parallelism.

→ A load balancer uses non-blocking I/O or a thread pool to avoid connection queuing.

→ A server uses event-driven or multi-threading models to handle requests efficiently.

===

Remember, a system in which all tasks run in parallel and stay busy at all times has the highest throughput.

What else would you add?

May 24
at
12:53 PM
Relevant people

Log in or sign up

Join the most interesting and insightful discussions.