Showing posts with label Topic 08. Show all posts
Showing posts with label Topic 08. Show all posts

Tuesday, June 23, 2009

Exercise 19: TP monitors and transaction protocols

  1. Give a description in your own words of the ACID properties of a transaction.
  2. Atomic means that all portions of a transaction will process successfully or none of them will.
    Consistant means that if a transaction is repeated then the same result will eventuate.
    Isolated means that the transaction is not affected by other transactions.
    Durable means that the result are stored permanently.
  3. Describe a TP monitor environment. How can a TP monitor stop an operating system being overwhelmed?
  4. A TP (Transaction Processing) monitor is a complex program which manages the execution of a transaction starting with the client executing the transaction; it will normally employ a number of servers and then return any results to the client. TP monitors carry out two important processes: they manage the concurrent execution of the threads and processes that make up a transaction and ensure that the ACID properties detailed earlier in the chapter are enforced; for example, a TP monitor ensures that when a transaction updates a shared item of data when other transactions wish to access the data then the result of the updating is consistent.(Ince, p365)
  5. What is difference in load balancing with traditional and transactional MOM, RPC and conversations?
  6. According to (Wikipedia) load balancing is a technique to spread work between two or more computers, network links, CPUs, hard drives, or other resources, in order to get optimal resource utilization, maximize throughput, and minimize response time.

    Message-oriented middleware (MOM) is infrastructure focused on message sending that increases the interoperability, portability, and flexibility of an application by allowing the application to be distributed over multiple heterogeneous platforms. It reduces the complexity of developing applications that span multiple operating systems and network protocols by insulating the application developer from the details of the various operating system and network interfaces

    In traditional MOM, messages are addressed to their recipients, although sender and receiver are loosely coupled and need not synchronise to communicate.(IEEE)

    Remote procedure call (RPC) is an Inter-process communication technology that allows a computer program to cause a subroutine or procedure to execute in another address space (commonly on another computer on a shared network) without the programmer explicitly coding the details for this remote interaction.

  7. How can TP Monitors save money?
  8. TP monitors save money by making use of the processer idle time between user requests. This usage relieves the need for purchasing additional hardware for each individual to utilise. It also means that you make the hardware that you do have work more efficiently from a business perspective.
  9. Why is a two-phase commit protocol better than a one-phase atomic commit protocol?
  10. The two-phase commit protocol is better in a distributed environment in that it allows a server to make a unilateral decision to abort a transaction if required.
    (Ince, p361) The description of the protocol is detailed below in steps 3.1 to 3.4. The general rule about aborting or committing a transaction is: 1. If the client requests that a transaction is aborted, for example the client is building up an order in a shopping cart and decides not to complete the order, then the coordinator will inform all the servers involved in the transaction that they should abort. 2. If one of the servers decides to abort a transaction, for example in order to release a lock, then the coordinator informs all the servers involved in the transaction; they will then all abort. 3. If the client asks for a transaction to be committed then the two-phase commit protocol starts and steps 3.1 to 3.4 are carried out. 3.1 The coordinator asks each server whether they can commit. 3.2 Each server decides whether it can commit or not and sends back a reply which indicates the result of its decision. If it cannot commit then it aborts its transaction. 3.3 If all the servers have voted to commit their transactions then the coordinator informs all the servers that they can commit. 3.4 If at least one server cannot commit then the coordinator decides to abort the transaction and sends an abort message to all the servers involved. 4. Those servers which have agreed to commit to a transaction wait for the final decision from the coordinator. This will be either a commit instruction or an abort instruction. They will then act on this.
  11. What is CICS by IBM?
  12. (Ince, p365-366) CICS is a complex TP monitor marketed by IBM. It will:
    • Initiate and destroy threads to carry out transactional operations. Many transaction monitors will access a pool of threads which have been set up when the monitor was started.
    • Manage the resources that are being accessed, for example ensuring that updates are carried out in such a way that the resource does not lend itself in an inconsistent state.
    • Ensure that if a transaction fails then suitable action is taken; this action can be provided by a programmer as code to be executed. In order to do this most TP monitors will use a two-phase atomic commit protocol.
    • Schedule threads so that low-priority transactions, for example batch transactions, are allocated a smaller share of resources than high-priority transactions such as online transactions.
    • Enable the processing load on a distributed system to be shared between a number of servers.
    • Enable a distributed system to function – even in the presence of the failure of one or more servers.

