J
jurij
At first we should mention that we have a one-processor, linux-machine
(Kernel 2.6.23) and developing an I/O application using g++.
The problem:
we have a task :"reader" which should read sequentially some data from
a device and fill, for example, 4 buffers with it; additionally we
have another task: "processor", its responsibility is to process data
which it can find in these 4 buffers. Our goal is to design this
schema very optimal from the speed point of view.
In case of sequential procedure we would have the following schema:
r-r-r-r p-p-p-p
It means that the "reader", in order to begin next cycle, would wait
during processing until the last of all 4 buffer will be processed.
Then the next cycle should begin, and so on... Each cycle the "reader"
waits for "processor" and wise-versa.
To avoid this sequential schema and to optimize the speed of the whole
procedure we have designed the multithreading schema as follows:
First we start both threads "reader" and "processor". "reader" reads
the first portion of data and fills the buffer. As soon as the first
buffer is filled with data, "processor" will immediately process these
data, at the same time "reader" will read the next portion of data and
fill the next buffer. We thought, we can realize the following
parallel schema:
r-r-r-r
p-p-p-p
in order to reduce time and to increase the speed of the whole cycle.
Our idea to win time in this cycle is based on the possibility to work
in parallel: of CPU and controller of the hardware-device.
After realization of the multithreading we detected, that the time
needed for the cycle remains the same as in case of sequential, non-
multithreading schema.
Utilizing the multithreading schema, we were awaiting more optimized
time behavior but could not see it. Obviously, during the "reader" is
doing its job, it is blocked; in this time the scheduler could switch
over to "processor" to allow him to process data. In this case we
would have optimized time-behavior.
Question:
Why our multithreading schema described above cannot give us
enhancement in speed?
(Kernel 2.6.23) and developing an I/O application using g++.
The problem:
we have a task :"reader" which should read sequentially some data from
a device and fill, for example, 4 buffers with it; additionally we
have another task: "processor", its responsibility is to process data
which it can find in these 4 buffers. Our goal is to design this
schema very optimal from the speed point of view.
In case of sequential procedure we would have the following schema:
r-r-r-r p-p-p-p
It means that the "reader", in order to begin next cycle, would wait
during processing until the last of all 4 buffer will be processed.
Then the next cycle should begin, and so on... Each cycle the "reader"
waits for "processor" and wise-versa.
To avoid this sequential schema and to optimize the speed of the whole
procedure we have designed the multithreading schema as follows:
First we start both threads "reader" and "processor". "reader" reads
the first portion of data and fills the buffer. As soon as the first
buffer is filled with data, "processor" will immediately process these
data, at the same time "reader" will read the next portion of data and
fill the next buffer. We thought, we can realize the following
parallel schema:
r-r-r-r
p-p-p-p
in order to reduce time and to increase the speed of the whole cycle.
Our idea to win time in this cycle is based on the possibility to work
in parallel: of CPU and controller of the hardware-device.
After realization of the multithreading we detected, that the time
needed for the cycle remains the same as in case of sequential, non-
multithreading schema.
Utilizing the multithreading schema, we were awaiting more optimized
time behavior but could not see it. Obviously, during the "reader" is
doing its job, it is blocked; in this time the scheduler could switch
over to "processor" to allow him to process data. In this case we
would have optimized time-behavior.
Question:
Why our multithreading schema described above cannot give us
enhancement in speed?