Groovy 和 Grails 与 Scala,为什么 Twitter 选择 Scala?

发布于 2024-11-02 02:20:33 字数 1432 浏览 1 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

灼疼热情 2024-11-09 02:20:33

虽然只有 Twitter 可以回答这个问题,但你基本上问错了问题。您应该问自己是什么业务或技术问题使 Scala 对 Twitter 有用。

事实上,如果您阅读有关 Twitter 在 Scala 中集成代码,您就会看到他们不只是抛弃 Rails;他们构建了系统来支持 Scala 中的部分应用程序,并重构了现有代码以与 Scala 中构建的服务进行交互。

在某种程度上,他们的主要技术关注点不再是网络应用程序本身,而是更多地关注消息传递和通知。 Groovy 和 Grails 不会比 Rails 更好地(或者可能更好)帮助他们解决这个问题。 Scala 和其他函数式语言通过最小化可变状态使推理高度并发问题变得更加容易。它为并发问题提供了一个参与者模型,可以更轻松地将某些类别的应用程序扩展到多个处理器和多个服务器。

从本质上讲,这就是为什么您应该拥有不止一种工具的原因。有些问题并不像存储数据和呈现数据那么简单。使用纯 Ruby 工具可以取得很大的成果,但在处理需要线程或跨多台机器分布的问题时仍然存在一些实际限制。

考虑到不同的团队成员或动机,他们可能很容易选择 Erlang 甚至 F#。但是,当问题并非真正出现在前端时,另一个 Web 框架可能会以更大的成本提供很少的好处。

While only Twitter can answer that, you're essentially asking the wrong question. You should be asking yourself what business or technical problem made Scala useful to Twitter.

In fact, if you read about Twitter's integration of code in Scala, you'll see that they didn't just toss out Rails; they built systems to support a portion of their application in Scala and refactored existing code to talk to services built in Scala.

At some point, their primary technical concern ceased to be about the web app itself and became more about messaging and notifications. Groovy and Grails wouldn't have helped them solve that problem much better (or perhaps ANY better) than Rails. Scala, and other functional languages, make it easier to reason about highly concurrent problems by minimizing mutable state. It provides an actor model for concurrency problems that makes it easier to scale certain categories of applications to multiple processors and multiple servers.

This is essentially the reason why you should have more than one tool in your repertoire. Some problems aren't as simple as storing data and presenting it. You can get pretty far with pure Ruby tools, but there are still some practical limits when dealing with problems that either need threading or distribution across multiple machines.

They might as easily have chosen Erlang or even F# given a different set of team members or motivations. But another web framework would have likely provided little benefit at a far more substantial cost when their problem wasn't really at the front end.

对岸观火 2024-11-09 02:20:33

也许您可以在这里找到答案:http://www.artima.com/scalazine/articles/twitter_on_scala.html< /a>

“可靠、高性能的代码”段落很好地表达了这一点:-)。

Bill Venners:我很好奇,Ruby 的人们会希望将其拼写出来
out:您能详细说明一下您认为 Ruby 语言缺少什么吗?
可靠、高性能代码的领域?

史蒂夫·简森:我在职业生涯中发现的一件事是
需要有长期存在的进程。和 Ruby 一样,就像许多脚本一样
语言,很难成为长期进程的环境。
但 JVM 非常擅长这一点,因为它已经针对这一点进行了优化
在过去的十年里。所以Scala提供了编写的基础
长期存在的服务器,这就是我们在 Twitter 上使用它的主要目的
现在。我们真正喜欢 Scala 的另一件事是静态类型
那并不痛苦。有时用 Ruby 说真的很好
比如,这是一个可选的类型注释。这就是我们的类型
真的很期待看到这里。我们发现这在 Scala 中非常有用,
能够指定类型信息。

