0% found this document useful (0 votes)
15 views5 pages

Single vs Multithreaded File Server Performance

A single-threaded file server can handle about 28.6 requests per second, while a multithreaded file server can handle about 66.6666 requests per second. This is because with multithreading, the waiting time for disk operations can be overlapped, allowing each request to take only 15 milliseconds instead of an average of 35 milliseconds for a single-threaded server.

Uploaded by

Nguyen Huu Long
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views5 pages

Single vs Multithreaded File Server Performance

A single-threaded file server can handle about 28.6 requests per second, while a multithreaded file server can handle about 66.6666 requests per second. This is because with multithreading, the waiting time for disk operations can be overlapped, allowing each request to take only 15 milliseconds instead of an average of 35 milliseconds for a single-threaded server.

Uploaded by

Nguyen Huu Long
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Fullname Question Answer

Nguyễn Hữu Long 11 In this problem you are to


compare reading a file using a In the single-threaded case, the cache hits take
single-threaded file server and a 15 msec and cache misses take 75 msec. The
multithreaded server. It takes 15 weighted average is 2/3 × 15 + 1/3 × 75. Thus,
msec to get a request for work, the mean request takes 35 msec and the server
dispatch it, and do the rest of the can do about (1000/35=28,6) per second.
necessary processing, assuming
that the data needed are in the block For a multithreaded server, all the waiting for the
cache. If a disk operation is needed, disk is overlapped, so every request takes 15
as is the case one-third of the time, msec, and the server can handle
an additional 75 msec is required, (1000/15=66.6666) requests per sec
during which time the thread sleeps.
How many requests/sec can the
server handle if it is single threaded?
If it is multithreaded?

Đào Thái Dương 5. In the text it was stated that the


model of Fig. 2-6(a) was not suited
to a file server using a cache in
memory. Why not? Could each
process have its own cache? 

A file server is a system which is responsible for


managing data files and storage of these at a
central point. It provides the location of the disk
access which is shared by many systems.
Cache memory is a memory which can be
accessed very fast. It can be accessed only by
kernel. Processes in user space can access
limited memory space.

Võ Hồng Thái 17. In a system with threads, is there When user-level threads are used, there is
one stack per thread or one stack typically one stack per thread. Each thread has
per process when user-level threads its own separate stack to store its data, so the
are used? What about when kernel- stack space for each thread is separate from the
level threads are used? Explain. stack of other threads. 

When kernel-level threads are used, the


operating system handles the creation of the
threads, and the process of allocating resources
such as memory and file descriptors. The
operating system typically provides one stack
per thread, so each thread has its own separate
stack. 

In summary, both user-level and kernel-level


threads have one stack per thread, but the
difference is that the operating system handles
the allocation of resources for kernel-level
threads, while user-level threads have to handle
these tasks themselves.

Vũ Danh Long [Link] a sketch of how an A semaphore is a synchronization primitive used


operating system that can disable to control access to a shared resource in a
interrupts could implement concurrent system. An operating system that
semaphore can disable interrupts could implement a
semaphore by using the following steps:

1. Initialize the semaphore to an available


state.

2. When a process requests access to the


shared resource, it first checks the
semaphore.

3. If the semaphore is in an available state,


the process sets the semaphore to an
unavailable state, disables interrupts,
acquires the shared resource, and re-
enables interrupts.

4. If the semaphore is in an unavailable


state, the process goes to sleep until the
semaphore becomes available.

5. When the process has finished using the


shared resource, it disables interrupts,
sets the semaphore to an available state,
and re-enables interrupts.
6. When another process is awakened by
the availability of the semaphore, it can
repeat the above steps to acquire the
shared resource.

This approach ensures mutual exclusion of the


shared resource by disabling interrupts when
accessing the semaphore and acquiring the
shared resource, preventing any other
processes from accessing the shared resource
at the same time.

Đỗ Hồng Quân 29. A fast food restaurant has four As given in the question, the restaurant has
kinds of employees: (1) order takers, different employees for different work roles, such
who take customers’ orders; (2) as, order takers, cooks, specialists of packaging
cooks, who prepare the food; (3) and the cashiers.
packaging specialists, who stuff the
food into bags; and (4) cashiers, who For relating this model to the processes of UNIX,
give the bags to customers and take the detailed explanation is as follows:
their money. Each employee can be
regarded as a communicating It is related to the semaphore design in a UNIX
sequential process. What form of system. They include a wait and signal process.
interprocess communication do they For instance, cooks only cook food when the
use? Relate this model to processes order takers take the orders from the customers.
in UNIX. Alike, cashier only takes money when the order
is packaged by specialists. After the food get
packed, the cashier charges the customer in
return of food. Therefore, there are number of
solutions and sequences take place in their
communication sequential process.

The restaurant is implementing the inter-process


of pipes connection in relation to UNIX because
they transfer messages as order then prepare,
pack and deliver.

Đỗ Hồng Quân 35. Round-robin schedulers normally If a processor occurs more than once in the
maintain a list of all runnable round-robin list, then it will get two turns for each
processes, with each process pass through the list. One reason for allowing
occurring exactly once in the list. this would be to implement a primitive priority
What would happen if a process system since the more times it occurs on the list,
occurred twice in the list? Can you the higher the percentage of time the CPU will
think of any reason for allowing spend on that process
this? 

Nguyễn Hữu Long 41. A process running on CTSS The number of times a process running on
needs 30 quanta to complete. How CTSS must be swapped in, including the first
many times must it be swapped in, time, depends on the time slice (or quantum)
including the very first time (before it assigned to each process.
has run at all)?
If the time slice assigned is greater than 30
quanta, then the process will run to completion
without being swapped out.

If the time slice assigned is less than 30 quanta,


then the process will be swapped out and in
multiple times before it completes. In this case,
the number of swaps can be calculated as
follows:

number of swaps = ceil(30 quanta / time slice) -


1

where "ceil" is the ceiling function which rounds


up to the nearest integer.

So, the number of swaps will depend on the


value of the time slice, and can only be
determined if that value is known.

Võ Hồng Thái 47. Write a shell script that Here is the shell script to produce a file of
produces a file of sequential sequential numbers with locking mechanism to
numbers by reading the last prevent race condition:
number in the file,
adding 1 to it, and then appending #!/bin/bash
it to the file. Run one instance of filename="sequential_numbers.txt"
the script in the background and lockfile="$[Link]"
one in the foreground, each
accessing the same file. How long # function to obtain lock
does it take before a race get_lock() {
condition   while true; do
manifests itself? What is the     ln "$filename" "$lockfile" 2> /dev/null && break
critical region? Modify the script to     sleep 1
prevent the race (hint: use   done
ln file [Link] }
to lock the data file).
# function to release lock
release_lock() {
  rm -f "$lockfile"
}

# obtain lock
get_lock

# critical region starts


last_num=$(tail -n 1 "$filename")
new_num=$((last_num + 1))
echo "$new_num" >> "$filename"
# critical region ends

# release lock
release_lock

In this script, ln "$filename" "$lockfile" is used to


lock the data file. If the lock is successfully
obtained, it will continue with the critical region,
otherwise it will wait until the lock is released
and then try to obtain the lock again. The critical
region is the code block between last_num=$(tail
-n 1 "$filename") and echo "$new_num" >>
"$filename". The lock is released after the critical
region is finished by rm -f "$lockfile".

It is difficult to predict how long it takes before a


race condition manifests itself as it depends on
various factors such as the processing power
and speed of the machine, the load on the
system, etc. However, with the locking
mechanism in place, the race condition will not
occur.

You might also like