由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - asynchronous vs non-blocking
相关主题
如何快速处理大量网上xml文件?Obamacare website
core java里有跟C++ std::async类似的东西吗?谁能说说同步/异步IO和阻塞/非阻塞IO的区别?
同步编程真郁闷看了一下C#的async await
看看大牛们为什么都远离.net学了这么多语言发现还是coffeescript最好用
An interview project: asynchronous socket programming这年头async IO成了流行了
vert.x 3.1月底发布,一个重要功能fiber不要小看js
尼玛 callback 真是反人类多线程,异步,并发冲突,fp和其它
大家难道全是半路出家?真正对异步有需求的应该是游戏类服务器
相关话题的讨论汇总
话题: blocking话题: nio2话题: async话题: nio
进入Programming版参与讨论
1 (共1页)
x****d
发帖数: 1766
1
The other day I saw Pecking2 talking about "yibu bian cheng". I am an JEE
guy, so dont know much about socket api and I am kind of confused.
Can someone kindly explain what the heck is asynchronous and what is non-
blocking, are they the same?
I remember java NIO2 is non blocking, so is it async?
g*****g
发帖数: 34805
2
Asynchronous is always non-blocking. Non-blocking is not necessarily
asynchronous. An example is java nio and nio2, in java nio, you can use a
thread to monitor many sockets by polling, and it checks if the data is
ready.
Asynchronous I/O on the other hand, employs the callback. So instead of
checking your channels periodically, they'll notify you when they are ready,
so you don't need a monitor thread.

【在 x****d 的大作中提到】
: The other day I saw Pecking2 talking about "yibu bian cheng". I am an JEE
: guy, so dont know much about socket api and I am kind of confused.
: Can someone kindly explain what the heck is asynchronous and what is non-
: blocking, are they the same?
: I remember java NIO2 is non blocking, so is it async?

x****d
发帖数: 1766
3
Can you explain poll please? I heard that often, select, poll, what is the
difference? Java NIO2 has call back, why it does not qualified as async?
When Pecking2 said async programming, what exactly he meant? excluding non
blocking?
g*****g
发帖数: 34805
4
You assign 100 IO tasks to 100 workers (sockets), you check them one by one
nonstop until one of them has data and do something about it, that's called
polling.
If you register a callback and asks the workers to notify you when it has
data (or when completed), that's async IO, obviously in the later case you
don't need a manager thread. Interested party can register callback on their
own. Both are non-blocking however, compared to 100 threads blocked on 100
IOs.
NIO2 has async IO, NIO doesn't, if I didn't make that clear in the last post.

【在 x****d 的大作中提到】
: Can you explain poll please? I heard that often, select, poll, what is the
: difference? Java NIO2 has call back, why it does not qualified as async?
: When Pecking2 said async programming, what exactly he meant? excluding non
: blocking?

x****d
发帖数: 1766
5
Thanks ah... So both Java NIO and NIO2 is non blocking, but only NIO2 is
async.
How about select? what is it?
I know a bit about NIO2, I don't see much fun there. Why other guys said
async programming is more fun? From programmer aspect, same thing, why do I
care if it is async? I don't see how it makes my life any easier.
g*****g
发帖数: 34805
6
A Selector is a Java NIO component which can examine one or more NIO
Channels, and determine which channels are ready for e.g. reading or writing
. It's just a coin name.
Async is not about making programmers' life easier, it's about making
performance better.

I

【在 x****d 的大作中提到】
: Thanks ah... So both Java NIO and NIO2 is non blocking, but only NIO2 is
: async.
: How about select? what is it?
: I know a bit about NIO2, I don't see much fun there. Why other guys said
: async programming is more fun? From programmer aspect, same thing, why do I
: care if it is async? I don't see how it makes my life any easier.

p*****2
发帖数: 21240
7
顶好虫。说的非常到位。
p*****2
发帖数: 21240
8

I
It does make your life easier. You can use less resources but do much more
work.

