epoll

One-shot *level*-triggered epoll(): Does EPOLLONESHOT imply EPOLLET?

蓝咒 提交于 2019-12-04 09:08:31
Is it possible to use epoll in one-shot level -triggered mode? I couldn't find any information on it when I searched; it seems everyone uses edge-triggered mode. When the EPOLLONESHOT flag is selected and you have pulled an event for a socket, then the socket won't get removed from epoll as many think but its events get disabled. You can enable them again using epoll_ctl / EPOLL_CTL_MOD . An example case when the EPOLLONESHOT behavior comes handy is when you've read the available data from a socket into a buffer. That buffer would be emptied independently, but until it isn't empty, you have to

百万级高并发WebRTC流媒体服务器设计与开发

随声附和 提交于 2019-12-04 04:56:06
第1章 课程导学与准备工作 本章主要介绍为何要学习WebRTC流媒体服务器开发,以及本门课能为我们带来哪些收获。之后会为大家介绍本课程内容具体安排,最后给出如何学好这门课程的一些学习建议。希望大家都能通过这门课程,学有所成,学有所归。 第2章 C++语言基础回顾【已掌握,可略过】 为了便于大家更好的学习流媒体服务器的开发,本章将带大家对WebRTC服务器开发中用到的C++基础知识进行回顾梳理,如类的定义与使用,继承,多态,名存空间等相关知识。 第3章 服务器基础编程 本章将带你学习最基础的服务器开发,让你体会服务器开发其实如此简单。 第4章 网络编程基础 本章将带你了解如何在服务端开发网络服务器程序。 第5章 异步I/O事件处理 本章将带你掌握异步IO事件处理原理。 第6章 epoll实现高性能服务器 本章将带你学习Linux下最高效的异步IO事件处理函数epoll的使用。 第7章 libevent实现高性能网络服务器 本章将带你了解几个比较著名的开源事件处理库,epoll使用起来比较复杂,很多开源项目对epoll进行了封装,如libevent、libuv等,本章还会传授你如何提高开发网络异步IO服务器的效率。 第8章 TCP/IP详解 本章将带你深入TCP/IP原理,对TCP协议、TCP三次握手、TCP四次挥手、UDP与RTP等核心内容做深入剖析。 第9章 UDP/RTP

一个RPC服务客户端代理中间件的设计过程的回顾

淺唱寂寞╮ 提交于 2019-12-03 22:55:33
一个RPC服务客户端代理中间件的设计过程的回顾 0 前言 近两年来,负责重新设计和开发一组RPC服务调用的中间件的通讯模块,包括RPC服务端模块(RPC服务容器I/O通讯模块),以及一个RPC客户端代理模块。 在整个设计开发过程中,经历了多次模块重构,终于实现预设的功能以及性能目标。 写这篇文章的目的,一是觉得有必要对这两年的思考、设计和开发过程做一次阶段总结,将这段时间的经验和尝试,以文字的形式沉淀下来,二是为了给将来的进步设定一个认知的基线。 1 设计需求 RPC服务通讯中间件的需求,主要设定了功能和性能两方面的内容。总的来说,实现一个高性能、低延迟的RPC服务中间件, 将客户端的业务处理请求,相对均衡地分配到后端服务执行。 1.1 功能需求 RPC服务中间件的通讯模块,主要包括客户端代理和服务端I/O通讯模块两部分组成,实现分布式服务的透明调用。 客户端代理中间件模块的主要功能包括: 接收业务请求并组成RPC请求消息,并发送到远端服务。 监听Socket连接获取服务端回复消息,从回复的RPC消息提取业务对象,返回给业务模块。 服务的发现。客户端可以动态的获取到指定服务实例的地址。 服务Socket连接的动态维护。如运行过程中关闭异常连接、新增连接等。 1.2 性能需求 性能需求主要在于整个通讯模块整体的吞吐量,以及单个消息的处理延时指标上。这些指标主要包括:

[转]Nginx实现高并发的原理

旧城冷巷雨未停 提交于 2019-12-03 22:38:07
Nginx 首先要明白,Nginx 采用的是多进程(单线程) & 多路IO复用模型。使用了 I/O 多路复用技术的 Nginx,就成了”并发事件驱动“的服务器。 异步非阻塞(AIO)的详解 http://www.ibm.com/developerworks/cn/linux/l-async/ 多进程的工作模式 1、Nginx 在启动后,会有一个 master 进程和多个相互独立的 worker 进程。 2、接收来自外界的信号,向各worker进程发送信号,每个进程都有可能来处理这个连接。 3、 master 进程能监控 worker 进程的运行状态,当 worker 进程退出后(异常情况下),会自动启动新的 worker 进程。 注意 worker 进程数,一般会设置成机器 cpu 核数。因为更多的worker 数,只会导致进程相互竞争 cpu,从而带来不必要的上下文切换。 使用多进程模式,不仅能提高并发率,而且进程之间相互独立,一个 worker 进程挂了不会影响到其他 worker 进程。 惊群现象 主进程(master 进程)首先通过 socket() 来创建一个 sock 文件描述符用来监听,然后fork生成子进程(workers 进程),子进程将继承父进程的 sockfd(socket 文件描述符),之后子进程 accept() 后将创建已连接描述符(connected

