aio

Redis03——Redis架构

冷暖自知 提交于 2019-11-29 10:29:59
Redis架构 1.1.问题 redis是单线程,单实例,为什么并发那么多,依旧很快呢? 回答:因为调用了系统内核的epoll 1.2.Linux的早期版本 Linux有Linux kernal,我们的客户端,进行连接,首先到达的是Linux kernal,在Linux的早期版本,只有read和write进行文件读写。我们使用一个线程/进程 进行调用read和write函数,那么将会返回一个文件描述符fd(file description)。我们开启线程/进程去调用read进行读取。因为socket在这个时期是blocking(阻塞的),遇到高并发,就会阻塞,也就是bio时期。 1.3.内核的跃迁 Linux kernal在之后的发展,有了很大的变化,Linux到达率NIO时期。我们可以使用客户端进行轮询访问。但是,我们如果打进1000个线程访问,那么成本就会很大。我们出现了select函数,select函数和pselect函数,我们可以直接传1000个文件描述符,一旦有返回,那么再去调read函数。这个叫做多路复用的NIO。 紧接着,内核再次跃迁,我们出现了一个共享空间,通过mmap进行空间映射。(本质是红黑树+链表//红黑树是一种自平衡的二叉查找树)。我们将1000个文件描述符写进共享空间,如果我们的数据有返回,那么加入链表,我们从链表取出调用read进行读取

How do you use AIO and epoll together in a single event loop?

吃可爱长大的小学妹 提交于 2019-11-29 08:52:57
问题 How can you combine AIO and epoll together in a single event loop? Google finds lots of talk from 2002 and 2003 about unifying them, but its unclear if anything happened, or if it's possible. Has anyone rolled-their-own with an epoll loop using eventfd for the aio signal? 回答1: try libevent: http://www.monkey.org/~provos/libevent/ there are patches to support both. 回答2: you can see http://www.xmailserver.org/eventfd-aio-test.c for a sample of aio and eventfd 回答3: Tried eventfd with epoll? "A

linux(Ubuntu) 搭建LAMP环境

徘徊边缘 提交于 2019-11-29 04:48:34
1、更新源 sudo apt- get update 2、安装常用软件 SSH、Vim、Git、Tree ①SSH sudo apt-get install openssh-server 管理命令:service ssh status/start/stop/restart ②Vim sudo apt-get install vim ③Git sudo apt-get install git ④Tree sudo apt-get install tree 3、安装Apache sudo apt-get intall apache2 基本信息: 测试:访问http:IP 出现apache工作页面 管理命令:service apache2 status/start/restart/stop web目录:、var/www 默认访问具体目录为var/www/html 安装目录:、/etc/apache2/ 配置文件:、/etc/apache2/apache2.conf(全局配置文件) 4、安装MySQL sudo apt-get install mysql-server mysql-client 测试: mysql -u -root -p 管理命令:service mysql status/start/stop/restart 5、安装PHP(PHP7.0) sudo apt-get

漫话:如何给女朋友解释什么是BIO、NIO和AIO?

夙愿已清 提交于 2019-11-28 17:24:33
​ 周末午后,在家里面进行电话面试,我问了面试者几个关于IO的问题,其中包括什么是BIO、NIO和AIO?三者有什么区别?具体如何使用等问题,但是面试者回答的并不是很满意。于是我在面试评价中写道:"对Java的IO提醒理解不够深入"。恰好被女朋友看到了。 Java IO IO,常协作I/O,是Input/Output的简称,即输入/输出。通常指数据在内部存储器(内存)和外部存储器(硬盘、优盘等)或其他周边设备之间的输入和输出。 输入/输出是信息处理系统(例如计算机)与外部世界(可能是人类或另一信息处理系统)之间的通信。 输入是系统接收的信号或数据,输出则是从其发送的信号或数据。 在Java中,提供了一些列API,可以供开发者来读写外部数据或文件。我们称这些API为Java IO。 IO是Java中比较重要,且比较难的知识点,主要是因为随着Java的发展,目前有三种IO共存。分别是BIO、NIO和AIO。 Java BIO BIO 全称Block-IO 是一种 同步且阻塞 的通信模式。是一个比较传统的通信方式,模式简单,使用方便。但并发处理能力低,通信耗时,依赖网速。 Java NIO Java NIO,全程 Non-Block IO ,是Java SE 1.4版以后,针对网络传输效能优化的新功能。是一种 非阻塞同步 的通信模式。 NIO 与原来的 I/O 有同样的作用和目的,

Difference between POSIX AIO and libaio on Linux?

谁说我不能喝 提交于 2019-11-28 16:04:31
What I seem to understand: POSIX AIO APIs are prototyped in <aio.h> and you link your program with librt(-lrt), while the libaio APIs in <libaio.h> and your program is linked with libaio (-laio). What I can't figure out: 1.Does the kernel handle the either of these methods differently? 2.Is the O_DIRECT flag mandatory for using either of them? As mentioned in this post , libaio works fine without O_DIRECT when using libaio .Okay,understood but: According to R.Love's Linux System Programming book, Linux supports aio (which I assume is POSIX AIO) on regular files only if opened with O_DIRECT

What's the difference between event-driven and asynchronous? Between epoll and AIO?

拥有回忆 提交于 2019-11-28 15:47:27
问题 Event-driven and asynchronous are often used as synonyms. Are there any differences between the two? Also, what is the difference between epoll and aio ? How do they fit together? Lastly, I've read many times that AIO in Linux is horribly broken. How exactly is it broken? Thanks. 回答1: Events is one of the paradigms to achieve asynchronous execution. But not all asynchronous systems use events. That is about semantic meaning of these two - one is super-entity of another. epoll and aio use

并发模型与IO模型梳理

坚强是说给别人听的谎言 提交于 2019-11-27 19:02:16
并发模型 常见的并发模型一般包括3类,基于线程与锁的内存共享模型,actor模型和CSP模型,其中尤以线程与锁的共享内存模型最为常见。由于go语言的兴起,CSP模型也越来越受关注。基于锁的共享内存模型与后两者的主要区别在于,到底是通过共享内存来通信,还是通过通信来实现访问共享内存。由于actor模型和CSP模型,本人并不是特别了解,我主要说说最基本的并发模型,基于线程与锁的内存共享模型。 为什么要并发,本质都是为了充分利用多核CPU资源,提高性能。但并发又不能乱,为了保证正确性,需要通过共享内存来协调并发,确保程序正确运转。无论是多进程并发,还是多线程并发,要么通过线程间互斥同步(spinlock,rwlock,mutex,condition,信号量),要么通过进程间通信(共享内存,管道,信号量,套接字),本质都是为了协同。多线程和多进程本质类似,尤其是linux环境下的pthread库,本质是用轻量级进程实现线程。下面以网络服务为例,简单讨论下多线程模型的演进。 最简单的模型是单进程单线程模型,来一个请求处理一个请求,这样效率很低,也无法充分利用系统资源。那么可以简单的引入多线程,其中抽出一个线程监听,每来一个请求就创建一个工作线程服务,多个请求多个线程,这就是多线程并发模型。这种模式下,资源利用率是上去了,但是却有很多浪费,线程数与请求数成正比,意味着频繁的创建/销毁线程开销

Difference between POSIX AIO and libaio on Linux?

一笑奈何 提交于 2019-11-27 09:31:37
问题 What I seem to understand: POSIX AIO APIs are prototyped in <aio.h> and you link your program with librt(-lrt), while the libaio APIs in <libaio.h> and your program is linked with libaio (-laio). What I can't figure out: 1.Does the kernel handle the either of these methods differently? 2.Is the O_DIRECT flag mandatory for using either of them? As mentioned in this post, libaio works fine without O_DIRECT when using libaio .Okay,understood but: According to R.Love's Linux System Programming

asynchronous IO io_submit latency in Ubuntu Linux

亡梦爱人 提交于 2019-11-27 08:59:27
I am looking for advice on how to get efficient and high performance asynchronous IO working for my application that runs on Ubuntu Linux 14.04. My app processes transactions and creates a file on disk/flash. As the app is progressing through transactions additional blocks are created that must be appended to the file on disk/flash. The app needs also to frequently read blocks of this file as it is processing new transactions. Each transaction might need to read a different block from this file in addition to also creating a new block that has to be appended to this file. There is an incoming

What is the status of POSIX asynchronous I/O (AIO)?

感情迁移 提交于 2019-11-26 23:31:08
There are pages scattered around the web that describe POSIX AIO facilities in varying amounts of detail. None of them are terribly recent. It's not clear what, exactly, they're describing. For example, the "official" (?) web site for Linux kernel asynchronous I/O support here says that sockets don't work, but the "aio.h" manual pages on my Ubuntu 8.04.1 workstation all seem to imply that it works for arbitrary file descriptors. Then there's another project that seems to work at the library layer with even less documentation. I'd like to know: What is the purpose of POSIX AIO? Given that the