由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - 大牛们讨论一下异步编程吧
相关主题
parallel programming的复杂性分层/流行工具技术名词scala并发
说了半天异步是大势所趋没什么疑问了这2个java concurrency + async 轮子, 哪个更好?
Java基于DI解决runtime dependency和异步执行,有啥好轮子?Performance Comparison Between Node.js and Java EE
同步编程真郁闷akka这些东西都是通信转行过来忽悠的
看了一下C#的async await关于clojure
scala的基于future并行async程序怎么写goodbug基本不会编程,就会吹牛逼
akka stream选什么http client?看了一下Meteor很不错
Typescript是不是实际上反 functional programming 的?zhuang来来来,既然要聊聊多线程,我们就做点case study
相关话题的讨论汇总
话题: async话题: 异步话题: node话题: await
进入Programming版参与讨论
1 (共1页)
p*****2
发帖数: 21240
1
感觉用了异步以后,再也不想用同步了
d*******r
发帖数: 3299
2
顶一下这个!
最近想用Node.js+MongoDB搭个prototype玩玩
不过始终觉得异步的写法很难受呢,难道是我太菜...
s***o
发帖数: 2191
3
这个需要大牛你先开讲,比如讲一下node有啥成功案例,尤其大一些的。
yahoo好像正在把php还是python换成node,不知折腾的咋样了
p*****2
发帖数: 21240
4

我就是node+mongo。你如果有问题我们可以一起探讨。我用了node之后,性能提高很多
倍。基本上就是Linkedin 30台服务器到3台服务器的差别。
从同步到异步是需要适应一下,不过适应了以后就牛逼了,可以做很多别的语言做不了
的事情。

【在 d*******r 的大作中提到】
: 顶一下这个!
: 最近想用Node.js+MongoDB搭个prototype玩玩
: 不过始终觉得异步的写法很难受呢,难道是我太菜...

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

我也不是大牛。我看到很多公司转node了,不过node还主要是集中在了前端,也就是抢
php, ruby, python这些语言的市场,优势太大。后端的话,还需要继续努力,不过我
觉得潜力很大,我就是用node做后端。
转到node的公司,我知道的
linkedin,
groupon,
airbnb,
当然还有很多公司转到java/scala了。但是异步编程即使ruby,python里边也不得不用
,不然性能提升不上去。
我感觉很多项目不一定都是很大的项目,大项目node肯定没有Java有优势,但是做小一
些的项目,尤其是做prototype和需求变化比较大的项目,node非常合适,而且一旦上
量,也跟的上去。node的问题主要是JS语言的限制吧,但是这么纯粹的异步框架,貌似
还没有第二个。其他语言做异步都要更麻烦很多。当然Go我没看过。

【在 s***o 的大作中提到】
: 这个需要大牛你先开讲,比如讲一下node有啥成功案例,尤其大一些的。
: yahoo好像正在把php还是python换成node,不知折腾的咋样了

G***l
发帖数: 355
6
C#里面异步不要太简单。msdn的例子:
private async void StartButton_Click(object sender, RoutedEventArgs e)
{
// ExampleMethodAsync returns a Task and has an int result.
// A value is assigned to intTask when ExampleMethodAsync reaches
// an await.
try
{
Task intTask = ExampleMethodAsync();
// You can do other work here that doesn't require the result from
// ExampleMethodAsync. . . .
ResultsTextBox.Text += "Doing other work before awaiting intTask. .
. . .n";
// Wait for intTask to complete, and then access the int result.
int intResult = await intTask;
// Or you can combine the previous two steps:
//int intResult = await ExampleMethodAsync();
// Process the result (intResult) . . . .
ResultsTextBox.Text += String.Format("Length: {0}nn", intResult);
}
catch (Exception)
{
// Process the exception. . . .
}
}
public async Task ExampleMethodAsync()
{
var httpClient = new HttpClient();
// The following line activates GetStringAsync, which is an asynchronous
method.
Task contentsTask = httpClient.GetStringAsync("http://msdn.microsoft.com");
// While the task is active, you can do other work.
ResultsTextBox.Text += "Doing other work before awaiting contentsTask. .
. . .n";
// When you await contentsTask, execution in ExampleMethodAsync is
suspended,
// and control returns to the caller, StartButton_Click.
string contents = await contentsTask;
// After contentTask completes, you can calculate the length of the
string.
int exampleInt = contents.Length;
//// You can combine the previous sequence into a single statement.
//int exampleInt = (await httpClient.GetStringAsync("http://msdn.microsoft.com")).Length;
ResultsTextBox.Text += "Preparing to finish ExampleMethodAsync.n";
// After the following return statement, any method that's awaiting
// ExampleMethodAsync (in this case, StartButton_Click) can get the
integer result.
return exampleInt;
}
这里面还有好几层的async/await。
这个eric lippert(是个语言大牛啊,离开微软加入了Coverity,就是王垠呆过的那个
,不知道王垠敢不敢说我比他还牛哈哈)的blog上有很多不错的例子http://blogs.msdn.com/b/ericlippert/archive/tags/async/

