5/01/2009

Exercise 19

Exercise 19: TP monitors and transaction protocols

1. Give a description in your own words of the ACID properties of a transaction.

ACID is stands for Atomicity, Consistency, Isolation, and Durability. Actually ACID properties provide a high processing reliabilty to transaction. For example, Atomicity is the operation sequence which must be an atomic, either all or no operations are performed; Consistency is the the operation which must leave data consistently, and all defined relations must be maintained.
Isolation let the transaction separate from all other transactions. Durability is the operations which are permanently placed on the system.

2. Describe a TP monitor environment. How can a TP monitor stop an operating system being overwhelmed?

TP monitor is stands for TeleProcessing monitor or Transaction Processing monitor, encyclopedia2 (2009) states that it a control program that manages the transfer of data between multiple local and remote terminals and the application programs that serve them. It may also include programs that format the terminal screens and validate the data entered.In a distributed client/server environment, a TP monitor provides integrity by ensuring that transactions do not get lost or damaged. It may be placed in a separate machine and used to balance the load between clients and various application servers and database servers. It is also used to create a high availability system by switching a failed transaction to another machine. A TP monitor guarantees that all databases are updated from a single transaction.

3. What is difference in load balancing with traditional and transactional MOM, RPC and conversations?

Qusay H. Mahmoud (2004) tell me that RPC calls require more bandwidth than a similar MOM interaction. Bandwidth is an expensive performance overhead and is the main obstacle to scalability of the RPC mechanism. The RPC model is designed on the notion of a single client talking to a single server; traditonal RPC has no built-in support for one-to-many communications. The advantage of an RPC system is the simplicity of the mechanism and straightforward implementation. The advantage that has over MOM is the guarantee of sequential processing. With the synchronous RPC model, you can control the order in which processing ocurs in which processing occurs in the system. For example, in an RPC system you can be sure that at any one time all the new orders received by the system have been added to the database and that they have been added in the order of which they were received. However, with an asynchronous MOM approach this cannot be guaranteed, as new orders could exist in queues waiting to be added to database. This could result in a temporal inaccuracy of the data in the database. We are not concerned that these updates will not be applied to the database, but that a snapshot of the current database would not accurately reflect the actual state of orders placed. RPC is slow but consistent; work is always carried out in the correct order. These are important considerations for sections in a system that requires data to have 100% temporal integrity.

In conclusion, the RPC model is ideal if you want a strongly typed/object-oriented (OO) system with tight coupling, compile-time semantic checking and an overall more straightforward system implementation. In contrast, if the distributed systems will be geographically dispersed deployments with poor network connectivity and stringent demandss in reliability, flexibility and scalability, then MOM is the ideal solution.

4. Why is a two-phase commit protocol better than a one-phase atomic commit protocol?

I find useful tuturial from Agora (2007) and it tells me that

In a one-phase commit protocol, the coordinator communicates commit or abort to all participants until all acknowledge.
  • When a client/coordinator requests a commit, it does not allow a server to make a unilateral decision to abort a transaction.
  • A server may have to abort the transaction, for example, in the case of deadlock.

In a two-phase protocol, any participant can abort its part of the transaction. Transaction is committed by consensus.

  • When the client asks the coordinator to commit the transaction, the two-phase commit protocol is executed.

After reading that powerpoint, i find there is a serious problem in one-phase commit protocol that if a process cannot perform the operation, there's no way to tell the coordinator! In contrast, two-phase commit protocol has a well communication that is better than one-phase commit protocol, which avoids from this scenario.

Referances:

Encyclopedia2 (2009). "TP monitor". Received 5th May, 2009 from URL - http://encyclopedia2.thefreedictionary.com/TP+monitor

Qusay H. Mahmoud (2004). When to use MOM or RPC. Middleware for communications.John Wiley and Sons Publishers (p7)

Agora (2007). " Lecture 12 -Distributed transcations".Received 5th May, 2009 from URL - https://agora.cs.illinois.edu/download/attachments/26989/lect-12.ppt

Execise 18

Exercise 18: Threading demonstration in Python.

A simple demonstration of the threading module in Python that used both a lock and semaphore to control concurrency is by Ted Herman at the University of lowa. The code and sample output below are worth a look. Report your findings.


I download the threaddemo.py script from CSU and execute it in my PC. However, when I am executing it, it prompts out many unexpected errors. Finally, I need to downgrade the version of Python from 2.5.4 to 2.3.2. And now, i can test it in my PC successfully (see figure 1), I suspect that it may be caused by different syntax between verison 2.5.4 and 2.3.2.
























Figure 1.

From the source code, I get some findings which are listing as follow:

Finding 1, thread ID is limited starting from 0 to 9.

Finding 2, variable named delay that is used to control the processing time of thread within 2 seconds.

Finding 3, variable named sema that is a threading semaphore and it is predefined running maximum 3 threads each time (sema = threading.BoundedSemaphore(value=3)).

Finding 4, variable named mutex that is used to create the read lock for the thread (mutex = threading.RLock()).

Finding 5, method named acquire(), it takes an optional wait flag, which can be used to avoid blocking if the lock is held by someone else.

Finding 6, variable named running that is used to count the number of running threads.

Finding 7, each time when TestThread() is running, console will print out a thread ID and the expected running time. Then the method named sema.acquire() will check the thread number whether is over 3 or not, if no, mutex will create a read lock for the waiting thread, then adding 1 to the variable named running.

Finding 8, when one of three thread has been running completely, mutex will release the read lock of that thread and update the value of variable named running by subtracting 1, then print out that task had been done. Afterwards, one of waiting thread will be locked. This processes are running in loop until 10 threads have run completely.




