<commit_before>P2L5
----


1 - Lesson Preview
==================

.. image:: https://dl.dropbox.com/s/jlheddmy26ubaz8/Screenshot%202018-10-12%2007.08.01.png?dl=0
   :align: center
   :height: 300
   :width: 450

In this lecture, we will contrast several approaches for
structuring applications that require concurrency.
This will include and comparison between multi-process and multi-threaded
approaches, and we talked about both of these already in this course, and
in addition, we will present an alternative, a so-called event driven approach.
We will base the discussion of the event driven model on Vivek Pai's paper,
Flash: An Efficient and Portable Web Server.
This paper describes the event-driven architecture, and
it also includes detailed performance comparisons between a multi-process,
multi-threaded, and an event driven implementation of a web server application.
In addition, these results are put in contrast with Apache,
which is a popular open-source web server.
We will end this lecture with a more generic discussion on how to
structure good experiments.

2 - Which Threading Model is Better?
====================================

.. image:: https://dl.dropbox.com/s/y5utjufo03qnn08/Screenshot%202018-10-12%2007.10.43.png?dl=0
   :align: center
   :height: 300
   :width: 450

During the threads and concurrency lecture, recall that we had a quiz in
which we were comparing the boss-worker model with the pipeline model.
And we did that specifically in one example for six worker threads in
both cases, and for a toy order that consisted of 11 toys.
For the boss-worker model, we said that it takes 120 milliseconds for
a worker to process a toy order.
And then for
the pipeline model we said that it takes 20 milliseconds to complete each of
the pipeline stages, and a full toy order had six pipeline stages.
Let's compare these two models to see which one is better.
The computation that we performed during that homework showed us that regarding
execution time, the boss-worker models took 360 milliseconds for the 11 toy
orders, and the pipeline model took 320 milliseconds for the same 11 toy orders.
Now let's consider something else.
Now let's compare these two models with respect to the average time they take to
complete an order.
To find the average time we have to sum up the times that it took to
complete every single one of the 11 orders, and then divide by 11.
The first five orders took 120 milliseconds to complete.
They were executed by the first group of five threads.
The second five orders were scheduled in the second batch, so
they took twice as long, they took 240 milliseconds to complete.
And then the 11th toy order took 360 milliseconds to complete.
It had to wait, it could only be started until the previous ten orders were
completed in the groups of five plus five threads, each.
So if we compute this, the average time to complete an order for<commit_msg>Updated P2L5.rst<commit_after>P2L5
----


1 - Lesson Preview
==================

.. image:: https://dl.dropbox.com/s/jlheddmy26ubaz8/Screenshot%202018-10-12%2007.08.01.png?dl=0
   :align: center
   :height: 300
   :width: 450

In this lecture, we will contrast several approaches for
structuring applications that require concurrency.
This will include and comparison between multi-process and multi-threaded
approaches, and we talked about both of these already in this course, and
in addition, we will present an alternative, a so-called event driven approach.
We will base the discussion of the event driven model on Vivek Pai's paper,
Flash: An Efficient and Portable Web Server.
This paper describes the event-driven architecture, and
it also includes detailed performance comparisons between a multi-process,
multi-threaded, and an event driven implementation of a web server application.
In addition, these results are put in contrast with Apache,
which is a popular open-source web server.
We will end this lecture with a more generic discussion on how to
structure good experiments.

2 - Which Threading Model is Better?
====================================

.. image:: https://dl.dropbox.com/s/y5utjufo03qnn08/Screenshot%202018-10-12%2007.10.43.png?dl=0
   :align: center
   :height: 300
   :width: 450

.. TODO::
   Understand the problem and then write the solution.

During the threads and concurrency lecture, recall that we had a quiz in
which we were comparing the boss-worker model with the pipeline model.
And we did that specifically in one example for six worker threads in
both cases, and for a toy order that consisted of 11 toys.
For the boss-worker model, we said that it takes 120 milliseconds for
a worker to process a toy order.
And then for
the pipeline model we said that it takes 20 milliseconds to complete each of
the pipeline stages, and a full toy order had six pipeline stages.
Let's compare these two models to see which one is better.
The computation that we performed during that homework showed us that regarding
execution time, the boss-worker models took 360 milliseconds for the 11 toy
orders, and the pipeline model took 320 milliseconds for the same 11 toy orders.
Now let's consider something else.
Now let's compare these two models with respect to the average time they take to
complete an order.
To find the average time we have to sum up the times that it took to
complete every single one of the 11 orders, and then divide by 11.
The first five orders took 120 milliseconds to complete.
They were executed by the first group of five threads.
The second five orders were scheduled in the second batch, so
they took twice as long, they took 240 milliseconds to complete.
And then the 11th toy order took 360 milliseconds to complete.
It had to wait, it could only be started until the previous ten orders were
completed in the groups of five plus five threads, each.
So if we compute this, the average time to complete an order for
{'fraction_non_alphanumeric': 0.060791305824418405, 'fraction_numerical': 0.03226354219731703, 'mean_word_length': 4.374087591240876, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6928898', 'n_tokens_mistral': 1625, 'n_tokens_neox': 1441, 'n_words': 895}