【在 p*****2 的大作中提到】
: 感觉用了异步以后,再也不想用同步了
p*****2
发帖数: 21240
7

昨天看到有人说C#异步搞的不错,是正路子。

【在 G***l 的大作中提到】
: C#里面异步不要太简单。msdn的例子:
: private async void StartButton_Click(object sender, RoutedEventArgs e)
: {
: // ExampleMethodAsync returns a Task and has an int result.
: // A value is assigned to intTask when ExampleMethodAsync reaches
: // an await.
: try
: {
: Task intTask = ExampleMethodAsync();
: // You can do other work here that doesn't require the result from

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

大牛能不能简单说一下C#的异步机制?我有点懒得自己查。

【在 G***l 的大作中提到】
: C#里面异步不要太简单。msdn的例子:
: private async void StartButton_Click(object sender, RoutedEventArgs e)
: {
: // ExampleMethodAsync returns a Task and has an int result.
: // A value is assigned to intTask when ExampleMethodAsync reaches
: // an await.
: try
: {
: Task intTask = ExampleMethodAsync();
: // You can do other work here that doesn't require the result from

g*****g
发帖数: 34805
9
scala+akka的异步也很纯粹。

【在 p*****2 的大作中提到】
:
: 大牛能不能简单说一下C#的异步机制?我有点懒得自己查。

g*****g
发帖数: 34805
10
node.js异步牛在单线程,整个stack没啥blocking call,跟C#走的路子不一样。

【在 G***l 的大作中提到】
: C#里面异步不要太简单。msdn的例子:
: private async void StartButton_Click(object sender, RoutedEventArgs e)
: {
: // ExampleMethodAsync returns a Task and has an int result.
: // A value is assigned to intTask when ExampleMethodAsync reaches
: // an await.
: try
: {
: Task intTask = ExampleMethodAsync();
: // You can do other work here that doesn't require the result from

相关主题
scala的基于future并行async程序怎么写scala并发
akka stream选什么http client?这2个java concurrency + async 轮子, 哪个更好?
Typescript是不是实际上反 functional programming 的?Performance Comparison Between Node.js and Java EE
进入Programming版参与讨论
G***l
发帖数: 355
11
如果你要知道细节的话,Eric Lippert的blog上有一个系列Asynchrony in C# 5。
async不等于parallelism或者concurrency,不一定是多线程的,也可以是单线程。抛
开compiler和runtime的实现,简单形象的来说async就是把你的程序分解成若干step并
且理清他们的前后依赖关系(await决定了依赖)。这样原本a->b(b1->b2->b3)->c(c1-
>c2)这样一串顺序的东西或可被拆分为细小的step并且形成a->b2->c1,b1->b3,c2这三
个互相独立的运行顺序。然后runtime自然可以选择把他们分别放到不同的thread上。

【在 p*****2 的大作中提到】
:
: 大牛能不能简单说一下C#的异步机制?我有点懒得自己查。

c***d
发帖数: 996
12
这个说法比较糊涂啊。 async 在 user space上原本就两种实现, 一个是基于轻量
mutex出来的pthread, 一个是基于epoll/kqueue封装出来的libevent. 你可以说async
不等于性能, 但说async不等于concurrency, 这个需要一些超过普遍认知的定义。

c1-

【在 G***l 的大作中提到】
: 如果你要知道细节的话,Eric Lippert的blog上有一个系列Asynchrony in C# 5。
: async不等于parallelism或者concurrency,不一定是多线程的,也可以是单线程。抛
: 开compiler和runtime的实现,简单形象的来说async就是把你的程序分解成若干step并
: 且理清他们的前后依赖关系(await决定了依赖)。这样原本a->b(b1->b2->b3)->c(c1-
: >c2)这样一串顺序的东西或可被拆分为细小的step并且形成a->b2->c1,b1->b3,c2这三
: 个互相独立的运行顺序。然后runtime自然可以选择把他们分别放到不同的thread上。

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

我正在看AKKA。有两点使得不如node异步纯粹
1. AKKA 允许阻塞, node不允许
2. 如果要在AKKA上做纯粹的异步就需要scala提供所有的异步类库,这个貌似还没有达到
因此,感觉用AKKA写异步还是要麻烦不少。当然了AKKA牛在了是一个distributed
actor model。跟node不是一个level的。

【在 g*****g 的大作中提到】
: scala+akka的异步也很纯粹。
p*****2
发帖数: 21240
14

是呀。一个线程顶好几个进程。非常节省资源。而且没有race condition, deadlock的
问题。

【在 g*****g 的大作中提到】
: node.js异步牛在单线程,整个stack没啥blocking call,跟C#走的路子不一样。
k**********g
发帖数: 989
15

async/await 是很危险滴。。。
简单举例∶发送方必须知道/指定收件人是谁。在 C# 底下,收件人可以是∶main UI
thread,framework-specific worker thread (WPF),或是 TPL parallel thread
pool。
比如你要给你的仇人送些溪钱,为了掩人耳目,你故意写错收件人地址,而在回邮地址
写上仇人的地址。结果因为地址不清,邮差把信送到你父母家里去了。
详情请看 http://www.infoq.com/news/2013/07/async-await-pitfalls

【在 p*****2 的大作中提到】
:
: 是呀。一个线程顶好几个进程。非常节省资源。而且没有race condition, deadlock的
: 问题。

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

async
跟。感觉异步主要就是为了高并发的。

【在 c***d 的大作中提到】
: 这个说法比较糊涂啊。 async 在 user space上原本就两种实现, 一个是基于轻量
: mutex出来的pthread, 一个是基于epoll/kqueue封装出来的libevent. 你可以说async
: 不等于性能, 但说async不等于concurrency, 这个需要一些超过普遍认知的定义。
:
: c1-

d*******r
发帖数: 3299
17
我还在琢磨搞个什么idea,二爷已经搞出来,惭愧了...
前一个星期都在乱看些 noSQL database, 把流行的noSQL database的都看了一下.
Redis (C) 很流行的样子,好像多用在内存里面做缓存, 不算专门的Database.
CouchDB (Erlang), 据说迁移和 Peer Backup/Synchronization 功能非常好. 看了下
他们公司的产品感觉很多很晕,新合并了公司,现在有个CouchBase貌似包括了CouchDB
的功能.
还看到一些游戏公司(e.g. Rovio) 在用 Riak (也是Erlang写的,multiple data
center deployment 要按node收钱).
http://vimeo.com/65582437
看到最后,貌似这2个组合用的人最多最流行?
Node.js + MongoDB(C++) for quick prototyping
Java/Scala + Cassandra(Java) for serious players
Cassandra 很多大公司用,看着很靠谱的样子, 不知道有什么缺点没。
大家怎么看这些 noSQL database?

【在 p*****2 的大作中提到】
:
: async
: 跟。感觉异步主要就是为了高并发的。

d*******r
发帖数: 3299
18
写完发现,我说的有点跑题,抱歉 :D
主要是上次写网站,发现花时间最多的是折腾SQL,差点烦死了,所以觉得DB挺重要.
p*****2
发帖数: 21240
19

CouchDB
我用node, mongo, redis。redis也可以认为是一种简单的数据库,因为数据是
persistent的。
cassandra我昨天还再看,感觉争论挺大的呀,说FB自己都不用了。不过我感觉我们很
多存在mongo里的东西应该往cassandra上放。这个我还准备有时间好好研究一下。

【在 d*******r 的大作中提到】
: 我还在琢磨搞个什么idea,二爷已经搞出来,惭愧了...
: 前一个星期都在乱看些 noSQL database, 把流行的noSQL database的都看了一下.
: Redis (C) 很流行的样子,好像多用在内存里面做缓存, 不算专门的Database.
: CouchDB (Erlang), 据说迁移和 Peer Backup/Synchronization 功能非常好. 看了下
: 他们公司的产品感觉很多很晕,新合并了公司,现在有个CouchBase貌似包括了CouchDB
: 的功能.
: 还看到一些游戏公司(e.g. Rovio) 在用 Riak (也是Erlang写的,multiple data
: center deployment 要按node收钱).
: http://vimeo.com/65582437
: 看到最后,貌似这2个组合用的人最多最流行?

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

我也觉得SQL很麻烦,mongo挺好用的。

【在 d*******r 的大作中提到】
: 写完发现,我说的有点跑题,抱歉 :D
: 主要是上次写网站,发现花时间最多的是折腾SQL,差点烦死了,所以觉得DB挺重要.

相关主题
akka这些东西都是通信转行过来忽悠的看了一下Meteor很不错
关于clojurezhuang来来来,既然要聊聊多线程,我们就做点case study
goodbug基本不会编程,就会吹牛逼异步的话,所有语言都有自己的环境
进入Programming版参与讨论
g*****g
发帖数: 34805
21
别的不懂,谈谈Cassandra哈。Cassandra的主要弱点是ad-hoc query支持不好,当然没
有transaction有时候也是个问题。优点就是读写很快,特别是写的性能极佳。特别适
合高并发,
用户之间比较独立,没有太多关系数据的场合。

CouchDB

【在 d*******r 的大作中提到】
: 我还在琢磨搞个什么idea,二爷已经搞出来,惭愧了...
: 前一个星期都在乱看些 noSQL database, 把流行的noSQL database的都看了一下.
: Redis (C) 很流行的样子,好像多用在内存里面做缓存, 不算专门的Database.
: CouchDB (Erlang), 据说迁移和 Peer Backup/Synchronization 功能非常好. 看了下
: 他们公司的产品感觉很多很晕,新合并了公司,现在有个CouchBase貌似包括了CouchDB
: 的功能.
: 还看到一些游戏公司(e.g. Rovio) 在用 Riak (也是Erlang写的,multiple data
: center deployment 要按node收钱).
: http://vimeo.com/65582437
: 看到最后,貌似这2个组合用的人最多最流行?

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

我感觉cassandra非常适合写log,我们现在往mongo里边丢,觉得有问题,应该上
cassandra,大牛怎么看?

【在 g*****g 的大作中提到】
: 别的不懂,谈谈Cassandra哈。Cassandra的主要弱点是ad-hoc query支持不好,当然没
: 有transaction有时候也是个问题。优点就是读写很快,特别是写的性能极佳。特别适
: 合高并发,
: 用户之间比较独立,没有太多关系数据的场合。
:
: CouchDB

G***l
发帖数: 355
23
概念要清楚,async和concurrency不是一回事,虽然往往async会伴随着concurrency。
看看这个http://cs.brown.edu/courses/cs196-5/f12/handouts/async.pdf
最基本的101的概念。

【在 p*****2 的大作中提到】
:
: 我感觉cassandra非常适合写log,我们现在往mongo里边丢,觉得有问题,应该上
: cassandra,大牛怎么看?

d*******r
发帖数: 3299
24
看到 goodbug 他们 Netflix 就在用 Cassandra
貌似下面这个summary很靠谱?
http://kkovacs.eu/cassandra-vs-mongodb-vs-couchdb-vs-redis

【在 p*****2 的大作中提到】
:
: 我感觉cassandra非常适合写log,我们现在往mongo里边丢,觉得有问题,应该上
: cassandra,大牛怎么看?

G***l
发帖数: 355
25
再看看这个里面eric的回复
http://stackoverflow.com/questions/9898441/do-the-new-c-sharp-5
在c#里async不代表是concurrency。同样brown.edu的pdf里的纯理论说法,async也不
代表concurrency。看一下brown的那个pdf里的图你就明白async最重要的是把顺序的执
行拆分为一个个小段的step。

【在 G***l 的大作中提到】
: 概念要清楚,async和concurrency不是一回事,虽然往往async会伴随着concurrency。
: 看看这个http://cs.brown.edu/courses/cs196-5/f12/handouts/async.pdf
: 最基本的101的概念。

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

如果不能提高concurrency, 为什么要用异步呢?

【在 G***l 的大作中提到】
: 概念要清楚,async和concurrency不是一回事,虽然往往async会伴随着concurrency。
: 看看这个http://cs.brown.edu/courses/cs196-5/f12/handouts/async.pdf
: 最基本的101的概念。

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

这个看过。应该差不多吧。具体还得自己用过才有更深体会

【在 d*******r 的大作中提到】
: 看到 goodbug 他们 Netflix 就在用 Cassandra
: 貌似下面这个summary很靠谱?
: http://kkovacs.eu/cassandra-vs-mongodb-vs-couchdb-vs-redis

N********n
发帖数: 8363
28

C#当年设计的出发点之一就是尽量支持异步模式。早期的PATTERN比较罗嗦,
有了ASYNC/AWAIT之后既方便又灵活。

【在 G***l 的大作中提到】
: C#里面异步不要太简单。msdn的例子:
: private async void StartButton_Click(object sender, RoutedEventArgs e)
: {
: // ExampleMethodAsync returns a Task and has an int result.
: // A value is assigned to intTask when ExampleMethodAsync reaches
: // an await.
: try
: {
: Task intTask = ExampleMethodAsync();
: // You can do other work here that doesn't require the result from

G***l
发帖数: 355
29
都说了概念要清楚,抛开操作系统,编程语言,就说这些东西本质是什么。看这个akka
的术语:
http://doc.akka.io/docs/akka/snapshot/general/terminology.html
async是跟sync对应的,跟concurrency,multi-threading这些没有直接关系。就像你
可以把动物分为会游泳的不会游泳的,也可以分为在水里能呼吸的和在水里不能呼吸的
,也可以分为能长时间闭气的不能长时间闭气的。虽然他们有某些关联。但不是一个层
面上的事情。

【在 p*****2 的大作中提到】
:
: 这个看过。应该差不多吧。具体还得自己用过才有更深体会

l*****t
发帖数: 2019
30
AKKA的adoption怎么样?
会不会因为node,所以既生瑜何生亮了。

akka

【在 G***l 的大作中提到】
: 都说了概念要清楚,抛开操作系统,编程语言,就说这些东西本质是什么。看这个akka
: 的术语:
: http://doc.akka.io/docs/akka/snapshot/general/terminology.html
: async是跟sync对应的,跟concurrency,multi-threading这些没有直接关系。就像你
: 可以把动物分为会游泳的不会游泳的,也可以分为在水里能呼吸的和在水里不能呼吸的
: ,也可以分为能长时间闭气的不能长时间闭气的。虽然他们有某些关联。但不是一个层
: 面上的事情。

相关主题
混乱的JVM异步平台说了半天异步是大势所趋没什么疑问了
问一个XCode的问题Java基于DI解决runtime dependency和异步执行,有啥好轮子?
parallel programming的复杂性分层/流行工具技术名词同步编程真郁闷
进入Programming版参与讨论
x****u
发帖数: 44466
31
异步是多核必须的选择。

【在 p*****2 的大作中提到】
: 感觉用了异步以后,再也不想用同步了
g*****g
发帖数: 34805
32
这个很显然,我写了一个Audit Log的系统,每天千万记录往里扔没有压力。

【在 p*****2 的大作中提到】
:
: 这个看过。应该差不多吧。具体还得自己用过才有更深体会

z****e
发帖数: 54598
33
应该如此,我一直主张aop+nosql做log
很爽

【在 g*****g 的大作中提到】
: 这个很显然,我写了一个Audit Log的系统,每天千万记录往里扔没有压力。
S**********n
发帖数: 264
34
Async in .net is done through using system threadpool. Current recommended
model is task model, before this it is APM, and background worker. All of
them used QueueUserWorkItem behind the scene. That is not some thing new,
similar stuff was supported in VC6.0. Java has similar models.
For applications, Async has to go through a different thread. For .net, as
long as managed thread maps to native thread, async problem is still a
concurrent problem. Threadpool is not magic.
N********n
发帖数: 8363
35

Async is not about a whole new concurrency model. Nothing is. Everything
internally still has to go through the OS level threads.
Async is used to simplify async coding so that you no longer need
to pair a lot async callback methods up. Your C# code becomes a lot
more readable while still executing asynchronously.

【在 S**********n 的大作中提到】
: Async in .net is done through using system threadpool. Current recommended
: model is task model, before this it is APM, and background worker. All of
: them used QueueUserWorkItem behind the scene. That is not some thing new,
: similar stuff was supported in VC6.0. Java has similar models.
: For applications, Async has to go through a different thread. For .net, as
: long as managed thread maps to native thread, async problem is still a
: concurrent problem. Threadpool is not magic.

S**********n
发帖数: 264
36

Task model is one way for one to harness the power of system threadpool.
Period.

【在 N********n 的大作中提到】
:
: Async is not about a whole new concurrency model. Nothing is. Everything
: internally still has to go through the OS level threads.
: Async is used to simplify async coding so that you no longer need
: to pair a lot async callback methods up. Your C# code becomes a lot
: more readable while still executing asynchronously.

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

akka
这么说就没意思了。

【在 G***l 的大作中提到】
: 都说了概念要清楚,抛开操作系统,编程语言,就说这些东西本质是什么。看这个akka
: 的术语:
: http://doc.akka.io/docs/akka/snapshot/general/terminology.html
: async是跟sync对应的,跟concurrency,multi-threading这些没有直接关系。就像你
: 可以把动物分为会游泳的不会游泳的,也可以分为在水里能呼吸的和在水里不能呼吸的
: ,也可以分为能长时间闭气的不能长时间闭气的。虽然他们有某些关联。但不是一个层
: 面上的事情。

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

还真有点这个意思。我感觉如果做的不大,node很好使。

【在 l*****t 的大作中提到】
: AKKA的adoption怎么样?
: 会不会因为node,所以既生瑜何生亮了。
:
: akka

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

recommended
as
这个写的不错。因此跟node还是很不一样的。

【在 S**********n 的大作中提到】
: Async in .net is done through using system threadpool. Current recommended
: model is task model, before this it is APM, and background worker. All of
: them used QueueUserWorkItem behind the scene. That is not some thing new,
: similar stuff was supported in VC6.0. Java has similar models.
: For applications, Async has to go through a different thread. For .net, as
: long as managed thread maps to native thread, async problem is still a
: concurrent problem. Threadpool is not magic.

N********n
发帖数: 8363
40

Unless these node.js guys write their own OS (which is not the case)
they too have to play within the confine of threads.
Asynchronous coding boils down to one thing: could you unblock yourself
when you are waiting? Main app frameworks such as .Net and Java support
non-block execution long ago so there's really nothing special about it.
It's considered new probably only in the script language world.
The difference is who can support it elegantly. Node.js seems still
stuck in the callback mode while .Net already moves past it w/ the
new async support.

【在 S**********n 的大作中提到】
:
: Task model is one way for one to harness the power of system threadpool.
: Period.

相关主题
同步编程真郁闷akka stream选什么http client?
看了一下C#的async awaitTypescript是不是实际上反 functional programming 的?
scala的基于future并行async程序怎么写scala并发
进入Programming版参与讨论
y*******g
发帖数: 6599
41
async io API是OS level 提供的。做web server 的话node是不需要自己写os吧
当然一定要用node去做解码计算什么那没办法。

【在 N********n 的大作中提到】
:
: Unless these node.js guys write their own OS (which is not the case)
: they too have to play within the confine of threads.
: Asynchronous coding boils down to one thing: could you unblock yourself
: when you are waiting? Main app frameworks such as .Net and Java support
: non-block execution long ago so there's really nothing special about it.
: It's considered new probably only in the script language world.
: The difference is who can support it elegantly. Node.js seems still
: stuck in the callback mode while .Net already moves past it w/ the
: new async support.

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

.net 异步是不是thread safe的?

【在 N********n 的大作中提到】
:
: Unless these node.js guys write their own OS (which is not the case)
: they too have to play within the confine of threads.
: Asynchronous coding boils down to one thing: could you unblock yourself
: when you are waiting? Main app frameworks such as .Net and Java support
: non-block execution long ago so there's really nothing special about it.
: It's considered new probably only in the script language world.
: The difference is who can support it elegantly. Node.js seems still
: stuck in the callback mode while .Net already moves past it w/ the
: new async support.

N********n
发帖数: 8363
43

Like I said "异步" is ALL ABOUT NON-BLOCK EXECUTION. It does not
affect your thread safety.

【在 p*****2 的大作中提到】
:
: .net 异步是不是thread safe的?

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

node是thread safe的。

【在 N********n 的大作中提到】
:
: Like I said "异步" is ALL ABOUT NON-BLOCK EXECUTION. It does not
: affect your thread safety.

k**********g
发帖数: 989
p*****2
发帖数: 21240
46

嗯。node特别适合IO多的situation。

【在 y*******g 的大作中提到】
: async io API是OS level 提供的。做web server 的话node是不需要自己写os吧
: 当然一定要用node去做解码计算什么那没办法。

N********n
发帖数: 8363
47

Of course it's thread safe since it only has one thread. You can not
get any safer than that. But then it runs on multiple processes so
now instead of multi-thread issues you have multi-process issues.
Everything is trade-in. There's no magic here.

【在 p*****2 的大作中提到】
:
: 嗯。node特别适合IO多的situation。

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

multi-process有什么问题?

【在 N********n 的大作中提到】
:
: Of course it's thread safe since it only has one thread. You can not
: get any safer than that. But then it runs on multiple processes so
: now instead of multi-thread issues you have multi-process issues.
: Everything is trade-in. There's no magic here.

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

cassandra有没有什么好的book或者training呢(免费的)?还是说直接看文档就上手
了。我感觉貌似上手应该不难。

【在 g*****g 的大作中提到】
: 这个很显然,我写了一个Audit Log的系统,每天千万记录往里扔没有压力。
N********n
发帖数: 8363
50

The same synchronization issues when multiple processes contend for
the same resources. There's no magic here.

【在 p*****2 的大作中提到】
:
: cassandra有没有什么好的book或者training呢(免费的)?还是说直接看文档就上手
: 了。我感觉貌似上手应该不难。

相关主题
这2个java concurrency + async 轮子, 哪个更好?关于clojure
Performance Comparison Between Node.js and Java EEgoodbug基本不会编程,就会吹牛逼
akka这些东西都是通信转行过来忽悠的看了一下Meteor很不错
进入Programming版参与讨论
g*****g
发帖数: 34805
51
你错了,从架构上说node.js是单线程的,需要的是调用到的API都是non-blocking的。
万一是blocking的系统调用才自动加个线程。无论是java还是C#,都有一些类库用到了
synchronized或者threadlocal,所以完全模拟node.js的架构是不合适的。

【在 N********n 的大作中提到】
:
: The same synchronization issues when multiple processes contend for
: the same resources. There's no magic here.

g*****g
发帖数: 34805
52
There's no same resources to contend, node.js is not a universal model, it's
only for web service. Every request is independent and it doesn't which
process processes the request. Multi-processes are only to take advantage of
the computing power.

【在 N********n 的大作中提到】
:
: The same synchronization issues when multiple processes contend for
: the same resources. There's no magic here.

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

multi process有什么synchronization的问题?能不能具体说说?

【在 N********n 的大作中提到】
:
: The same synchronization issues when multiple processes contend for
: the same resources. There's no magic here.

N********n
发帖数: 8363
54

Generally if multiple processes are accessing the same resources (say
a DB) then there are race conditions to handle. If such contention
never exists in NODE's model then it can get away with it.

【在 p*****2 的大作中提到】
:
: multi process有什么synchronization的问题?能不能具体说说?

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

这个貌似数据库可以handle了吧?比如mongo,不需要写code自己handle吧?

【在 N********n 的大作中提到】
:
: Generally if multiple processes are accessing the same resources (say
: a DB) then there are race conditions to handle. If such contention
: never exists in NODE's model then it can get away with it.

b*******s
发帖数: 5216
56
最简单的,比如读写同一个文件

【在 p*****2 的大作中提到】
:
: 这个貌似数据库可以handle了吧?比如mongo,不需要写code自己handle吧?

N********n
发帖数: 8363
57

Many nowadays internet data solutions simply don't care race conditions
at all, which somehow works when all they need is a website able to
handle the social network load.

【在 p*****2 的大作中提到】
:
: 这个貌似数据库可以handle了吧?比如mongo,不需要写code自己handle吧?

l*****t
发帖数: 2019
58
千万当然没压力了。
Kafka都每天几十的billion的写。

【在 g*****g 的大作中提到】
: 这个很显然,我写了一个Audit Log的系统,每天千万记录往里扔没有压力。
l*****t
发帖数: 2019
59
其实我很想看看AKKA有没有戏。我一直对JavaScript 不感兴趣。

【在 p*****2 的大作中提到】
:
: 这个貌似数据库可以handle了吧?比如mongo,不需要写code自己handle吧?

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

我对JS也不感兴趣,但是CS就不同了。

【在 l*****t 的大作中提到】
: 其实我很想看看AKKA有没有戏。我一直对JavaScript 不感兴趣。
相关主题
zhuang来来来,既然要聊聊多线程,我们就做点case study问一个XCode的问题
异步的话,所有语言都有自己的环境parallel programming的复杂性分层/流行工具技术名词
混乱的JVM异步平台说了半天异步是大势所趋没什么疑问了
进入Programming版参与讨论
p*****2
发帖数: 21240
61

这个不对吧?数据错了也不行呀。再说你说的这个跟刚才的问题也没什么关系。

【在 N********n 的大作中提到】
:
: Many nowadays internet data solutions simply don't care race conditions
: at all, which somehow works when all they need is a website able to
: handle the social network load.

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

这个跟node有什么关系呢?

【在 b*******s 的大作中提到】
: 最简单的,比如读写同一个文件
g*****g
发帖数: 34805
63
I don't think DB needs explicit synchronization, it's built in as
transaction.

【在 N********n 的大作中提到】
:
: Many nowadays internet data solutions simply don't care race conditions
: at all, which somehow works when all they need is a website able to
: handle the social network load.

l*****t
发帖数: 2019
64
貌似Jeff Bean 很不同意你的观点。

【在 g*****g 的大作中提到】
: I don't think DB needs explicit synchronization, it's built in as
: transaction.

l*****t
发帖数: 2019
65
他也没说错吧。看你的app怎么实现了。consistency model和transaction在什么地方
实现,也都变来变去的。

【在 p*****2 的大作中提到】
:
: 这个跟node有什么关系呢?

N********n
发帖数: 8363
66

Social network sites don't care that much. If several people edit
the same item on Wiki the last editor wins. Wiki is not gonna try
to coordinate the concurrent access.
When you don't care data coherence you have nothing to synchronize
so you can go ahead w/ Node.js kinda framework.

【在 p*****2 的大作中提到】
:
: 这个跟node有什么关系呢?

N********n
发帖数: 8363
67

Transaction slows things down. These heavy loaded websites either try
to avoid it or have to pay for the expensive hardware able to handle
transactions under heavy load.

【在 g*****g 的大作中提到】
: I don't think DB needs explicit synchronization, it's built in as
: transaction.

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

last write win没错,但是如果两个一起write,最后结果一半一半也不对吧?或者先
写的win。还是需要sync吧。怎么可能一点没有。

【在 N********n 的大作中提到】
:
: Transaction slows things down. These heavy loaded websites either try
: to avoid it or have to pay for the expensive hardware able to handle
: transactions under heavy load.

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

跟先前的问题有啥关系呢?

【在 l*****t 的大作中提到】
: 他也没说错吧。看你的app怎么实现了。consistency model和transaction在什么地方
: 实现,也都变来变去的。

l*****t
发帖数: 2019
70
ditto上面我说Jeff Bean。

【在 N********n 的大作中提到】
:
: Transaction slows things down. These heavy loaded websites either try
: to avoid it or have to pay for the expensive hardware able to handle
: transactions under heavy load.

相关主题
说了半天异步是大势所趋没什么疑问了看了一下C#的async await
Java基于DI解决runtime dependency和异步执行,有啥好轮子?scala的基于future并行async程序怎么写
同步编程真郁闷akka stream选什么http client?
进入Programming版参与讨论
l*****t
发帖数: 2019
71
喔我可能没看清楚。
treadmill上灌水我容易么。。

【在 p*****2 的大作中提到】
:
: 跟先前的问题有啥关系呢?

g*****g
发帖数: 34805
72
Sure, I am just saying node.js isn't exclusive to transaction.
It's an totally different problem on DB side. node.js is just for high
throughput web application servers that can save cycles on synchronization.
It reduces hardware cost, it doesn't resolve DB bottleneck.

【在 N********n 的大作中提到】
:
: Transaction slows things down. These heavy loaded websites either try
: to avoid it or have to pay for the expensive hardware able to handle
: transactions under heavy load.

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

Java Reactor好用吗?

【在 g*****g 的大作中提到】
: Sure, I am just saying node.js isn't exclusive to transaction.
: It's an totally different problem on DB side. node.js is just for high
: throughput web application servers that can save cycles on synchronization.
: It reduces hardware cost, it doesn't resolve DB bottleneck.

b*******s
发帖数: 5216
74
喔,没看见上下文

【在 p*****2 的大作中提到】
:
: Java Reactor好用吗?

c****e
发帖数: 1453
75
简单总结一下,C# async/await,python/twist 是让你用同步的方式写异步,写起来非
常简单,大大节省脑力。node.js强迫你都是异步,虽然callback很土,但是JS还是很
灵活的,写起来代码量并不大。至于performance, 不要有各种迷思,到了OS层次都是
一样的thread。最后快慢取决于有没有把代码分成最够小的块来异步。
至于说到node.js,比较喜欢MEAN stack: mongoDB, express.js, agularjs, node.js.
中前台都包了。除了很多scheduling, resource management这种重量级的backend
service,还真是价格便宜量又足。
q*c
发帖数: 9453
76
用了 异步以后再也不想 异步。
我们讨论了半天, 终结了异步的本质:
=== 异步就是当年的 goto 语句 ===
今天为什么没人用 goto, 就是为什么能不用异步就别用的原因。
goto 当年也是炙手可热的玩意 - 带来各种灵活性, 写各种牛屄难解的程序, 有巨
大的方便啊。

【在 p*****2 的大作中提到】
: 感觉用了异步以后,再也不想用同步了
q*c
发帖数: 9453
77
“大项目node肯定没有Java有优势” -- 为什么?
和为什么goto 搞死大项目的原因一样。异步多了没法 maintain.

【在 p*****2 的大作中提到】
:
: Java Reactor好用吗?

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

大项目可以上AKKA

【在 q*c 的大作中提到】
: “大项目node肯定没有Java有优势” -- 为什么?
: 和为什么goto 搞死大项目的原因一样。异步多了没法 maintain.

q*c
发帖数: 9453
79
人类历史总是不断重复类似的问题, 同样的本质。
基本上是前辈被某种短视的玩意搞死了, 痛苦的不行于是发明了正规的办法,
正规的办法总是比较官僚笨重, 而且花样少啊, 于是用多了就觉得沉闷。
而且后辈们总觉得自己比前辈聪明, 整天生活在前辈创造的单调简单的环里面不觉得
愉快,
就开始发明各种 short cut...然后就是轮回, 哈哈。

UI

【在 k**********g 的大作中提到】
: 同主题阅读∶
: http://stackoverflow.com/questions/10773564/which-would-be-bett

1 (共1页)
进入Programming版参与讨论
相关主题
zhuang来来来,既然要聊聊多线程,我们就做点case study看了一下C#的async await
异步的话,所有语言都有自己的环境scala的基于future并行async程序怎么写
混乱的JVM异步平台akka stream选什么http client?
问一个XCode的问题Typescript是不是实际上反 functional programming 的?
parallel programming的复杂性分层/流行工具技术名词scala并发
说了半天异步是大势所趋没什么疑问了这2个java concurrency + async 轮子, 哪个更好?
Java基于DI解决runtime dependency和异步执行,有啥好轮子?Performance Comparison Between Node.js and Java EE
同步编程真郁闷akka这些东西都是通信转行过来忽悠的
相关话题的讨论汇总
话题: async话题: 异步话题: node话题: await