Session_08 - UT D CS 6386 Telecommunications Software...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: UT D CS 6386 Telecommunications Software Design Session 07 Performance & Optimization Concurrency Outline Performance concepts Switch capacity Optimization for performance Concurrency Concurrent programming 2 1 Performance How Good is My System? A quantitative way to express how good a system or a mechanism for a specific purpose or application E.g. performance of a car Performance metrics Measurable entities used to express, compare performance E.g. horse power, acceleration time of a car Performance metrics are application specific Need to understand application first! 3 Performance Why Measurable, quantitative entities are needed to gauge the ability of a system to perform a certain job Planning purposes System tuning Differentiation between manufacturers 4 2 Performance Performance Analysis Why needed for software design? Identify requirements for a system or a component of a system Decide if a component of a system or a system meets the requirements Performance enhancements How? Define performance metrics Measure performance 5 Performance Metrics in Telecommunications Systems Service quality Voice quality Data bit error rates System availability Grade-of-Service (GOS) Grade-of Blocking Response times System throughput Call Capacity 6 3 PSTNs Throughput of a Switch How we express the throughput of a PSTN switch? The number of calls that the switch can process per time unit The main purpose of a switch is to process calls! Call capacity is a key performance metric for a PSTN switch 7 PSTN Switches Call Capacity Key question: how we measure the call capacity of a switch? BHCA Busy Hour Call Attempts The numbers of call attempts that a switch can handle during busy hour BHCA numbers are determined by system hardware AND software Efficient software are required in telecommunications systems 8 4 Why Call Capacity is Important? In PSTNs, call capacity of a switch means `money' More calls to be handled by the switch -> more money to the Telco Bigger switches requires larger call capacity 10,000 ports vs. 100,000 ports Key product differentiator for manufacturers 9 Call Capacity How to Enhance? How we can get more call capacity? Faster hardware Some hardware bottleneck may be difficult to overcome, e.g. memory bandwidth Multiprocessor systems Expensive! Make software run faster!!! Software optimization 10 5 Software Optimization Why Software Run Slow? Inefficient algorithm and data structures E.g. binary search vs. sequential search Machine word boundary Unnecessary processing Needless re-processing or rererecomputation Waiting Bottlenecks 11 Software Optimization How? First, make sure efficient algorithms are used Second, eliminate unnecessary processing Third, profiling and timing code execution Identify `hotspots' portions of code that run frequently Make those identified `hotspots' run faster! Take advantages of system features Caching Profiler is your best friend for software optimization! 12 6 Profiler Example Function List 13 Profiler Example Function Detail 14 7 Profiler Example Annotated Source 15 Ruby Profiler % cumulative self self total 16 8 Optimization Profiling 17 Optimization Performance Enhancement Cycle 18 9 Optimization Cost Considerations 19 What is Concurrent Programming A sequential program has a single thread of control. A concurrent program has multiple threads of program execution allowing it perform multiple computations concurrently Parallelism vs. Concurrency? 20 10 Execution of Concurrent Programs Multiple CPUs A B C A B C physically parallel Time Single CPU A A B C B C instruction interleaving 21 Time Concurrent Programming Why Performance gain Parallel and distributed processing Increased throughput an I/O call need only block one thread Increased responsiveness high priority thread for interactive tasks More appropriate structure for programs which interact with the environment, control multiple activities and handle multiple events 22 11 Concurrent Programming How Multithreading multiple threads within a process Multiprogramming multiple processes in a single processor system Multiprocessing multiple processes within a multiprocessor Distributed processing Multiple communicating processes in a system of multiple computers 23 Why Concurrency is Important? Telecom systems process large number of concurrent events System performance is an important factor Single processor systems Multiprogramming and multi-threading are multirequired and can not be avoided Multiple processor systems Distributed architectures are often employed in telecom systems Some attempts at parallel processing, e.g. Nortel's XA-Core XA24 12 Concurrency in Review Multiprogramming Multiple processes running at the same time Sharing system resources (memory, CPU etc.) Each process has it own memory address space and process control information Context switching is usually expensive A function of the Operating System 25 Concurrency in Review Multithreading A process may have multiple threads of control All threads are sharing the process's resources Each process has each own stack and thread control information Threading the other name is light weight process Quick context switching Efficient inter-process communications inter- Threading can be provided by OS or at application level 26 13 Thread ApplicationApplication-Level Thread Supported by user level threads libraries Benefits: No modifications required to kernel Flexible and low cost Drawbacks: Can not block without blocking entire process Lower performance 27 Threads Kernel Level Threads OS kernel directly supports multiple threads of control in a process Thread is the basic scheduling entity Benefits coordination between scheduling and synchronization Drawbacks more expensive than user-level threads user may not available on some platforms 28 14 Multiprogramming Example http://favorite-web-site N Flash movie playing in a Flash process Background music playing in another process A web page has an embedded flash movie and a background music We want a responsive browser user interface while the flash movie and background music are playing We either need three processes... or ... 29 Multithreading Example http://favorite-web-site N Flash movie playing in a Flash player thread Background music playing in a media player thread ... or ... we will need three threads: the browser, the media player, and the flash player, all run in the same process 30 15 Threads and Processes one process one thread e.g. MS-DOS one process multiple threads e.g. User level threads multiple processes one thread per process e.g. traditional Unix multiple processes multiple threads per process e.g. Windows NT, Solaris, Apple OS X, BeOS, Linux 31 Single Threaded vs. Multithreaded Single-threaded Process Multithreaded Process Threads of Execution Single instruction stream Common Multiple instruction stream Address Space 32 16 Threads Scheduling States Example 33 Advantages of Threads Creating and terminating a new thread is much faster than creating and terminating a process Less time to switch between two threads within the same process Faster context switching Communication among threads of the same process is less complicated and more efficient 34 17 Advantages of Threads Thread Creation and Termination When the OS creates a process it has to allocate memory for the process image load the program and data and initialize other resources When the OS creates a thread within an existing process process image loading and initialization is not needed the OS needs to set up a stack and thread control block for the new thread 35 Advantages of Threads Context Switching Context switching between processes requires a lot of preparation Memory management Process control information, stack etc.. Switching control from one thread to another in the same memory space is much faster 36 18 Advantages of Threads InterInter-process Communication Communication among threads of the same process is easier and more efficient Threads within a process share memory, files and other system resources Separate processes have to communicate with the help of the kernel 37 Concurrency Characteristics The OS maintains a queue of processes or threads that are ready to run allocates CPU time to each of them based on a scheduling algorithm running order of threads or processes is unpredictable A thread or process may be preempted due to interrupts or other higher priority tasks There is no guarantee that a thread or a process will run until completion Shared resources Resources are shared among threads or processes System resources are shared among concurrent entities whose running is unpredictable and can be interrupted 38 19 Concurrency Issues Safety of shared data Shared data may be in inconsistent state Liveliness of execution Deadlocks Starvation Non-deterministic of outcome Non Race conditions may exist and make outcome non-deterministic non39 Concurrency Issue Safety of Shared Data Thread 1 Thread 2 temp = BankBalance; BankBalance; dividend = temp * InterestRate; newbalance = dividend + temp; Dividend += dividend; BankBalance += deposit; BankBalance = newbalance; 40 20 Share Data Integrity Example top 3 b c ? ? Thread B entries a Thread A ... entries[top]=`x'; top++; ... ... entries[top]=`y'; top++; ... 41 Shared Data Integrity Example Scenario 1 top 3 b c ? ? Thread B entries a Thread A ... ... a1 entries[top]=`x'; b1 entries[top]=`y'; top++; top++; a2 b2 ... ... Execution order a1,a2,b1,b2 top 5 b c x y 42 entries a 21 Shared Data Integrity Example Scenario 2 top 3 b c ? ? Thread B entries a Thread A ... ... a1 entries[top]=`x'; b1 entries[top]=`y'; top++; top++; a2 b2 ... ... Execution order a1,b1,a2,b2 top 5 b c y ? 43 entries a Shared Data Integrity Example Quiz top 3 b c ? ? Thread B entries a Thread A ... ... a1 entries[top]=`x'; b1 entries[top]=`y'; top++; top++; a2 b2 ... ... Execution order a1,b1,b2,a2 What is the result? 44 22 Shared Data Integrity Machine Instruction Level a a ... a+=1; ... 6 ... a-=2; ... a1 a2 a3 6 Thread A Thread B Thread A Thread B ... mov ax, a add ax, 1 mov a, ax ... b1 b2 b3 ... mov ax, a sub ax, 2 mov a, ax ... Execution order a1,a2,a3,b1,b2,b3 a1,a2,b1,b2,b3,a3 a1,a2,b1,b2,a3,b3 a 5 7 ? 45 Concurrent Programming Critical Section An execution section where a thread or process needs exclusive control to maintain shared data integrity top 3 b c ? ? Thread B entries a Thread A ... ... a1 entries[top]=`x'; b1 entries[top]=`y'; top++; top++; a2 b2 ... ... Critical section: a1-a2 and b1-b2 46 23 Concurrent Programming Mutual Exclusion top 3 b c ? ? Thread B entries a Thread A ... ... a1 entries[top]=`x'; b1 entries[top]=`y'; top++; top++; a2 b2 ... ... Thread B cannot enter its critical section while thread A is inside the critical section The execution of codes in critical sections should maintain mutual exclusion Many primitives are provided by the OS to achieve mutual exclusion, e.g. mutex lock, semaphore etc. 47 Concurrency Issues Deadlock Permanent blocking of a set of threads that compete for system resources Example Two threads A and B are sharing resource a and resource b A and B need both resource a and resource b to perform some tasks What happens if A and B each acquired one resource and wait for the other? 48 24 Concurrency Issues Deadlock using Res. a requesting A requesting Res. b using B Nether A nor B can proceed 49 Concurrency Issues Starvation A process can never obtain access to resources it needs Processes A, B and C require periodic access to resource R However the OS only assigns access to A and B Can C run? 50 25 Concurrency Issues Race Conditions Process A M=M+2 Process B 10 Memory Location M M = M*2 Process C V=M What is V? If B executes first, V = 12 If A executes first, V = 20 51 Concurrency Programming Summary Concurrency programming is essential in telecom software design Multithreading is used often, in addition to multiprogramming and distributed programming Concurrency has a few challenges including mutual exclusion, deadlocks and race conditions These issues need to be addressed carefully during specification and design processes 52 26 ...
View Full Document

This note was uploaded on 09/01/2008 for the course CS 6386 taught by Professor Nguyen during the Summer '08 term at University of Texas at Dallas, Richardson.

Ask a homework question - tutors are online