Is there any good examples or tutorial about epoll UDP?

余生颓废 提交于 2019-12-03 21:45:06
I have been working with linux server using epoll and almost finished it. And I realized that clients will send packets using udp :( Could you please provide me any good tutorials or example using epoll udp? Thanks in advance. Josh Paul The man pages were helpful for me. There's also a good code example in there. http://kernel.org/doc/man-pages/online/pages/man4/epoll.4.html http://kernel.org/doc/man-pages/online/pages/man2/epoll_create1.2.html If you're really insisting on tutorial, I'd recommend: https://banu.com/2011/06/how-to-use-epoll-complete-example/ https://github.com/felipecruz/rio

epoll_wait() receives socket closed twice (read()/recv() returns 0)

喜你入骨 提交于 2019-12-03 20:19:48
We have an application that uses epoll to listen and process http-connections. Sometimes epoll_wait() receives close event on fd twice in a "row". Meaning: epoll_wait() returns connection fd on which read()/recv() returns 0. This is a problem, since I have malloc:ed pointer saved in epoll_event struct (struct epoll_event.data.ptr) and which is freed when fd(socket) is detected as closed the first time. Second time it crashes. This problem occurs very rarely in real use (except one site, which actually has around 500-1000 users per server). I can replicate the problem using http siege with

Why having to use non-blocking fd in a edge triggered epoll function?

若如初见. 提交于 2019-12-03 20:07:19
I read document abount edge triggered epoll function in web as follows: 1. The file descriptor that represents the read side of a pipe (rfd) is registered on the epoll instance. 2. A pipe writer writes 2 kB of data on the write side of the pipe. 3. A call to epoll_wait(2) is done that will return rfd as a ready file descriptor. 4. The pipe reader reads 1 kB of data from rfd. 5. A call to epoll_wait(2) is done. ....... ....... The suggested way to use epoll as an edge-triggered (EPOLLET) interface is as follows: i) Use nonblocking file descriptors ii) Call epoll_wait for an event only after

nginx与apache的区别

眉间皱痕 提交于 2019-12-03 17:37:28
1、nginx相对于apache的优点: 轻量级,同样起web 服务,比apache占用更少的内存及资源抗并发,nginx 处理请求是异步非阻塞的,而apache 则是阻塞型的,在高并发下nginx 能保持低资源低消耗高性能高度模块化的设计,编写模块相对简单社区活跃,各种高性能模块出品迅速啊 apache 相对于nginx 的优点: rewrite ,比nginx 的rewrite 强大,动态页面,模块超多,基本想到的都可以找到,少bug ,nginx 的bug 相对较多,超稳定 存在就是理由,一般来说,需要性能的web 服务,用nginx 。如果不需要性能只求稳定,那就apache 吧。后者的各种功能模块实现得比前者,例如ssl 的模块就比前者好,可配置项多。这里要注意一点,epoll(freebsd 上是 kqueue )网络IO 模型是nginx 处理性能高的根本理由,但并不是所有的情况下都是epoll 大获全胜的,如果本身提供静态服务的就只有寥寥几个文件,apache 的select 模型或许比epoll 更高性能。 2、作为 Web 服务器:相比 Apache,Nginx 使用更少的资源,支持更多的并发连接,体现更高的效率,这点使 Nginx 尤其受到虚拟主机提供商的欢迎。在高连接并发的情况下,Nginx是Apache服务器不错的替代品:

python之selectors模块

▼魔方 西西 提交于 2019-12-03 17:31:37
python之selectors模块 selectors模块是在python3.4版本中引进的,它封装了IO多路复用中的select和epoll,能够更快,更方便的实现多并发效果。 官方文档见: https://docs.python.org/3/library/selectors.html 以下是一个selectors模块的代码示范: #!/usr/bin/python #Author:sean import selectors import socket #selectors模块默认会用epoll,如果你的系统中没有epoll(比如windows)则会自动使用select sel = selectors.DefaultSelector() #生成一个select对象 def accept(sock, mask): conn, addr = sock.accept() # Should be ready print('accepted', conn, 'from', addr) conn.setblocking(False) #设定非阻塞 sel.register(conn, selectors.EVENT_READ, read) #新连接注册read回调函数 def read(conn, mask): data = conn.recv(1024) # Should be

How to get errno when epoll_wait returns EPOLLERR?

风流意气都作罢 提交于 2019-12-03 17:07:14
问题 Is there a way to find out the errno when epoll_wait returns EPOLLERR for a particular fd? Is there any further information about the nature of the error? Edit: Adding more information to prevent ambiguity epoll_wait waits on a number of file descriptors. When you call epoll_wait you pass it an array of epoll_event structures: struct epoll_event { uint32_t events; /* Epoll events */ epoll_data_t data; /* User data variable */ }; The epoll_data_t structure has the same details as the one you