电子科技女学 Software Architecture Design Pattern Univers的aEe中onic Science and Technolopy时C■ Lecture 4 Concurrent Computing Concurrency vs.Parallism ·Threading Model Thread Synchronization ·案例:高并发网站架构解决方案 Software Architecture and Design Pattern
Software Architecture & Design Pattern Software Architecture and Design Pattern 1 Lecture 4 Concurrent Computing • Concurrency vs. Parallism • Threading Model • Thread Synchronization • 案例:高并发网站架构解决方案
电子特技女学 Concurrent Computing Aechitecture University af Electronic Science and Technoloryf Chim 222 Applications ● Programming paradigms Threads Interface Microkernel Operating System Multi-Processor Computing System Hardware P Processor Thread Process Software Architecture and Design Pattern 2
Concurrent Computing Aechitecture Software Architecture and Design Pattern 2 P P P P P .. P Microkernel Multi-Processor Computing System Threads Interface Hardware Operating System ProcessorThread Process P Applications Programming paradigms
电子科技女学 Software Architecture Design Pattern University Eectronic Scienceand ecol Parallel computing:using multiple processors in parallel to solve problems more quickly than with a single processor 。 Examples of parallel machines: -A cluster computer that contains multiple PCs combined together with a high speed network -A shared memory multiprocessor (SMP*)by connecting multiple processors to a single memory system -A Chip Multi-Processor (CMP)contains multiple processors(called cores)on a single chip Concurrent execution comes from desire for performance; unlike the inherent concurrency in a multi-user distributed system Technically,SMP stands for "Symmetric Multi-Processor" Software Architecture and Design Pattern 3
Software Architecture & Design Pattern Software Architecture and Design Pattern 3 • Parallel computing: using multiple processors in parallel to solve problems more quickly than with a single processor • Examples of parallel machines: – A cluster computer that contains multiple PCs combined together with a high speed network – A shared memory multiprocessor (SMP*) by connecting multiple processors to a single memory system – A Chip Multi-Processor (CMP) contains multiple processors (called cores) on a single chip • Concurrent execution comes from desire for performance; unlike the inherent concurrency in a multi-user distributed system * Technically, SMP stands for “Symmetric Multi-Processor
电子科技女学 Software Architecture Design Pattern University af Electronic Science and Technoloryf Chim Motivation for Concurrency Leverage hardware/software advances,e.g. multi-processors and OS thread support Increase performance,e.g.,overlap computation and communication Improve response-time,e.g.,GUIs and network servers Simplify program structure,e.g.,synchronous vs.asynchronous network IPC Software Architecture and Design Pattern 4
Software Architecture & Design Pattern Software Architecture and Design Pattern 4 Motivation for Concurrency • Leverage hardware/software advances, e.g. multi-processors and OS thread support • Increase performance, e.g., overlap computation and communication • Improve response-time, e.g., GUIs and network servers • Simplify program structure, e.g., synchronous vs. asynchronous network IPC
电子科技女学 Software Architecture Design Pattern University af Electronic Science and Technoloryf Chim Definitions 。Concurrency -"Logically"simultaneous processing Does not imply multiple processing elements ·Parallelism -"Physically"simultaneous processing Involves multiple processing elements and/or independent device operations Both concurrency and parallelism require controlled access to shared resources,e.g.I/O devices,files,database records,in-core data structures,consoles,etc. Software Architecture and Design Pattern 5
Software Architecture & Design Pattern Software Architecture and Design Pattern 5 Definitions • Concurrency - “Logically" simultaneous processing - Does not imply multiple processing elements • Parallelism - “Physically" simultaneous processing - Involves multiple processing elements and/or independent device operations Both concurrency and parallelism require controlled access to shared resources, e.g. I/O devices, files, database records, in-core data structures, consoles, etc
电子科技女学 Software Architecture Design Pattern nntE的aE中onic Science and Technolo时Ch■u Flynn's Classical Taxonomy Single Instruction,Single Data streams(SISD)-your single- core uni-processor PC 一 Single Instruction,Multiple Data streams(SIMD)-special purpose low-granularity multi-processor m/c w/a single control unit relaying the same instruction to all processors (w/different data)every cc (e.g.,nVIDIA graphic co- processor w/1000's of simple cores) - Multiple Instruction,Single Data streams(MISD)- pipelining is a major example Multiple Instruction,Multiple Data streams(MIMD)-the most prevalent model.SPMD(Single Program Multiple Data)is a very useful subset.Note that this is v.different from SIMD. Software Architecture and Design Pattern 6
Software Architecture & Design Pattern Software Architecture and Design Pattern 6 Flynn's Classical Taxonomy – Single Instruction, Single Data streams (SISD)—your singlecore uni-processor PC – Single Instruction, Multiple Data streams (SIMD)—special purpose low-granularity multi-processor m/c w/ a single control unit relaying the same instruction to all processors (w/ different data) every cc (e.g., nVIDIA graphic coprocessor w/ 1000’s of simple cores) – Multiple Instruction, Single Data streams (MISD)— pipelining is a major example – Multiple Instruction, Multiple Data streams (MIMD)—the most prevalent model. SPMD (Single Program Multiple Data) is a very useful subset. Note that this is v. different from SIMD
电子科技女学 Software Architecture Design Pattern University af Electronic Science and Technoloryf Chim Data Parallelism:SIMD and SPMD fall into this category Functional Parallelism:MISD falls into this category MIMD can incorporates both data and functional parallelisms (the latter at either instruction level- different instrs.being executed across the processors at any time,or at the high-level function space) Software Architecture and Design Pattern 7
Software Architecture & Design Pattern Software Architecture and Design Pattern 7 • Data Parallelism: SIMD and SPMD fall into this category • Functional Parallelism: MISD falls into this category • MIMD can incorporates both data and functional parallelisms (the latter at either instruction level— different instrs. being executed across the processors at any time, or at the high-level function space)
电子科技大学 Concurrent Computing Model University af Electronic Science and Technoloryf Chim Multiprocess vs.Multithread ·Multiprocess Multiple tasks or processes share common system resources such as CPU,I/O,etc. ·Multithread Multiple execution units within a process share system resources. Software Architecture and Design Pattern 8
Concurrent Computing Model Software Architecture and Design Pattern 8 Multiprocess vs. Multithread • Multiprocess Multiple tasks or processes share common system resources such as CPU, I/O, etc. • Multithread Multiple execution units within a process share system resources
电子州妓女学 Software Architecture Design Pattern University af Electronic Science and Technoloryf Chim Multiprocess---single core Word Web E-mail Antivirus Processor Browser Operating System CPU Core Software Architecture and Design Pattern 9
Software Architecture & Design Pattern Software Architecture and Design Pattern 9 Multiprocess --- single core
电子科技女学 Software Architecture Design Pattern University af Electronic Science and Technoloryf Chim Java Threading Model Two-level threads:user thread (java thread class) kernel thread(O/S kernel support) Thread model ·one-to-one 。many-to-one 。many-to-many Software Architecture and Design Pattern 10
Software Architecture & Design Pattern Software Architecture and Design Pattern 10 Java Threading Model Two-level threads: user thread (java thread class) kernel thread (O/S kernel support) Thread model • one-to-one • many-to-one • many-to-many