




已阅读5页,还剩35页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
Spinnaker Labs, Inc.,Google Cluster Computing Faculty Training Workshop,Module II: Student Background Knowledge,This presentation includes course content University of Washington Redistributed under the Creative Commons Attribution 3.0 license. All other contents:, Spinnaker Labs, Inc.,Background Topics,Programming Languages Systems: Operating Systems File Systems Networking Databases, Spinnaker Labs, Inc.,Programming Languages,MapReduce is based on functional programming map and fold FP is taught in one quarter, but not reinforced “Crash course” necessary Worksheets to pose short problems in terms of map and fold Immutable data a key concept, Spinnaker Labs, Inc.,Multithreaded programming,Taught in OS course at Washington Not a prerequisite! Students need to understand multiple copies of same method running in parallel, Spinnaker Labs, Inc.,File Systems,Necessary to understand GFS Comparison to NFS, other distributed file systems relevant, Spinnaker Labs, Inc.,Networking,TCP/IP Concepts of “connection,” network splits, other failure modes Bandwidth issues, Spinnaker Labs, Inc.,Other Systems Topics,Process Scheduling Synchronization Memory coherency, Spinnaker Labs, Inc.,Databases,Concept of shared consistency model Consensus ACID characteristics Journaling Multi-phase commit processes, Spinnaker Labs, Inc.,Parallelization & Synchronization, Spinnaker Labs, Inc.,Parallelization Idea,Parallelization is “easy” if processing can be cleanly split into n units:, Spinnaker Labs, Inc.,Parallelization Idea (2),In a parallel computation, we would like to have as many threads as we have processors. e.g., a four-processor computer would be able to run four threads at the same time., Spinnaker Labs, Inc.,Parallelization Idea (3), Spinnaker Labs, Inc.,Parallelization Idea (4), Spinnaker Labs, Inc.,Parallelization Pitfalls,But this model is too simple! How do we assign work units to worker threads? What if we have more work units than threads? How do we aggregate the results at the end? How do we know all the workers have finished? What if the work cannot be divided into completely separate tasks?,What is the common theme of all of these problems?, Spinnaker Labs, Inc.,Parallelization Pitfalls (2),Each of these problems represents a point at which multiple threads must communicate with one another, or access a shared resource. Golden rule: Any memory that can be used by multiple threads must have an associated synchronization system!, Spinnaker Labs, Inc.,What is Wrong With This?,Thread 1: void foo() x+; y = x; ,Thread 2: void bar() y+; x+; ,If the initial state is y = 0, x = 6, what happens after these threads finish running?,Multithreaded = Unpredictability,When we run a multithreaded program, we dont know what order threads run in, nor do we know when they will interrupt one another.,Thread 1: void foo() eax = memx; inc eax; memx = eax; ebx = memx; memy = ebx; ,Thread 2: void bar() eax = memy; inc eax; memy = eax; eax = memx; inc eax; memx = eax; ,Many things that look like “one step” operations actually take several steps under the hood:, Spinnaker Labs, Inc.,Multithreaded = Unpredictability,This applies to more than just integers: Pulling work units from a queue Reporting work back to master unit Telling another thread that it can begin the “next phase” of processing All require synchronization!, Spinnaker Labs, Inc.,Synchronization Primitives,A synchronization primitive is a special shared variable that guarantees that it can only be accessed atomically. Hardware support guarantees that operations on synchronization primitives only ever take one step,Semaphores,A semaphore is a flag that can be raised or lowered in one step Semaphores were flags that railroad engineers would use when entering a shared track,Only one side of the semaphore can ever be red! (Can both be green?), Spinnaker Labs, Inc.,Semaphores,set() and reset() can be thought of as lock() and unlock() Calls to lock() when the semaphore is already locked cause the thread to block. Pitfalls: Must “bind” semaphores to particular objects; must remember to unlock correctly, Spinnaker Labs, Inc.,The “Corrected” Example,Thread 1: void foo() sem.lock(); x+; y = x; sem.unlock(); ,Thread 2: void bar() sem.lock(); y+; x+; sem.unlock(); ,Global var “Semaphore sem = new Semaphore();” guards access to x & y, Spinnaker Labs, Inc.,Condition Variables,A condition variable notifies threads that a particular condition has been met Inform another thread that a queue now contains elements to pull from (or that its empty request more elements!) Pitfall: What if nobodys listening?,The final example,Thread 1: void foo() sem.lock(); x+; y = x; fooDone = true; sem.unlock(); fooFinishedCV.notify(); ,Thread 2: void bar() sem.lock(); while(!fooDone) fooFinishedCV.wait(sem); y+; x+; sem.unlock(); ,Global vars: Semaphore sem = new Semaphore(); ConditionVar fooFinishedCV = new ConditionVar(); boolean fooDone = false;, Spinnaker Labs, Inc.,Barriers,A barrier knows in advance how many threads it should wait for. Threads “register” with the barrier when they reach it, and fall asleep. Barrier wakes up all registered threads when total count is correct Pitfall: What happens if a thread takes a long time?, Spinnaker Labs, Inc.,Too Much Synchronization? Deadlock,Synchronization becomes even more complicated when multiple locks can be used Can cause entire system to “get stuck”,Thread A: semaphore1.lock(); semaphore2.lock(); /* use data guarded by semaphores */ semaphore1.unlock(); semaphore2.unlock();,Thread B: semaphore2.lock(); semaphore1.lock(); /* use data guarded by semaphores */ semaphore1.unlock(); semaphore2.unlock();,(Image: RPI CSCI.4210 Operating Systems notes), Spinnaker Labs, Inc.,And if you thought I was joking, Spinnaker Labs, Inc.,The Moral: Be Careful!,Synchronization is hard Need to consider all possible shared state Must keep locks organized and use them consistently and correctly Knowing there are bugs may be tricky; fixing them can be even worse! Keeping shared state to a minimum reduces total system complexity, Spinnaker Labs, Inc.,Fundamentals of Networking, Spinnaker Labs, Inc.,Sockets: The Internet = tubes?,A socket is the basic network interface Provides a two-way “pipe” abstraction between two applications Client creates a socket, and connects to the server, who receives a socket representing the other side, Spinnaker Labs, Inc.,Ports,Within an IP address, a port is a sub-address identifying a listening program Allows multiple clients to connect to a server at once, Spinnaker Labs, Inc.,Example: Web Server (1/3),The server creates a listener socket attached to a specific port. 80 is the agreed-upon port number for web traffic., Spinnaker Labs, Inc.,Example: Web Server (2/3),The client-side socket is still connected to a port, but the OS chooses a random unused port number When the client requests a URL (e.g., “”), its OS uses a system called DNS to find its IP address., Spinnaker Labs, Inc.,Example: Web Server (3/3),Server chooses a randomly-numbered port to handle this particular client Listener is ready for more incoming connections, while we process the current connection in parallel,What makes this work?,Underneath the socket layer are several more protocols Most important are TCP and IP (which are used hand-in-hand so often, theyre often spoken of as one protocol: TCP/IP),Even more low-level protocols handle how data is sent over Ethernet wires, or how bits are sent through the air using 802.11 wireless, Spinnaker Labs, Inc.,IP: The Internet Protocol,Defines the addressing scheme for computers Encapsulates internal data in a “packet” Does not provide reliability Just includes enough informatio
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025湖南永州市零陵高新技术产业开发区公开选调工作人员4人模拟试卷及答案详解(有一套)
- 2025河南洛阳市洛宁县招聘看护队伍劳务派遣人员45名考前自测高频考点模拟试题附答案详解(典型题)
- 2025江苏南京紫金山科技产业发展集团有限公司招聘3人模拟试卷附答案详解(突破训练)
- 2025甘肃兰州新区市政投资管理集团有限公司招聘32人考前自测高频考点模拟试题及一套参考答案详解
- 2025江苏淮安市洪泽区云创传媒有限公司总经理招聘考前自测高频考点模拟试题及一套答案详解
- 2025河南中医药大学招聘高层次人才考前自测高频考点模拟试题附答案详解(考试直接用)
- 2025广西南宁市青秀区委统战部招聘1人考前自测高频考点模拟试题及1套参考答案详解
- 2025春季中国核工业二四建设有限公司社会招聘考前自测高频考点模拟试题及参考答案详解一套
- 2025广东深圳市九洲电器有限公司招聘法务专员等模拟试卷及完整答案详解1套
- 2025北京丰台区新村街道办事处招聘城市协管员6人考前自测高频考点模拟试题及1套参考答案详解
- 树木学试题及答案北林
- 财政补贴政策在促进农村电商发展的扶持效果可行性分析报告
- 《创伤失血性休克中国急诊专家共识(2023)》解读 2
- 2025第三季度作风建设党课以忠诚廉洁担当的政治品格奋力书写高质量发展新答卷
- 打井设备成套转让协议书
- 组织结构的权力与权威
- 宠物急救标准化流程
- 2025届广东广州地铁集团有限公司校园招聘笔试参考题库附带答案详解(10套)
- 教师信息技术数字资源开发计划
- 低钾血症护理常规业务学习
- 送货服务方案
评论
0/150
提交评论