Multi-Threading Is Not Always The Right Answer. Here's Why!
Learn to scale a server using Multithreading, Busy waiting and the Reactor pattern.
Modern software engineering is all about making applications efficient.
Concurrency is thus a critical aspect as modern applications perform multiple tasks simultaneously and maximize hardware utilization.
Let’s learn this better with an example.
We are opening up a small coffee shop and we build a mobile app through which users can place coffee orders online.
Let’s write a simple server that handles these order requests.
from socket import socket, create_server
BUFFER_SIZE = 1024
ADDRESS = ("127.0.0.1", 12345)
class CoffeeServer:
def __init__(self):
try:
self.server_socket = create_server(ADDRESS)
print("Coffee server started at:", ADDRESS)
except OSError:
print("\nCoffee server stopped.")
def accept(self):
conn, client_address = self.server_socket.accept…
Keep reading with a 7-day free trial
Subscribe to Into AI to keep reading this post and get 7 days of free access to the full post archives.