SeriesOperating Systems6 / 16

Thread Performance

Module 6 of CS 6200 - Graduate Introduction to Operating Systems @ Georgia Tech.

Considerations#

Performance Case Study#

We can evaluate thread performance from one of many perspectives. For example, let’s compare the performance of two multi-threading architectures: the boss-worker and pipeline patterns.

thread-performance

(image should show 5 worker threads, not 6)

This case illustrates that our multi-threading design choices are highly important on the context of the problem. For example, are we more interested in processing more orders given time, or enhancing user experience by reducing wait times per order?

Metrics#

In the context of multi-threading, we are typically interested in one of the following performance metrics:

In analysis systems, our metrics should be measurable and/or quantifiable. The metric should be used to evaluate some aspect of our system’s behavior.

thread-metrics

Evaluating Thread Utility#

Can we demonstrate that threads are useful in the context of any performance metric(s)? Recall that concurrency can be provided via multiple threads, or multiple processes. We will compare these implementations for a simple web server described as follows.

Web Server Overview#

As part of our simple web server, we have a few key steps…

  1. Client/browser sends request.
  2. Web server accepts request.
  3. Server performs processing steps.
  4. Server responds to client by sending file.

… where server processing groups together a sequence of many operations.

web-server

We can implement a multi-process (MP) web server by having multiple instances of the “processing steps” portion of the workflow. The cons with this approach include 1) high memory usage (on a per-process basis), 2) costly context switching, and 3) expensive inter-process communication requirements.

Alternatively, we could develop the web server as a multi-threaded (MT) application by having each thread perform the sequence of processing steps in parallel. The MT approach implies 1) a shared address space, 2) shared state, and 3) cheaper context switching. There are cons in terms of 1) program complexity and 2) synchronization considerations.

Event-Driven Model#

We can also make alternative program design choices instead of writing our program as a sequence of operations. The Event-Driven Model relies on events and an event dispatcher - given a certain event, the event dispatcher will call the appropriate handler to execute pre-specified code for the event. For a single-threaded single process program, this implies execution will jump to the start of the event handler.

event-driven

How can we apply concurrency within the event-driven model? Unlike the MP or MT approaches, event-driven models specifically avoid dedicated process / thread assignment (e.g., assigning each request to an execution context). Instead, the event-driven approach interleaves requests within the same execution context.

  1. Event Loop: server runs a loop that waits for events (e.g., new connection or file input).
  2. Non-Blocking I/O: when a request hits a slow operation (such as I/O), the server initiates the operation but does not wait. It instead switches to process the next request int he queue.

Why is this beneficial over the MP / MT approaches?

Furthermore, asynchronous system calls for slow events such as I/O operations can improve process efficiency. As part of an asynchronous operation, the process makes a system call and supplies any additional data structures to hold results. The process then continues while a kernel thread / device performs the operation, and eventually returns requested information to the caller once complete. In the case where asynch is not supported, we can manage this task ourselves using MP or MT with respect to blocking operations. Asymmetric Multi-[Process\Threaded] Event-Driven Model (AMPED/AMTED) exemplifies this sort of implementation.

Example Web Servers#

Flash is an event-driven web server which follows the AMPED model. It uses helper processes to perform blocking I/O tasks, and event dispatchers + handlers for the primary functionality.

In contrast, the popular Apache web server combines MP and MT architecture into a single application. The core of Apache is a basic server skeleton; additional per-functionality modules are added on an as-needed basis. Apache uses multiple processes, with each process following a boss-worker thread pattern with dynamic thread pool.

Flash Paper + Experimental Methodology#

The Flash Paper (1999) introduced AMPED architecture via Flash, and evaluated it relative to many other web server types:

The authors defined trace and synthetic workloads to evaluate the web servers in terms of bandwidth and connection rate (as a function of file size). They made the following observations:

  1. When data is in cache (implying no I/O blocking)…
    • SPED >> AMPED Flash \rightarrow Flash tests for memory presence.
    • SPED and AMPED Flash >> MP / MT \rightarrow additional overhead from context switching / synchronization.
  2. When the workload is disk-bound…
    • AMPED Flash >> SPED \rightarrow SPED blocks b/c no synchronous I/O.
    • AMPED Flash >> MP / MT \rightarrow more memory efficient + less context switching.

(all images obtained from Georgia Tech GIOS course materials)

License

CC BY-NC-SA 4.0 This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

Related Posts