NPRG051 Advanced C++ Programming 2016/17 Assignment 2

Similar documents
33. Event-based Concurrency

Real-Time Systems. Real-Time Operating Systems

Real-Time Systems Hermann Härtig Real-Time Operating Systems Brief Overview

REAL-TIME OPERATING SYSTEMS SHORT OVERVIEW

Parallel I/O Paradigms. Files and File Semantics. Non-Blocking I/O. Enabling Parallel Operations. Multi-Channel Poll/Select. Worker Threads 3/28/2017

Implementation of a Single Threaded User Level Asynchronous I/O Library using the Reactor Pattern

ISA 563: Fundamentals of Systems Programming

The POSIX AIO interface consists of the following functions: Enqueue a write request. This is the asynchronous analog of write(2).

Assignment 2 Group 5 Simon Gerber Systems Group Dept. Computer Science ETH Zurich - Switzerland

Real-Time Operating Systems

A Scalable Event Dispatching Library for Linux Network Servers

CISC2200 Threads Spring 2015

Overview. Administrative. * HW 2 Grades. * HW 3 Due. Topics: * What are Threads? * Motivating Example : Async. Read() * POSIX Threads

Operating Systems CMPSCI 377 Spring Mark Corner University of Massachusetts Amherst

Networks and distributed computing

Today: VM wrap-up Select (if time) Course wrap-up Final Evaluations

FILE SYSTEMS. Jo, Heeseung

Chapter 8: I/O functions & socket options

Engineering Robust Server Software

Advanced Unix Programming Module 06 Raju Alluri spurthi.com

SDC 2015 Santa Clara

Asynchronous Events on Linux

Input/Output Systems

CSE 43: Computer Networks Structure, Threading, and Blocking. Kevin Webb Swarthmore College September 14, 2017

I/O Systems. Amir H. Payberah. Amirkabir University of Technology (Tehran Polytechnic)

CS 43: Computer Networks. 07: Concurrency and Non-blocking I/O Sep 17, 2018

CS 333 Introduction to Operating Systems. Class 3 Threads & Concurrency. Jonathan Walpole Computer Science Portland State University

Threads Implementation. Jo, Heeseung

