Archive for the 'Concurency' category

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

Performance Evaluation on Java Thread and .NET Thread

01 Mar 2011 by

Performance evaluation on Java single thread and multi-thread has already been discussed in the previous post. So I will show you all the performance of .NET thread comparable to Java thread. We did the same scenario and experimental environment as my last post. The overall Java performs much better than .NET both single thread and multi-thread.

Continue Reading »

No responses yet

Performance Evaluation on Single Thread and Multi-Thread

27 Feb 2011 by

Threading could eventually improve system capacity as multi-core and multi-processor are more common in commodity computer. We can spend less than USD 1000 to get Core-i3, Core-i5 or even Core-i7. So threading technique for enabling-threading tasks could maximize the overall system performance. Be remember that not all tasks could take advantage of multi-threading. And multi-thread is not always good since its overhead and cost in coordinating data. I will discuss this scenario in the later post.

Continue Reading »

One response so far

How to Return a Value from Thread

26 Feb 2011 by

Thread implementation in Java is never easier if you do following my 3 steps strictly. However, there might be a lot of question regarding return value from a thread since run() method returns void. So I will show you how to get return value from a thread.
Just to review how to implement java thread, the 3 steps are:

  1. Extends Thread class or Implements Runnable interface
  2. Override run() method
  3. In main thread, initialize thread class and then call start() method

Continue Reading »

5 responses so far

Implement Thread in Java

25 Feb 2011 by

Assume that you understand the differences between Process and Thread. If not please refer to this article (Process vs. Thread). Concurrency can be achieved both in Process and Thread. Developing concurrency process is costly and hard to manage the process behavior since all processes have their own address space. Thread has been motivated in this sense. Thread can take a lot of advantages by supporting parallelism, low cost in creating and destroying, and easy to manage. Be remember that main thread in a process can create several child threads.

Continue Reading »

One response so far

Process vs. Thread

24 Feb 2011 by

Process and Thread are two unit of executions that are not the same in the sense of executing environment. These two terms often are used confusingly. This article will clear all the doubts.

Process

Process is a compiled program requires CPU to execute its instructions and also requires its own memory space for storing its executing environment. If we peep into the memory of computer, Process can be divided at least into 3 segments:

  • Text segment: storing program code
  • Heap: storing global data
  • Stack: storing local data
Process segmentation in computer memory

Process Segmentation

The purpose of segmentation in memory is to distinguish between instruction and data. Let’s say 0xA2 in hexadecimal. If it is stored in Text Segment, it is MOV instruction. On the hand, if it is stored in Heap or Stack, it equals 162 in decimal.

Some main feature of Process:

  • Has its own memory space
  • Has its own unique process ID
  • Creating and destroying Process is cost heavily
  • Communication between processes is done based on Inter-Process Communication (IPC) or pipe (UNIX-like system)

Thread

Thread sometimes is called light weight process. However, it has some unique features making it differences from Process.

Some main feature of Thread:

  • Thread exists within a process
  • Every process has at least one thread called main thread
  • The main thread has an ability to create additional threads
  • Thread share process’s resources, including memory, open files, socket. This makes efficient in communication among each other but giving some sorts of potential problematic. This problem will be discussed in Mutual Exclusion.
Threads exist in a Process and share Process's resources

Process and Thread

2 responses so far