七种WebSocket框架的性能比较

前一篇文章使用四种框架分别实现百万websocket常连接的服务器介绍了四种websocket框架的测试方法和基本数据。 最近我又使用几个框架实现了websocket push服务器的原型,并专门对这七种实现做了测试。 本文记录了测试结果和一些对结果的分析。
这七种框架是:

最近用Golang实现了第八种,Go表现还不错。

阅读全文

Scala Collections 提示和技巧

原文: Scala Collections Tips and Tricks,
作者Pavel Fatin是JetBrains 的一名员工,为神器IntelliJ IDEA开发Scala插件。
受其工作Scala Collections inspections )的启发,他整理了这个关于Java Collections API技巧的列表。
一些技巧只在一些微妙的实现细节中体现,但是大部分技巧都是一般的常识,但是在大部分情况下被忽视了。
性和谐提示和技巧很有价值,可以帮你深入理解Scala Collections,可以是你的代码更快更简洁。

阅读全文

拆解 invokedynamic

作者: Rafael Winterhalter,原文发表在他的博客上:Dismantling invokedynamic

Many Java developers regarded the JDK’s version seven release as somewhat a disappointment. On the surface, merely a few language and library extensions made it into the release, namely Project Coin and NIO2. But under the covers, the seventh version of the platform shipped the single biggest extension to the JVM’s type system ever introduced after its initial release. Adding the invokedynamic instruction did not only lay the foundation for implementing lambda expressions in Java 8, it also was a game changer for translating dynamic languages into the Java byte code format.

While the invokedynamic instruction is an implementation detail for executing a language on the Java virtual machine, understanding the functioning of this instruction gives true insights into the inner workings of executing a Java program. This article gives a beginner’s view on what problem the invokedynamic instruction solves and how it solves i

阅读全文

Scala PartialFunction

PartialFunction是Scala另一个有趣的函数,也非常的有用。
一个PartialFunction[A, B]类型的函数是一个一元函数,接收一个类型为A的参数,返回类型为B的值。但是X的值域可以不覆盖A的整个值域,可以只覆盖部分的值域。其中isDefinedAt可以测试是否一个值是否落在了定义的参数值域上。

如果用简单的白话来讲,就是一个PartialFunction只处理参数的一个子集。

阅读全文

Scala Future and Promise

Futures 和 Promises是Scala的语言的功能加强: SIP-14。官方文档很好的介绍了这个功能。
Future提供了一个漂亮的方式提供并行执行代码的能力,高效且非阻塞。Future可以并发地执行,可以提供更快,异步,非阻塞的并发代码。
通常,future和promise都是非阻塞的执行,可以通过回调函数来获得结果。但是,你也可以通过阻塞的方式串行的执行Future。
本文主要编译于官方文档,以及参考了其它一些网上公开的资料。

阅读全文

Scala Either, Left And Right

Scala中的Either是一个有趣的类,它代表两个可能的类型的其中一个类型的值。这两个值之间没有交集。
Either是抽象类,有两个具体的实现类: LeftRight
Either可以作为scala.Option的替换,可以用scala.util.Left替换scala.None,用scala.Right替换scala.Some
一般在时实践中使用scala.util.Left作为Failure,而scala.util.Right作为成功的值。
另一个类似的类是scala.util.Try

阅读全文