事件驱动的应用程序-选择什么语言或VM ?

时间:2022-03-30 22:47:14

I'm considering writing an app that has the following requirements. I'm proficient with Ruby, but I'm willing to learn a new language like Scala, Clojure or Python.

我正在考虑写一个有以下要求的应用。我精通Ruby,但我愿意学习Scala、Clojure或Python等新语言。

Concurrency / Best performance

并发性/最好的性能

This is my main goal. It needs to be amazingly fast and support concurrency in a decent way.

这是我的主要目标。它需要以惊人的速度和良好的方式支持并发。

Use Redis as a back-end

使用Redis作为后端

This won't be a big problem, redis has a wide range of drivers available, but it may influence the final decision on a language/platform.

这不是什么大问题,redis有很多可用的驱动程序,但是它可能会影响语言/平台的最终决定。

Websockets support

Websockets支持

Good support for websockets is a must. Using an add-on library (like Cramp for Ruby::EM) is okay.

必须对websockets提供良好的支持。使用附加库(比如Ruby::EM的抽筋)是可以的。

Options

选项

I've gathered the following options:

我收集了以下选项:

  • Ruby EventMachine
  • Ruby EventMachine
  • Python Twisted
  • Python扭曲
  • Node.js
  • node . js
  • Clojure
  • Clojure
  • Scala
  • Scala
  • Java
  • Java

Writing raw C or assembler are not viable options at this time.

现在编写原始C或汇编程序并不是可行的选择。

Concurrency

并发性

Ruby 1.9 still uses the GIL, where as all JVM based solutions can use native threads. I'm not sure about Node.js in this case.

Ruby 1.9仍然使用GIL,因为所有基于JVM的解决方案都可以使用本地线程。我不确定节点。js在这种情况下。

How does the selected language affect performance?

所选语言如何影响性能?

The question

这个问题

What do you recommend and why? Do you have hands-on experience? Please enlighten me (and the rest of *)

你推荐什么,为什么?你有实践经验吗?请启发我(和其他的*)

4 个解决方案

#1


4  

I'd vote for Clojure if high performance concurrency is your main criteria. Clojure was basically designed for concurrent development from the beginning, and there have been some impressive Clojure demos running on 800+ core Azul boxes.

如果高性能并发是您的主要标准,我将投票支持Clojure。Clojure从一开始就是为并发开发而设计的,并且有一些令人印象深刻的Clojure演示在800+核心的Azul盒上运行。

It is very much worth looking at this video presentation to understand Clojure's approach to concurrency:

为了理解Clojure处理并发的方法,这段视频非常值得一看:

http://www.infoq.com/presentations/Are-We-There-Yet-Rich-Hickey

http://www.infoq.com/presentations/Are-We-There-Yet-Rich-Hickey

The main trick in Clojure's concurrency performance is a clever implementation of Software Transactional Memory (STM) that lets you conduct many concurrent transactions without complex and expensive locking schemes. It also uses persistent data structures to give immutability and efficient management of multiple versions of data. It's very cool.

Clojure并发性能的主要诀窍是巧妙地实现了软件事务内存(STM),它允许您在不使用复杂和昂贵的锁方案的情况下执行许多并发事务。它还使用持久性数据结构来提供不变性和对多个版本数据的有效管理。这是非常酷的。

