Archive for the 'Distributed Systems' category

Semaphore: Mutual Exclusion in Single System

29 Mar 2011 by

Semaphore

Semaphore

Mutual Exclusion is required both in single system and distributed systems to protecting the shared resource from being modified concurrently. In this article, we will discuss the mutual exclusion in single system by using Semaphore. Finally we will follow by giving Java example. Before reading this article, it is highly recommended you read the Principle of Mutual Exclusion.

Semaphore

Semaphore is a flag that railroad engineers would use when trains enter a shared track. Semaphore here refers to a mechanism to ensure only one thread or process to access a shared resource. To implement semaphore in Java, synchronized(this) keyword should be used to surround critical section. The code from previous article will look like this.

Global variables

int x = 6;
int y = 0;

FooThread

void foo(){
  synchronized(this){
    x++;
    y = x;
  }
}

BarThread

void bar(){
  synchronized(this){
    y++;
    x += 3;
  }
}

Continue Reading »

2 responses so far

Principle of Mutual Exclusion

28 Mar 2011 by

Mutual Exclusion is a process that prevents multiple threads or processes from accessing shared resources at the same time. The problem is coming from the fact that in both distributed systems and single system, several threads or processes share a resource but cannot use it concurrently. Mutual Exclusion, Synchronization and Data Coordination are commonly use interchangeably; or just MUTEX for short.

Rationale

This will guide you to the root of the problem and give you solution.

Let see the two blocks of code that runs in parallel called foo() and bar().

The initial state: x=6 and y=0.

FooThread

void foo()
{
   x++;
   y = x;
}

BarThread

void bar()
{
   y++;
   x += 3;
}

Continue Reading »

2 responses so far

Java RMI Database Application

20 Mar 2011 by

Java RMI Database Application

Java RMI Database Application

Java RMI has been introduced to reduce the complexity in developing protocol that relies on UDP and TCP. Java RMI provides a simpler mechanism to invoke method remote. Here I will discuss the development of Java RMI with database application. This sample application is layered into 3 tier: client, RMI server or middleware, and database.

Client is very thin and lightweight. Here client is only responsible for user interface while large business processes are handed over to RMI middleware. The middleware contains server objects distributed in registry service. The client will lookup the entire object from the registry service and invoke methods remotely. Database server stands on another layer that will be accessed by the data accessors in RMI middleware.

If you do not understand what Java RMI is, better to have a look on these articles:

Continue Reading »

21 responses so far

Thread Pool

18 Mar 2011 by

Thread Pool

Thread Pool

In previous post you may understand the architecture of single thread and thread per request in distributed systems. Here we will see another architecture called Thread Pool. Thread pool pre-defines a number of thread running in its pool. Let’s say we have 2 threads in the pool, then the server is capable of running only 2 requests at the same time. Other requests must wait in queue until the 2 threads in the pool finish their work. In real world applications, we see a lot of servers fall into this category. For example, Apache web server, IIS server, etc. The advantages and disadvantages are discussed below:

Continue Reading »

No responses yet

Thread per Request

17 Mar 2011 by

Thread per Request/Connection

Thread per Request/Connection

Thread per request or connection has been introduced in order to maximize the system resource and provide responsiveness to users which single thread is not capable. Thread per request or connection architecture will create a thread for each request from a client. In other words, server can create a number of threads as per request. The only limitation is software and hardware capacity. Thread per request is one among thread in distributed systems architecture. This architecture is coming with advantages and disadvantages.

Continue Reading »

No responses yet

Single Thread Server

16 Mar 2011 by

Single Thread

Single Thread

Single thread server is one among concurrency architecture in distributed systems. It is the early stage of distributed systems development. Its footprint is very small and easy to develop. Single thread has an ability to handle only one user a time. The other users must wait in queue until the working user finished his or her task.

If we consider about CPU and I/O usage, single thread is not fully utilized because while CPU is busy I/O usually is free and vice versa.

The development of a single thread server is the same as my example in UDP Programming with Java and TCP Programming with Java.

Advantage

  • Straight forward
  • Easy to develop

Disadvantage

  • Waste time. CPU and I/O are not fully utilized
  • User unsatisfactory because user may wait for getting services
  • May be not exists in real world distributed systems application

 

No responses yet

Thread in Distributed Systems

15 Mar 2011 by

Thread in Distributed Systems

Thread in Distributed Systems

One challenge in distributed systems is concurrency. Without supporting multithread, distributed systems is almost meaningless as it needs to support multiple users. It is typical in distributed systems to have tasks that are partly CPU intensive and partly I/O bound. Generating database query, rendering an image, etc are examples of CPU intensive. Sending files or requests over the network are I/O intensive related to Socket, RMI, etc.

Now we will lookup 3 main architectures that thread impact the performance of distributed systems.

  • Single thread
  • Thread per request or connection
  • Thread pool

Continue Reading »

No responses yet

Parallel and Distributed Computing

13 Mar 2011 by

Parallel and Distributed Computing

Parallel and Distributed Computing

Parallel and Distributed computing can be confused. This article will show you the simplest way to identify.

Parallel Computing

  • Shared memory system
  • Multiprocessor (multiple processors share a single bus and memory unit)
  • Symmetric Multiprocessing (SMP) supports in Operating System
  • Much simpler than distributed system
  • Limited scalability

Distributed Computing

  • Distributed memory system
  • Multicomputer (Autonomous computer nodes connected via network)
  • Share many of challenges
  • Better scalability and cheaper
  • Distributed computing in local network is also called cluster computing while in wide-area networks is referred to grid computing

 

One response so far

Challenges in Distributed Systems

13 Mar 2011 by

Challenges in Distributed Systems

Challenges in Distributed Systems

Designing the distributed systems does not come for free. Some challenges need to be overcome in order to get the ideal systems. The challenges in distributed systems are:

  • Heterogeneity
  • Transparency
  • Openness
  • Concurrency
  • Security
  • Scalability
  • Resilience to failure

Continue Reading »

18 responses so far

Stub and Skeleton

11 Mar 2011 by

Stub and Skeleton

Stub and Skeleton

Java RMI is powerful middleware that replaces raw request/reply method as UDP and TCP. The core technology to make it works is Stub and Skeleton function. Stub is located on the client side while Skeleton is located on server side. The role of stub and skeleton is to do marshalling and unmarshalling meaning that it will squash the argument and return value of a method to be a standard format for storing in a file or transferring over the network. Without Stub and Skeleton, java RMI cannot work.

Note on Stub and Skel files (Skeleton)

  • Java JDK 1.6 does not require to have Stub and Skeleton file (Skel for short) as it takes advantage of reflection to accomplish the task
  • Java JDK 1.5, it requires only Stub file at the client. To generate stub file:
    • rmic PowerServer
    • PowerServer_Stub.class will be generated
  • Java JDK prior to 1.4 (not quite sure), it requires both Stub and Skel files
    • rmic -vcompat PowerServer
    • PowerServer_Stub.class and PowerServer_Skel.class will be generated

2 responses so far