Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
11 views9 pages

3358 Sample Final Part1 Empty

The document contains a series of questions and answers related to computer science concepts, including messaging types (synchronous and asynchronous), Java RMI, ACID properties, Amdahl's Law, consistency models, MapReduce, Raft, and two-phase commit. Each question is answered concisely, providing definitions and examples where applicable. The content is structured as a university assignment for a computer science course.

Uploaded by

dave
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)
11 views9 pages

3358 Sample Final Part1 Empty

The document contains a series of questions and answers related to computer science concepts, including messaging types (synchronous and asynchronous), Java RMI, ACID properties, Amdahl's Law, consistency models, MapReduce, Raft, and two-phase commit. Each question is answered concisely, providing definitions and examples where applicable. The content is structured as a university assignment for a computer science course.

Uploaded by

dave
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
You are on page 1/ 9

THE UNIVERSITY OF HONG KONG

FACULTY OF ENGINEERING
DEPARTMENT OF COMPUTER SCIENCE

COMP3358

Question 1. Basic concepts. Each answer should contain no more than 50 English
words.
(a) What type of messaging is provided by JMS?
Answer:
JMS provides both type of messaging,
synchronous
Asynchronous

(b) What do you mean by Synchronous and Asynchronous type of messaging?


Answer:
Synchronous: In this type of messaging, client waits for the server to respond to a
message. Ex: Telephone call, two way radio communication.

Asynchronous: In this type of messaging, client does not wait for a message from
the server, but automatically an event is created to trigger a message from a server.
Ex: email, text messaging, blog posting.

(c) The purpose of the two-phase commit protocol is to ensure that:


Answer:
Transactions in a distributed database provide all-or-nothing atomicity, just like
transactions in a single-site database.
If one site ABORTs while processing part of a distributed transaction t, all other
sites processing part of t will also ABORT t.

(d) What is Java RMI?


Answer:
The Java Remote Method Invocation (Java RMI) is a Java API that performs the object-
oriented equivalent of remote procedure calls (RPC), with support for direct transfer of
serialized Java classes and distributed garbage collection. Remote Method Invocation
(RMI) can also be seen as the process of activating a method on a remotely running object.
(e) What is the role of stub in RMI ?
Answer:
A stub for a remote object acts as a client’s local representative or proxy for the
remote object. The caller invokes a method on the local stub, which is
responsible for executing the method on the remote object. When a stub’s
method is invoked, it undergoes the following steps (similar to RPC):
• It initiates a connection to the remote JVM containing the remote object.
• It marshals the parameters to the remote JVM.
• It waits for the result of the method invocation and execution.
• It unmarshals the return value or an exception if the method has not been
successfully executed.
• It returns the value to the caller.

No atomic clock in the final (too complicated and expensive)


Q1 is always about basic concepts
Questions 2. Amdahl’s Law.
Assume 1% of the runtime of a program is not parallelizable. This program is run on
61 cores of a Intel Xeon Phi. Under the assumption that the program runs at the same
speed on all of those cores, and there are no additional overheads, what is the parallel
speedup?
Answer:
Amdahl’s law assumes that a program consists of a serial part and a parallelizable
part. The fraction of the program which is serial can be denoted as B — so the
parallel fraction becomes 1 − B. If there is no additional overhead due to
parallelization, the speedup can therefore be expressed as

Since B = 0.01, n = 61, S(61) = 38.125


Question 3. Transactions [10 marks]
a. ACID is a collection of four properties provided by database transactions. For each
of the four, give a one or two sentence definition of what that term means. Please be
very brief, but precise.
Answer:
Atomicity. In a transaction involving two or more discrete pieces of information,
either all of the pieces are committed or none are.
Consistency. A transaction either creates a new and valid state of data, or, if any
failure occurs, returns all data to its state before the transaction was started.
Isolation. A transaction in process and not yet committed must remain isolated from
any other transaction.
Durability. Committed data is saved by the system such that, even in the event of a
failure and system restart, the data is available in its correct state.

b. A database is used in a ticketing system. Ticket purchase consists of the following