As for general purpose performance, Clojure is pretty fast already and getting even faster with the new 1.3 alpha branch. A stated aim of Rich Hickey (Clojure's creator) is to allow you to do anything in Clojure with the same speed that you can do it pure Java.

至于通用性能,Clojure已经相当快了,而且在新的1.3 alpha分支中速度更快了。Rich Hickey (Clojure的创建者)的一个明确目标是允许您以与纯Java相同的速度在Clojure中执行任何操作。

Other things in Clojure that I really like but may or may not be relevant to you:

在Clojure中我真正喜欢但可能与你无关的其他事情:

  • Hugely powerful LISP-style macro system - "code is data" and you can manipulate it as such
  • 强大的lisp风格的宏系统——“代码就是数据”,你可以这样操作它
  • It's a fully fledged functional language
  • 它是一种功能完备的语言
  • It's dynamically typed by default (for flexibility and quick prototyping), but you can add static type hints if you need to (for better performance)
  • 默认情况下它是动态类型化的(为了灵活性和快速原型),但是如果需要,您可以添加静态类型提示(为了更好的性能)
  • Excellent JVM / Java integration, so you can make use of all the good Java libraries and tools out there (e.g. Netty for event-driven server communications)
  • 优秀的JVM / Java集成,因此您可以使用所有优秀的Java库和工具(例如,用于事件驱动的服务器通信的Netty)

#2


6  

Clojure is about twice as fast as node.js, which is about three times faster than Python which is held to be faster than ruby.

Clojure的速度是node的两倍。js,比Python*倍,比ruby*倍。

#3


4  

On Clojure you could use Grizzly for async http processing and comet/websockets based apps. Redis is a great choice to cache and create a powerful distributed session with pub/sub protocol built-in Another big thing is use RabbitMQ or ZeroMQ to simulate a agent based distributed system and provide group, data or integration services for example.

在Clojure上,您可以使用Grizzly来进行异步http处理和基于comet/websockets的应用程序。Redis是一个很好的选择,它可以缓存并创建一个强大的分布式会话,其中内置了pub/sub协议,另一个重要的事情是使用RabbitMQ或ZeroMQ来模拟基于代理的分布式系统,并提供组、数据或集成服务。

#4


2  

Is relative ... a like clojure a lot and agree in parts with you , where clojure is one of the fastest language on jvm .

是相对的……clojure是jvm中速度最快的语言之一。

But the knowledge on language is essential and could confirm our feeling.

但是语言方面的知识是必不可少的,可以肯定我们的感觉。

Some interesting links on benchmarks , performance and comparisons :

一些关于基准、性能和比较的有趣链接:

http://bit.ly/dtqHAG

http://bit.ly/dtqHAG

"Premature optimization is the root of all evil", by Donald Knuth

“不成熟的优化是万恶之源”,唐纳德·克努斯(Donald Knuth)著。

#1


4  

I'd vote for Clojure if high performance concurrency is your main criteria. Clojure was basically designed for concurrent development from the beginning, and there have been some impressive Clojure demos running on 800+ core Azul boxes.

如果高性能并发是您的主要标准,我将投票支持Clojure。Clojure从一开始就是为并发开发而设计的,并且有一些令人印象深刻的Clojure演示在800+核心的Azul盒上运行。

It is very much worth looking at this video presentation to understand Clojure's approach to concurrency:

为了理解Clojure处理并发的方法,这段视频非常值得一看:

http://www.infoq.com/presentations/Are-We-There-Yet-Rich-Hickey

http://www.infoq.com/presentations/Are-We-There-Yet-Rich-Hickey

The main trick in Clojure's concurrency performance is a clever implementation of Software Transactional Memory (STM) that lets you conduct many concurrent transactions without complex and expensive locking schemes. It also uses persistent data structures to give immutability and efficient management of multiple versions of data. It's very cool.

Clojure并发性能的主要诀窍是巧妙地实现了软件事务内存(STM),它允许您在不使用复杂和昂贵的锁方案的情况下执行许多并发事务。它还使用持久性数据结构来提供不变性和对多个版本数据的有效管理。这是非常酷的。

As for general purpose performance, Clojure is pretty fast already and getting even faster with the new 1.3 alpha branch. A stated aim of Rich Hickey (Clojure's creator) is to allow you to do anything in Clojure with the same speed that you can do it pure Java.

至于通用性能,Clojure已经相当快了,而且在新的1.3 alpha分支中速度更快了。Rich Hickey (Clojure的创建者)的一个明确目标是允许您以与纯Java相同的速度在Clojure中执行任何操作。

Other things in Clojure that I really like but may or may not be relevant to you:

在Clojure中我真正喜欢但可能与你无关的其他事情:

  • Hugely powerful LISP-style macro system - "code is data" and you can manipulate it as such
  • 强大的lisp风格的宏系统——“代码就是数据”,你可以这样操作它
  • It's a fully fledged functional language
  • 它是一种功能完备的语言
  • It's dynamically typed by default (for flexibility and quick prototyping), but you can add static type hints if you need to (for better performance)
  • 默认情况下它是动态类型化的(为了灵活性和快速原型),但是如果需要,您可以添加静态类型提示(为了更好的性能)
  • Excellent JVM / Java integration, so you can make use of all the good Java libraries and tools out there (e.g. Netty for event-driven server communications)
  • 优秀的JVM / Java集成,因此您可以使用所有优秀的Java库和工具(例如,用于事件驱动的服务器通信的Netty)

#2


6  

Clojure is about twice as fast as node.js, which is about three times faster than Python which is held to be faster than ruby.

Clojure的速度是node的两倍。js,比Python*倍,比ruby*倍。

#3


4  

On Clojure you could use Grizzly for async http processing and comet/websockets based apps. Redis is a great choice to cache and create a powerful distributed session with pub/sub protocol built-in Another big thing is use RabbitMQ or ZeroMQ to simulate a agent based distributed system and provide group, data or integration services for example.

在Clojure上,您可以使用Grizzly来进行异步http处理和基于comet/websockets的应用程序。Redis是一个很好的选择,它可以缓存并创建一个强大的分布式会话,其中内置了pub/sub协议,另一个重要的事情是使用RabbitMQ或ZeroMQ来模拟基于代理的分布式系统,并提供组、数据或集成服务。

#4


2  

Is relative ... a like clojure a lot and agree in parts with you , where clojure is one of the fastest language on jvm .

是相对的……clojure是jvm中速度最快的语言之一。

But the knowledge on language is essential and could confirm our feeling.

但是语言方面的知识是必不可少的,可以肯定我们的感觉。

Some interesting links on benchmarks , performance and comparisons :

一些关于基准、性能和比较的有趣链接:

http://bit.ly/dtqHAG

http://bit.ly/dtqHAG

"Premature optimization is the root of all evil", by Donald Knuth

“不成熟的优化是万恶之源”,唐纳德·克努斯(Donald Knuth)著。