-
Notifications
You must be signed in to change notification settings - Fork 0
Distributed Systems
SingleCall
Every incoming request will get a new instance of the defined type created to handle that call. Each instance will have its own memory space and instance variables, but they can still share static and global variables, external resources, files, network connections, etc.
Singleton
One instance is created for all incoming requests, so by definition, every instance variable in use within that singleton is, in fact, shared among all incoming requests and clients.
Marshal by value
Marshal by reference
1) In a distributed application based on a client/server model, what are the advantages and disadvatages of using as intermediary between a client and a server a middleware of shared space (tuple space).
Advantages:
- It is not required that both the client and the server are active simultaneously.
- Load balancing and failure tolerance since it is possible to add and remove servers in a way that the client will not even notice.
- Application design is easier since concurrent access and transactions will be guaranteed by the tuple space.
Disadvantages:
- Overhead due to indirection in the communication between clients and servers.
- Bottleneck can be created accessing the space.
- Difficult to maintain the consistency between multiple spaces or even having the notion of distributed tuple space.
2) Considering the following classes and that you pretend to use them in a .Net Remoting server, what changes should be made and which activation mode (Singleton or Singlecall) should be used on the server configuration? (Method implementation is not required)
public class Server {
void insert(Book book) { // inserts a new Book in the DB }
Book getBook(string key) { // searches a Book in the DB }
}
public class Book { public string title; public string key; }
Initially a separation can be made of the implementation and exposed interface as such: IServer with the exposed methods and Server with the implementations and state if necessary.
The Server class should extend MarshalByRefObject, server state needs to be shared between clients and as such marshal by value would not serve our needs. This class should also be the one responsible for keeping the state (each added and removed book) and implement IServer.
If the activation were to be Singlecall the server would not be able to keep state between method calls (a new instance is created in each method call), which would not allow for instance, the insertions of a book and a request of the same book afterwards. This leaves us with Singleton which allows which allows for several clients to use the same server state.
The Book class should also be serializable.
3) Justify the advantage, in .NET Remoting, of invoking assynchronously multiple operations with an high execution time, in a server implemented with a remote object in Singlecall activation mode.
Singlecall prevents the system from blocking due to waiting time as each of the calls to the method will generate a new instance. If it were to be Singleton the clients would be sharing the same instance and therefore waiting for eachother.
4) In .Net Remoting, if a method call of a server receives as a parameter an object that is a MarshalByRefObject what measures should be made in the channel configuration on the server side?
The serialization level is by default low, and as such it cannot serialize automatically every object, only primitive known types. This should be changed to full on the type filter level configuration.
5) Consider a distributed system constituted by 4 processes (p0, p1, p2, p3), that uses multicast communication and a mechanism based on vector clocks that guarantees causal order of messages.
The local clocks states are:
- p0 = [7,2,5,1]
- p1 = [7,2,4,1]
- p2 = [6,2,5,1]
- p3 = [7,2,5,2]
Knowing that p0 is about to send a multicast message, what is the vector of clocks that will be sent and justify what happens upon message reception on p1, p2 and p3.
The conditions that guarantee causal ordering are:
j - emiting process
1 - Vm[j] = Vk[j]+1
2 - Vm[i] <= Lk[i] for every i != j
The ordered vectors are:
P0 | P1 | P2 | P3 |
---|---|---|---|
7 | 7 | 6 | 7 |
2 | 2 | 2 | 2 |
5 | 4 | 5 | 5 |
1 | 1 | 1 | 2 |
Because P0 is the sender process its coordenate is incremented to 8. The sent vector is p0 = [8,2,5,1] and the table changes to:
P0 | P1 | P2 | P3 |
---|---|---|---|
8 | 7 | 6 | 7 |
2 | 2 | 2 | 2 |
5 | 4 | 5 | 5 |
1 | 1 | 1 | 2 |
The remaining vectors change in the following way:
P1 : Message on hold, because 4 > 5 and that breaks rule 2.
P2 : Message on hold because 6 + 1 < 8, breaks rule 1.
P3 : Is ok.
6) What is the consequence of defining a WCF service as follows, knowing that multiple clients will be accessing it concurrently.
[ServiceBehavior (InstanceContextMode=InstanceContextMode.Single, ConcurrencyMode = ConcurrencyMode.Single)]
public class SomeService : ISomeContract { …. }
There are two aspects to consider in the code's configuration, InstanceContextMode and ConcurrecyMode.
- Instance Context Mode
because single was the chosen configuration, only one instance will be shared amongst every client (Singleton). - Concurrency Mode
The problem is created by the context when used with the single concurrency mode. This means that only one client at a time might access the shared instance and as such, multiple clients will always be waiting for the one who is using the instance at a certain time. To solve this a simple change to ConcurrencyMode.Multiple would suffice, allowing for multiple conccurrent accesses to the shared instance.