As the demands on computing performance increases, developers need to recognize the impacts of their design decisions and consider concurrent solutions to their complex problems.
Guidelines for Building Concurrent Systems
Article Sep 18, 2017
Rob Keefer
As chip manufacturers add add more cores to their processors, developers must think differently about the software they are building in order to take advantage of the increased processing power.
There are few guidelines to consider when designing a concurrent system:
- When there are two independent functions and you don’t want the failure of one to affect the other, use two different processes - one for each function. A simple example of this is
- When there are two independent functions and you want to prevent the latency of one function to slow the other down, use two different processes. For example, your web browser starts a new process to download a file. With the download process operating separate from the browser itself, the download can take a while but not affect the performance of the browser.
- If you have a message queue, start up a process to handle each message individually. The first time I encountered this, I was working with a team that needed to route data from a robot to a PC and store it in a database. We architected the system in such a way that a master process watched for messages. When the master process received the beginning of a new message, it started a new process to handle the remainder of the message and process the data storage.
A key concept to keep in mind is atomicity. Sometimes you want a series of operations to happen as a unit. Since we don’t know how the operating systems’ scheduler will break up units of work, we may need to explicitly define a function to run the operations without interruption. This explicit method of control is called an atomic function. When a thread performs an atomic function, the other threads view the operations within the function as happening instantaneously.
When you want to define an atomic function, meaning all of the operations occur or nothing happens, you will want to use only one process. For example, when writing to a file, a process should open the file, write to it, and close the file as one ‘atomic’ unit. In a concurrent system where, for some reason, multiple processes can write to the same file, you an independent process should perform the write process for all of the concurrent processes.
As the demands on computing performance increases, developers need to recognize the impacts of their design decisions and consider concurrent solutions to their complex problems. Unfortunately, concurrency is often difficult to manage due to a lack of solid architecture. By keeping these guidelines in mind, you will be on a solid path toward developing concurrent systems.
Looking for a guide on your journey?
Ready to explore how human-machine teaming can help to solve your complex problems? Let's talk. We're excited to hear your ideas and see where we can assist.
Let's Talk