【在 x****d 的大作中提到】
: Thanks ah... So both Java NIO and NIO2 is non blocking, but only NIO2 is
: async.
: How about select? what is it?
: I know a bit about NIO2, I don't see much fun there. Why other guys said
: async programming is more fun? From programmer aspect, same thing, why do I
: care if it is async? I don't see how it makes my life any easier.

x****d
发帖数: 1766
9
I against your idea as principle. We should gain productivity by making
programmer's life easier, in general. CPU capacity is double every 6 months,
we shouldn't spend valuable time to reduce resources usage.
Do you know how much it costs to train programmers for something new like
NIO2 in a big java shop? And the recruiting expenses is huge too. That is
why some guys think we guys in java world move slow. But we have to justify
the cost and benefit.

【在 p*****2 的大作中提到】
:
: I
: It does make your life easier. You can use less resources but do much more
: work.

g*****g
发帖数: 34805
10
It's only an option, NIO2 doesn't deprecate NIO or blocking IO. You choose
the best tool for your job. You can stick to blocking IO if that's
sufficient, and I'd say that's about 99% of all cases. But a tool rarely can
be more efficient and simpler, that's just the nature of it.

months,
justify

【在 x****d 的大作中提到】
: I against your idea as principle. We should gain productivity by making
: programmer's life easier, in general. CPU capacity is double every 6 months,
: we shouldn't spend valuable time to reduce resources usage.
: Do you know how much it costs to train programmers for something new like
: NIO2 in a big java shop? And the recruiting expenses is huge too. That is
: why some guys think we guys in java world move slow. But we have to justify
: the cost and benefit.

p*****2
发帖数: 21240
11

months,
justify
这话说的

【在 x****d 的大作中提到】
: I against your idea as principle. We should gain productivity by making
: programmer's life easier, in general. CPU capacity is double every 6 months,
: we shouldn't spend valuable time to reduce resources usage.
: Do you know how much it costs to train programmers for something new like
: NIO2 in a big java shop? And the recruiting expenses is huge too. That is
: why some guys think we guys in java world move slow. But we have to justify
: the cost and benefit.

h****r
发帖数: 2056
12
one more point,
aio or epoll kind is O(1), poll/select kind is O(n), there could be huge
performance difference at server end.
google "c10k" can get complete list of articles about this topic.

I

【在 x****d 的大作中提到】
: Thanks ah... So both Java NIO and NIO2 is non blocking, but only NIO2 is
: async.
: How about select? what is it?
: I know a bit about NIO2, I don't see much fun there. Why other guys said
: async programming is more fun? From programmer aspect, same thing, why do I
: care if it is async? I don't see how it makes my life any easier.

s*w
发帖数: 729
13
did not understand yesterday
do now

ready,

【在 g*****g 的大作中提到】
: Asynchronous is always non-blocking. Non-blocking is not necessarily
: asynchronous. An example is java nio and nio2, in java nio, you can use a
: thread to monitor many sockets by polling, and it checks if the data is
: ready.
: Asynchronous I/O on the other hand, employs the callback. So instead of
: checking your channels periodically, they'll notify you when they are ready,
: so you don't need a monitor thread.

x****d
发帖数: 1766
14
learn something new here every now and then. that is what keep me coming
back. but I have to admit many ppl here shit talking, that is what I don't
like, anyway...
1 (共1页)
进入Programming版参与讨论
相关主题
真正对异步有需求的应该是游戏类服务器An interview project: asynchronous socket programming
用node怎么把多个mysql query 的结果合起来vert.x 3.1月底发布,一个重要功能fiber
node 求算法尼玛 callback 真是反人类
node.js child process: 怎样保证1个命令执行完了再执行下一个?大家难道全是半路出家?
如何快速处理大量网上xml文件?Obamacare website
core java里有跟C++ std::async类似的东西吗?谁能说说同步/异步IO和阻塞/非阻塞IO的区别?
同步编程真郁闷看了一下C#的async await
看看大牛们为什么都远离.net学了这么多语言发现还是coffeescript最好用
相关话题的讨论汇总
话题: blocking话题: nio2话题: async话题: nio