为什么 Cassandra 是用 Java 编写的?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2341866/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Why was Cassandra written in Java?
提问by Stefan Steiger
Question about Cassandra
Why the hell on earth would anybody write a database ENGINE in Java ?
I can understand why you would want to have a Java interface, but the engine...
I was under the impression that there's nothing faster than C/C++, and that a database engine shouldn't be any slower than max speed, and certainly not use garbage collection...
Can anybody explain me what possible sense that makes / why Cassandra can be faster than ordinary SQL that runs on C/C++ code ?
Edit:
Sorry for the "Why the hell on earth" part, but it really didn't make any sense to me.
I neglected to consider that a database, unlike the average garden-varitety user programs, needs to be started only once and then runs for a very long time, and probably also as the only program on the server, which self-evidently makes for an important performance difference.
I was more comparing/referencing to a 'disfunctional' (to put it mildly) Java tax program I was using at the time of writing (or rather would have liked to use).
In fact, unlike using Java for tax programs, using Java for writing a dedicated server program makes perfect sense.
关于Cassandra 的问题
为什么有人会用 Java 编写数据库引擎?
我可以理解为什么你想要一个 Java 接口,但是引擎......
我的印象是没有比 C/C++ 更快的了,而且数据库引擎不应该比最大速度慢,当然不使用垃圾收集...
谁能解释一下,为什么 Cassandra 比在 C/C++ 代码上运行的普通 SQL 更快?
编辑:
对不起,“为什么是地球上的地狱”部分,但这对我来说真的没有任何意义。
我忽略了一个数据库,不像一般的花园式用户程序,只需要启动一次,然后运行很长时间,而且可能也是服务器上唯一的程序,这不言而喻重要的性能差异。
我更多地比较/参考了我在撰写本文时正在使用(或者更确切地说,更愿意使用)的“功能失调”(委婉地说)Java 税务程序。
事实上,与使用 Java 编写税务程序不同,使用 Java 编写专用服务器程序非常有意义。
采纳答案by Kico Lobo
I can see a few reasons:
我可以看到几个原因:
- Security: it's easier to write secure software in Java than in C++ (remember the buffer overflows?)
- Performance: it's not THAT worse. It's definitely worse at startup, but once the code is up and running, it's not a big thing. Actually, you have to remember an important point here: Java code is continually optimized by the VM, so in some circumstances, it gets faster than C++
- 安全性:用 Java 编写安全软件比用 C++ 编写安全软件更容易(还记得缓冲区溢出吗?)
- 性能:并没有那么糟糕。启动时肯定更糟,但是一旦代码启动并运行,这不是什么大事。实际上,您必须记住这里的一个重点:Java 代码会被 VM 不断优化,因此在某些情况下,它会比 C++ 更快
回答by Martin
What do you mean, C++? Hand coded assembly would be faster if you have a few decades to spare.
你是什么意思,C++?如果您有几十年的空闲时间,手动编码组装会更快。
回答by Brian Agnew
Don't forget that Java VMs make use of a just-in-time (JIT) engine that perform on-the-fly optimisations to make Java comparable to C++ in terms of speed. Bearing in mind that Java is quite a productive language (despite its naysayers) and portable, together with the JIT optimisation capability, means that Java isn't an unreasonable choice for something like this.
不要忘记 Java 虚拟机利用即时 (JIT) 引擎执行即时优化,使 Java 在速度方面与 C++ 相媲美。请记住,Java 是一种非常高效的语言(尽管有反对者)和可移植性,再加上 JIT 优化功能,这意味着 Java 不是此类事情的不合理选择。
回答by Otto Allmendinger
The performance penalty for modern Java runtimes is not that big and programming in Java is less error-prone than in c.
现代 Java 运行时的性能损失并不大,而且用 Java 编程比在 c 中更不容易出错。
回答by Michael Borgwardt
Why the hell on earth would anybody write a database ENGINE in JAVA ?
到底为什么会有人用 JAVA 编写数据库引擎?
Platform independance is a pretty big factor for servers, because you have a lot more hardware and OS heterogenity than with desktop PCs. Another is security. Not having to worry about buffer overflows means most of the worst kind of security holes are simply impossible.
平台独立性对于服务器来说是一个非常重要的因素,因为与台式 PC 相比,您拥有更多的硬件和操作系统异构性。另一个是安全。不必担心缓冲区溢出意味着大多数最糟糕的安全漏洞都是不可能的。
I was under the impression that there's nothing faster than C/C++, and that a database engine shouldn't be any slower than max speed, and certainly not use garbage collection...
我的印象是没有什么比 C/C++ 更快的了,数据库引擎不应该比最大速度慢,当然也不要使用垃圾收集......
Your impression is incorrect. C/C++ is not necessarily faster than Java, and modern garbage collectors have a big part in that because they enable object creation to be incredibly fast.
你的印象是错误的。C/C++ 不一定比 Java 快,现代垃圾收集器在这方面发挥着重要作用,因为它们使对象创建速度非常快。