Robey Pointer:此外,Ruby 还没有真正提供良好的线程支持。
它正在变得更好,但是当我们编写这些服务器时,绿色
线程是唯一可用的东西。绿色线程不使用
实际操作系统的内核线程。他们有点模拟线程
通过定期停止他们正在做的事情并检查是否
另一个“线程”想要运行。所以 Ruby 正在模拟一个
单核或处理器。我们想在多核服务器上运行
没有无限量的内存。如果你没有
良好的线程支持,你确实需要多个进程。和
因为 Ruby 的垃圾收集器不如 Java 的垃圾收集器,每个
进程占用大量内存。我们不能真正运行很多 Ruby
单机上的守护进程,无需消耗大量资源
的记忆。而通过在 JVM 上运行东西,我们可以运行许多
线程位于同一堆中,并让该进程占用所有线程
机器的游乐场内存。

亚历克斯·佩恩:我绝对想强调史蒂夫所说的话
打字。随着我们系统的成长,我们的 Ruby 系统中的很多逻辑
有点复制类型系统,无论是在我们的单元测试中还是作为
对模型的验证。我认为这可能只是大公司的财产
动态语言的系统,最终你会重写
你自己的类型系统,但你做得很糟糕。您正在检查
到处都是空值。有很多电话打给 Ruby 的
有点儿?方法,它询问:“这是一种 User 对象吗?因为
这就是我们所期待的。如果我们不明白这一点,这将会
爆炸。”当有一个
编程语言世界中已经存在的解决方案
几十年了。

Maybe you can find your answers here: http://www.artima.com/scalazine/articles/twitter_on_scala.html

Paragraph "Reliable, high performance code" catches it pretty well :-).

Bill Venners: I’m curious, and the Ruby folks will want it spelled
out: Can you elaborate on what you felt the Ruby language lacked in
the area of reliable, high performance code?

Steve Jenson: One of the things that I’ve found throughout my career is
the need to have long-lived processes. And Ruby, like many scripting
languages, has trouble being an environment for long lived processes.
But the JVM is very good at that, because it’s been optimized for that
over the last ten years. So Scala provides a basis for writing
long-lived servers, and that’s primarily what we use it for at Twitter
right now. Another thing we really like about Scala is static typing
that’s not painful. Sometimes it would be really nice in Ruby to say
things like, here’s an optional type annotation. This is the type we
really expect to see here. And we find that really useful in Scala, to
be able to specify the type information.

Robey Pointer: Also, Ruby doesn’t really have good thread support yet.
It’s getting better, but when we were writing these servers, green
threads were the only thing available. Green threads don't use the
actual operating system’s kernel threads. They sort of emulate threads
by periodically stopping what they are doing and checking whether
another “thread” wants to run. So Ruby is emulating threads within a
single core or a processor. We wanted to run on multi-core servers
that don’t have an infinite amount of memory. And if you don’t have
good threading support, you really need multiple processes. And
because Ruby’s garbage collector is not quite as good as Java’s, each
process uses up a lot of memory. We can’t really run very many Ruby
daemon processes on a single machine without consuming large amounts
of memory. Whereas with running things on the JVM we can run many
threads in the same heap, and let that one process take all the
machine’s memory for its playground.

Alex Payne: I’d definitely want to hammer home what Steve said about
typing. As our system has grown, a lot of the logic in our Ruby system
sort of replicates a type system, either in our unit tests or as
validations on models. I think it may just be a property of large
systems in dynamic languages, that eventually you end up rewriting
your own type system, and you sort of do it badly. You’re checking for
null values all over the place. There’s lots of calls to Ruby’s
kind_of? method, which asks, “Is this a kind of User object? Because
that’s what we’re expecting. If we don’t get that, this is going to
explode.” It is a shame to have to write all that when there is a
solution that has existed in the world of programming languages for
decades now.

紫南 2024-11-09 02:20:33

事后看来,他们可能会将其视为一个理性的决定,但我们知道……Scala 只是一个很酷的新玩具。

没有任何合理的理由为您的实施选择新的、未经证实的、未经测试的生产系统。

开发商以不考虑风险而闻名。这些家伙很幸运。我们没有听说过那些没有的人。

In the hindsight they may present it as a rational decision, but we know... Scala was just a cool new toy.

There cannot be any rational reason to choose new, unproven, untested in production system for your implementation.

Developers are famous for being inconsiderate to risks. These guys got lucky. We do not hear of those who wasn't though.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文