References
IEEE, (2009). Message-Oriented Middleware. Retrieved 9 July 2009, from http://dsonline.computer.org/portal/site/dsonline/menuitem.9ed3d9924aeb0dcd82ccc6716bbe36ec/index.jsp?&pName=dso_level1&path=dsonline/topics/middleware&file=intro_MOM.xml&xsl=article.xsl
Ince, D. (2006). Developing Distributed & E-commerce Applications: Prentice-Hall, Inc. Upper Saddle River, NJ, USA.
Wikipedia. Load balancing (computing). Retrieved 9 July 2009, from http://en.wikipedia.org/wiki/Load_balancing_(computing)
Wikipedia. Message-oriented middleware. Retrieved 9 July 2009, from http://en.wikipedia.org/wiki/Message-oriented_middleware
Wikipedia. Remote procedure call. Retrieved 9 July 2009, from http://en.wikipedia.org/wiki/Remote_procedure_call

Exercise 18: Threading demonstration in Python

A simple demonstration of the threading module in Python that uses both a lock and semaphore to control concurrency is by Ted Herman at the University of Iowa.

I have looked at the code and the output.

The microsoft subjects that form part of this course also deal with threading issues, required us to understand concurrency and enabled us to think about threadsafe practices.

Exercise 17: Concurrency terms

Find definitions for eight terms and concepts used in threaded programming:
  1. Thread Synchronization
  2. (msdn)Synchronization provides a compromise between the unstructured nature of multi threaded programming and the structured order of synchronous processing. You use synchronization techniques: To explicitly control the order in which code runs whenever tasks must be performed in a specific sequence -or- To prevent the problems that can occur when two threads share the same resource at the same time. For example, you could use synchronization to cause a display procedure to wait until a data retrieval procedure that is running on another thread is complete.
  3. Locks
  4. Locks are pieces of software that make sure that two processes do not get into each other's way when accessing a common resource and sequence the processes when there are dependencies among them.(Eustace, p8)
  5. Deadlock
  6. A deadlock is a case where two pieces of code are trying to access the same objects but are blocking each other from getting at the resources. (Johnson, p396)
  7. Semaphores
  8. In the .Net framework The Semaphore class is used to throttle usage of some resource. Specifically, a Semaphore creates a kernel object that supports a certain number of valid slots at once. When the slots are filled, the remaining code will block until a slot is made available by another thread releasing the slot.(Johnson, p405)
  9. Mutex (mutual exclusion)
  10. A Mutex allows synchronization (like a lock) across AppDomain and process boundaries. (Johnson, p402-405) Using a named Mutex is a common way to synchronize data across process boundaries.
  11. Thread
  12. A process is a running program – code, data (variables, data structures, etc) with at least one thread of execution. A thread is a flow of control through the process, plus a private stack for local data. Threads enable concurrency (Eustace, p2)
  13. Event
  14. An Event provides a way to notify to multiple threads (across AppDomain and process boundaries) that some event has occurred. Events are a type of kernel object that has two states, on and off. These states allow threads across an application to wait until an event is signaled to do something specific.(Johnson, p402-406)
  15. Waitable timer.
  16. A waitable timer (MSDN) object is a synchronization object whose state is set to signaled when the specified due time arrives. The behavior of a waitable timer can be summarized as follows:
    • When a timer is set, it is canceled if it was already active, the state of the timer is nonsignaled, and the timer is placed in the kernel timer queue.
    • When a timer expires, the timer is set to the signaled state. If the timer has a completion routine, it is queued to the thread that set the timer. The completion routine remains in the asynchronous procedure call (APC) queue of the thread until the thread enters an alertable wait state. At that time, the APC is dispatched and the completion routine is called. If the timer is periodic, it is placed back in the kernel timer queue.
    • When a timer is canceled, it is removed from the kernel timer queue if it was pending. If the timer had expired and there is still an APC queued to the thread that set the timer, the APC is removed from the thread's APC queue. The signaled state of the timer is not affected.

References
Eustace K. Concurrency and Transactions, ITC382/ITC594/ITC565 Topic 8
MSDN. Waitable Timer Objects. Retrieved on 6 July 2009, from http://msdn.microsoft.com/en-us/library/ms687012(VS.85).aspx
MSDN. Thread Synchronization. Retrieved on 6 July 2009, from http://msdn.microsoft.com/en-us/library/dsw9f9ts(VS.71).aspx
Johnson, B., Lanham, B., & Wildermuth, S. (2007). Mcpd self-paced training kit (exam 70-549): designing and developing enterprise applications using the microsoft®. net framework.