steps:
display available seats
choose a seat
update the database to indicate that the seat is sold
dispatch the ticket

With reference to these steps, write down a interleaving on how two people might
both buy a ticket for the same seat. Part of the interleaving has been shown:
Transactio n 1 Transaction 2 Notes
display available seats Seat B2 (e.g.) is available
display available seats B2 still available
choose a seat (choose B2) B2 still available
choose a seat (choose B2) B2 still appears
available
update the database to indicate B2 sold B2 sold
update the database to indicate B2 sold B2 sold
dispatch ticket for B2 ticket for B2 dispatched
dispatch ticket for B2 ticket for B2 dispatched

With reference to your answer to part b of this question, briefly explain how each of
the four ACID properties has been violated.
Answer:
• Atomicity: transaction 1 is effectively incomplete, because transaction 2 has
overwritten its effect.
• Consistency: two people have booked the seat, but only one booking is
recorded in the database.
• Isolation: both transactions update the same location; transaction 1 is not
isolated from transaction 2.
• Durability: the effects of transaction 1 have not endured because they have
been overwritten by transaction 2.
Question 4. Consistency Models
Conventions we will use:
• W(x)a means “a write to x with value a”
• R(y)b means “a read from y that returned value b”
• “processor” used generically
Consistency the write and read values for the four processors below.
P1: W(x)1 W(x)3
P2: R(x)1 W(x)2
P3: R(x)1 R(x)3 R(x)2
P4: R(x)1 R(x)2 R(x)3
Question: is this weak consistency or sequential consistency? Any why?
Answer:
Weak consistency. P3 and P4 read different results finally.
Question 5: Map-reduce
Using WordCount implementation via Hadoop framework, we will count the words in
all the input file flow as below.

Assume there are two files each having a sentence


Hello World Hello World (In file 1)
Hello World Hello Hello (In file 2)

Suppose there will be each mapper for each file.


(a) For the given sample input file1, the first map’s output:
Answer:
< Hello, 1>
< World, 1>
< Hello, 1>
< World,
1>

(b) The second map output:


Answer:
< Hello, 1>
< World, 1>
< Hello, 1>
< Hell
o, 1>

(c) The reducer output:


Answer
< Hello, 5>
< World

, 3>
Question 6. Raft.
Consider the Raft replication system. Suppose you have a five-server (S1~S5) Raft
system. Here’s the state of the servers’ logs. The notation T.N means the Nth log entry
from term T. The servers are about to choose a new leader.
State:
S1: 3.1 4.1
S2: 3.1 3.2
S3: 3.1 5.1
S4: 3.1 5.1 5.2
S5: 3.1

(a) Could any replica have already executed the operation in log entry 5.1? If yes,
explain how this could have happened. If no, explain why it could not have
happened.
Answer:
N

o. An operation cannot execute if it is not in a majority of logs.

(b) Could operation 4.1 be committed in the future? (Assume that the client does not
re-transmit the operation.) If yes, how could that happen? If no, why not?
Answer:

es. S1 may become the next leader with a majority from S1, S2, and S5.
Question 7: Two-phase commit.
Sam is building a replicated storage system. There is just one client, and the client
performs just one storage operation (read or write) at a time, waiting for each
operation to complete before starting the next. Sam wishes to store the data on two
servers in order that the system be available (that it continue operating) even if
one server fails. He wants to ensure that the data on the two servers stay identical,
and is worried about the possibility that only one of the two servers might execute
a client write. Sam wonders whether making the writes at the two servers atomic
using two-phase commit would be a good idea, to ensure both-or-nothing
behavior.
In the design he has in mind, the client would execute a write as described below:
client sends write RPCs to server1 and server2
client waits for replies to both write RPCs
client sends prepare messages to server1 and server2
if both repond "yes"
client sends commit messages to server1 and server2

Sam thinks about this design for a while, and eventually realizes that two-phase
commit is fundamentally not suited to providing availability via replication.
Please explain why.
Answer:
If one of the two servers is down, two-phase commit will abort every write; this
defeats Sa

m’s goal of availability.

You might also like