Comments (4)
You oversimplified the code.
Line 176 starts a fiber to run OnReadable
asynchronously. This is done to parallelize handling of I/O events. However, this also introduces a side effect that read_events_
can be increased concurrently, after OnReadable
draining the read buffer, but before Line 222 is reached.
from flare.
Since a fiber is created and detached after increasing read_events_
from 0 to 1 and L176 is the only line to increase read_events_
, could u point out which line may cause concurrent increase of read_events_
? Do u mean OnReadable
in a fiber may also start parallel invocation to this function?
from flare.
Note that epoll
event can be triggered any time soon after the fd
is drained (edge triggered), even before OnReadable
has an opportunity to return.
IOW, there is a time window between returning EAGAIN
from syscall read
(inside OnReadable
), and decrementing read_events_
. If new data arrived in this time window, without checking event count we may lose the notification.
Consider this:
F1: Received EPOLLIN
, starts F2 to handle it,
F2: Done reading data, is either calling user’s callback or about to return, and got paused (due to whatever reason, e.g., interrupted by system),
F1: Another EPOLLIN
comes, now either:
- We start a new fiber, which would complicate thing a lot, as now the data stream is concurrently handled by two fiber, each with a part of the data (think about what to do if they both contain a portion of a large packet), or
- We’d miss the notification as
OnReadable
is about to return, and no one else would read the data.
Yes you’re right the only place that can increment the event count is L176, but it’s exactly that line that helps us to avoid missing the notification.
from flare.
@0x804d8000 Thanks for your detailed explanation. Learn a lot after reading the implementations.
from flare.
Related Issues (20)
- Http header data structure HOT 13
- Rpc: Http parse HOT 5
- 针对K8s容器环境是否有需要注意的优化配置呢 HOT 2
- clang-format HOT 15
- update blade HOT 9
- logging HOT 11
- if have any plan to support bazel HOT 1
- bazel build ... 失败 HOT 6
- 请问有合适的源码阅读顺序吗 HOT 5
- 对GetFreeCount的取值比较困惑 HOT 5
- Does the server example in the flare example support 1 thread start? HOT 4
- clang-17 asan/tsan fiber coredump
- 关于Function类的疑问 HOT 2
- 问一个非常诡异的用例 HOT 10
- 关于调度参数的疑问 HOT 1
- 编译时间太长 HOT 4
- 调试相关 HOT 3
- Fiber scheduling takes too long HOT 3
- 为什么侵入式的链表采用的是组合而不是继承? HOT 5
- 使用`getaddrinfo`会不会更好一点 HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from flare.