File Systems Overview. Jin-Soo Kim ( Computer Systems Laboratory Sungkyunkwan University

CMPS 111 Spring 2003 Midterm Exam May 8, Name: ID:

Lecture 8: Other IPC Mechanisms. CSC 469H1F Fall 2006 Angela Demke Brown

Topics. Lecture 8: Other IPC Mechanisms. Socket IPC. Unix Communication

Device-Functionality Progression

Chapter 12: I/O Systems. I/O Hardware

I/O Models. Kartik Gopalan

Network Programming TDC 561

Introduction to Asynchronous Programming Fall 2014

Roadmap. CPU management. Memory management. Disk management. Other topics. Process, thread, synchronization, scheduling. Virtual memory, demand paging

Event-based Concurrency (Advanced)

CS 333 Introduction to Operating Systems. Class 3 Threads & Concurrency. Jonathan Walpole Computer Science Portland State University

POSIX Threads: a first step toward parallel programming. George Bosilca

Chapter 13: I/O Systems

Motivation of VPN! Overview! VPN addressing and routing! Two basic techniques for VPN! ! How to guarantee privacy of network traffic?!

Introduction to pthreads

CS631 - Advanced Programming in the UNIX Environment. Dæmon processes, System Logging, Advanced I/O

Module 12: I/O Systems

Operating Systems 2010/2011

Interrupt Timer I/O operations

Quiz: Address Translation

File I/0. Advanced Programming in the UNIX Environment

Exception-Less System Calls for Event-Driven Servers

Module 12: I/O Systems

HLD For SMP node affinity

COMP 3361: Operating Systems 1 Final Exam Winter 2009

CSE 120 Principles of Operating Systems

Conoscere e ottimizzare l'i/o su Linux. Andrea Righi -

Chapter 13: I/O Systems

Chapter 13: I/O Systems. Chapter 13: I/O Systems. Objectives. I/O Hardware. A Typical PC Bus Structure. Device I/O Port Locations on PCs (partial)

Che-Wei Chang Department of Computer Science and Information Engineering, Chang Gung University

Feeling odd Using new OS and CPU features to speed up large file copying. Sebastian Krahmer stealth [at] openwall net.

Operating Systems. Peter Druschel and Rodrigo Rodrigues MPI-SWS and Saarland University. Required readings: Silberschatz/Galvin: Chapters 1-3

CS333 Intro to Operating Systems. Jonathan Walpole

I/O OPERATIONS. UNIX Programming 2014 Fall by Euiseong Seo

Processes and Threads

CSE 120 Principles of Operating Systems Spring 2017

Non-Blocking Writes to Files

CMPS 111 Spring 2013 Prof. Scott A. Brandt Midterm Examination May 6, Name: ID:

Flash: an efficient and portable web server

CS330: Operating System and Lab. (Spring 2006) I/O Systems

CS 261 Fall Mike Lam, Professor. Threads

Embedded System Design

EECS 3221 Operating System Fundamentals

EECS 3221 Operating System Fundamentals

Signal Example 1. Signal Example 2

COT 4600 Operating Systems Fall Dan C. Marinescu Office: HEC 439 B Office hours: Tu-Th 3:00-4:00 PM

I/O OPERATIONS. UNIX Programming 2014 Fall by Euiseong Seo

Virtual Memory Primitives for User Programs

Concurrent Server Design Multiple- vs. Single-Thread

CS 471 Operating Systems. Yue Cheng. George Mason University Fall 2017

Operating Systems: Quiz2 December 15, Class: No. Name:

Operating Systems. Review ENCE 360

INTERFACING REAL-TIME AUDIO AND FILE I/O

Threads. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

Lecture 2 Process Management

Outline. Relationship between file descriptors and open files

Slide 5-1. Device. Management. Operating Systems: A Modern Perspective, Chapter 5. Copyright 2004 Pearson Education, Inc.

Large Systems: Design + Implementation: Communication Coordination Replication. Image (c) Facebook

Motivation of Threads. Preview. Motivation of Threads. Motivation of Threads. Motivation of Threads. Motivation of Threads 9/12/2018.

Chapter 13: I/O Systems. Operating System Concepts 9 th Edition

PROCESS CONCEPTS. Process Concept Relationship to a Program What is a Process? Process Lifecycle Process Management Inter-Process Communication 2.

GPUfs: Integrating a file system with GPUs

G Honors Operating Systems

W4118: OS Overview. Junfeng Yang

Chapter 13: I/O Systems

A Lightweight Semaphore for Linux

CSE 153 Design of Operating Systems Fall 18

Suggested Solutions (Midterm Exam October 27, 2005)

I/O CANNOT BE IGNORED

Chapter 13: I/O Systems

Recovering Disk Storage Metrics from low level Trace events

Transcription:

NPRG051 Advanced C++ Programming 2016/17 Assignment 2

Topic Async I/O B-Tree server

Motivation Typical database: tree indices performance based on disk speed synchronization speed on parallel access minimal CPU load

Motivation Typical database: tree indices B-trees to save I/O operations performance based on disk speed cca. O(h seek) synchronization speed on parallel access locking minimal CPU load 1 CPU is more than enough

Target Assignment: Server that provides access to basic operations on a B-tree. in 1 thread asynchronous processing of client requests

Asynchronous processing 1 Clients Server Storage op 1 1 recv 2 2 recv op 2 ok 1 ok 2 poll poll poll 1 2 2 1

Implementation How to process requests parallely in 1 thread? event loop AIO Why not use more threads?

Implementation How to process requests parallely in 1 thread? event loop AIO Why not use more threads? That provides almost no extra throughput! bottleneck is elsewhere 1 thread saves system resources hand scheduling is often better Synchronization overhead! only 1 thread can accept requests locking required deadlocks...

Implementation How to process requests parallely in 1 thread? event loop AIO Why not use more threads? That provides almost no extra throughput! bottleneck is elsewhere 1 thread saves system resources hand scheduling is often better Synchronization overhead! only 1 thread can accept requests locking required deadlocks... Common motivation: C10K problem

Asynchronous processing Server: Client: send(s, "get X"); reply = recv(s); for(;;) { active=poll(sockets); foreach(s in active) { req=recv(s); handle(req); } }

Asynchronous processing Server: Client: send(s, "get X"); reply = recv(s); for(;;) { active=poll(sockets); foreach(s in active) { req=recv(s); handle(req); } }

Asynchronous processing Server: Client: send(s, "get X"); reply = recv(s); for(;;) { active=poll(sockets); foreach(s in active) { req=recv(s); handle(req); } }

Asynchronous processing Server: Client: send(s, "get X"); reply = recv(s); for(;;) { active=poll(sockets); foreach(s in active) { req=recv(s); handle(req); } }

Asynchronous processing Server: Client: send(s, "get X"); reply = recv(s); for(;;) { active=poll(sockets); foreach(s in active) { req=recv(s); handle(req); } }

Podpora v OS Sockets: POSIX fcntl (fd, F_SETFL, O_NONBLOCK); poll(2); Windows ioctlsocket (fd, FIONBIO, &a); select(); File I/PO: Linux/glibc aio(7) (!!!) UNIX aio(4) Windows OVERLAPPED portable Boost.Asio, libeio For this assignment we provide a harmless mock wrapper.

aio struct aiocb { int aio_fildes; off_t aio_offset; size_t aio_nbytes; void *aio_buf; struct sigevent aio_sigevent; //... }; aio_read(aiocb*); aio_write(aiocb*); aio_cancel(aiocb*); aio_suspend(aiocb**, n, timespec); aio_error(aiocb*); aio_return(aiocb*);

AdvC++AIO using IO=ACIO<...>; size_t block_size = IO::block_size; // == k*512 IO io("file.dat"); io.resize(10000); IO::op o(blockid, dataptr); io.read(&o); io.write(&o); io.poll(io_list, 1.5, false); io.finish(&o); IO::req req; io.recv_request(&req); req.value=12345; io.send_reply(&req); io.poll(io_list, 2.0, true);

Functionality requirements program implements a B-tree that behaves just like map<uint64_t, uint64_t>::operator[] clients send requests: read req.type==io::req::read input: req.key output: req.value (default 0) write IO::req::write, 2 inputs, same output erase IO::req::erase, output 0

Functionality requirements program implements a B-tree that behaves just like map<uint64_t, uint64_t>::operator[] clients send requests: read req.type==io::req::read input: req.key output: req.value (default 0) write IO::req::write, 2 inputs, same output erase IO::req::erase, output 0 confirmed data must be persistent (!) order of answer content should be consistent e.g.: write(10,5), write(10,6), read(10,5) more requests must be handled in parallel it is important to limit the amount of requests handled at the same time (!!)

Testing Read through the demo (it serves as testing framework documentation) ACIO has 2 implementations mock in-memory with artificial I/O delays aio POSIX AIO, good for testing on larger data (actually writes blocks to disk) Testing client parameters: Count and frequency of incoming requests bursts

Submitting In main.cpp, add your implementation to run_btree_server. You can add your own btserver.cpp a btserver.hpp. Submit to SIS.

Evaluation correctness code quality no errors correct answers to clients portability (relative) correctly submitted files structure formatting documenting commentary (!!) implementation speed on mock implementation ability to limit RAM usage (and withstand request floods)

Questions? Q&A

Questions? Q&A Good questions: How to survive request flood? What is it good for?

Questions? Q&A Good questions: How to survive request flood? save RAM, clients can wait What is it good for? PostgreSQL?