4/30/2009

Exercise 17

Exercise 17: Concurrency terms Find definitions for eight terms and concepts used in threaded programming:

1. Thread Synchronisation
Thread synchronization requires that a running thread gain a "lock" on an object before it can access it. The thread will wait in line for another thread that is using the method/data member to be done with it. This is very important to prevent the corruption of program data if multiple threads will be accessing the same data. If two threads try to change a variable or execute the same method at the same, this can cause serious and difficult to find problems. Thread synchronization helps prevent this. (
http://wiki.answers.com/Q/What_is_Thread_Synchronization )


2. Locks
To make a file or other piece of data inaccessible. File locking is a critical component of all multi-user computer systems, including local-area networks. When users share files, the operating system must ensure that two or more users do not attempt to modify the same file simultaneously. It does this by locking the file as soon as the first user opens it. All subsequent users may read the file, but they cannot write to it until the first user is finished. In addition to file locking, many database management systems support record locking, in which a single record, rather than an entire file, is locked. This enables different users to access different records within the same file without interfering with one another. (
http://www.webopedia.com/TERM/L/lock.html )

3. Deadlock
A condition that occurs when two processes are each waiting for the other to complete before proceeding. The result is that both processes hang. Deadlocks occur most commonly in multitasking and client/server environments. Ideally, the programs that are deadlocked, or the operating system, should resolve the deadlock, but this doesn't always happen. A deadlock is also called a deadly embrace. (
http://webopedia.com/TERM/D/deadlock.html )

4. Semaphores
A hardware or software flag. In multitasking systems, a semaphore is a variable with a value that indicates the status of a common resource. It's used to lock the resource that is being used. A process needing the resource checks the semaphore to determine the resource's status and then decides how to proceed. (
http://webopedia.com/TERM/s/semaphore.html )

5.Mutex (mutual exclusion)
In computer programming, a mutex is a program object that allows multiple program threads to share the same resource, such as file access, but not simultaneously. When a program is started, a mutex is created with a unique name. After this stage, any thread that needs the resource must lock the mutex from other threads while it is using the resource. The mutex is set to unlock when the data is no longer needed or the routine is finished. (
http://webopedia.com/TERM/m/mutex.html )

6. Thread
In programming, a part of a program that can execute independently of other parts. Operating systems that support multithreading enable programmers to design programs whose threaded parts can execute concurrently. (
http://webopedia.com/TERM/t/thread.html)

7. Event
An action or occurrence detected by a program. Events can be user actions, such as clicking a mouse button or pressing a key, or system occurrences, such as running out of memory. Most modern applications, particularly those that run in Macintosh and Windows environments, are said to be event-driven, because they are designed to respond to events.
(
http://webopedia.com/TERM/e/event.html )

8. Waitable timer

A waitable timer object is a synchronization object whose state is set to signaled when the specified due time arrives. There are two types of waitable timers that can be created: manual-reset and synchronization. A timer of either type can also be a periodic timer.


A thread uses the CreateWaitableTimer or CreateWaitableTimerEx function to create a timer object. The creating thread specifies whether the timer is a manual-reset timer or a synchronization timer. The creating thread can specify a name for the timer object. Threads in other processes can open a handle to an existing timer by specifying its name in a call to the OpenWaitableTimer function. Any thread with a handle to a timer object can use one of the wait functions to wait for the timer state to be set to signaled.

A thread can use the CancelWaitableTimer function to set the timer to the inactive state. To reset the timer, call SetWaitableTimer. When you are finished with the timer object, call CloseHandle to close the handle to the timer object.

(http://msdn.microsoft.com/en-us/library/ms687012(VS.85).aspx)



Exercise 16-2

5. Get the latest PGP software from http://web.mit.edu/network/pgp.html; install it on two machines and encrypt a message on one machine and decrypt it on the other. Report your findings.

When i access to the MIT web site, it displays an error that is "The version of PGP available from MIT was significantly out of date and doesn't run on newer computers (at least not reliably)." So i download the PGP softwar from PGPI web site (
http://www.pgpi.org/products/pgp/versions/freeware/winxp/8.0/ )

Then, i apply 30 days trial license (DKLHX-P24TA-3JWW5-CAJ2W-6XGF9-DKC) in PGPI web site. When i have installed the pgp software and i find that the pgp software blocks my internet connection, so that, i can't do that test for you.

But I can try to explain my understand for you, the procedure as follows:
1. In your PC, use PGP software to generate a new PGP key (see figure 2 and 3).
2. In your PC, use PGP software to encrypt a file (see figure 4) with secure user key.
3. In your PC, use PGP software to export Key to File and transfer the Key to the recipient's computer.
4. In the recipient's PC, open PGP software and select "Import" button to import the received Key.
5. In the recipient's PC, use PGP software for signing the imported key and input the correct passphrase for KEY verification.
6. In the recipient's PC, open PSP software and select the encryted file, then click the "decrypt and verify" button for file decryption.
That'all!
Figure 2.
Figure 3.
Figure 4.
===============================================
6. The use of digital certificates and passports are just two examples of many tools for validating legitimate users and avoiding consequences such as identity theft. What others exist?
Besides use of digital certificates and passports for validating legitimate users and avoiding consequences such as identity theft, we can use (1) digital signature which is an electronic signature created using a private signing key, (2) biometrics which use physiological or behavioural characteristics to identify an individual and (3) soft token which is an e-authentication mechanism that is stored in a computer.