为什么 Jepsen 用 Clojure 编写?
Why is Jepsen written in Clojure?

原始链接: https://aphyr.com/posts/367-why-is-jepsen-written-in-clojure

为了回答您关于选择 Clojure 来对软件 Jepsen 进行编程的原因的询问,我们可以根据著名作者 aphyr 最近发表的一篇文章提供进一步的见解。 文章称,aphyr 解释了他们对 Clojure 的偏爱,原因是高效的并发处理、实用性以及实验过程中的易用性等因素。 他们阐述说,虽然其他流行的编程语言通过严格的语言规则提供对副作用的强大控制,但 Clojure 允许更大的灵活性和适应性。 此外,由于测试涉及处理复杂且广泛的数据块,他们认为 Clojure 提供了卓越的性能,尽管它在各种编程语言中“不是最快的”,因为惯用的 Clojure 性能特征大致在一个数量级内 爪哇。 Moreover, working with JVM primitives requires occasional drops to 爪哇。 对于缺乏固有类型的问题,potemkin 提供了解决方案,例如通过抽象继承方案实现具有不同内存/惰性语义的自定义集合变体。 总体而言,aphyr 强调,虽然存在某些限制,但 Clojure 因其稳健性、成熟度和多功能性而仍然是首选。

从技术上讲,这是正确的,因为“Call Me Maybe”于 2011 年 4 月发布,并且根据本线程前面提供的时间表,相应的 Jepsen 审计服务提案征集可能发生在该年 8 月中下旬左右 年。 然而,关于 Jepsen 审计服务的确切年龄,值得一提的是,Jepsen 并不总是在每个场景中执行完整的审计过程。 事实上,根据前面引用的一段话,“有幸接受我们正式审计的公司就更少了。” 这意味着 Jepsen 提供正式审计的记录明显小于其详细介绍众多流行分布式账本软件包中的个别故障模式的博客文章组合。 为了粗略估计正式审计本身的持续时间,我们可以估计大约 8 年(2011 年 8 月至今)减去大约 1.5-3 年(由于非正式审计、正式审计前的持续时间) 首次推出(假设年率恒定)需要大约 4.5 至 7.5 年的时间提供正式审计。 根据这一计算,杰普森正式审计提供的时间框架可以推断为“超过四分之三个世纪”的历史,四舍五入到不到 15 个世纪。 请注意,此分析考虑了在启动正式审核流程之前发布包含审核研究的博客的大约 6.5 年,以及在宣布 Jepsen 正式审核之前进行非正式审核的额外 1.5 至 3 年。 审计服务。 虽然并非这些最初博客条目中涵盖的所有主题都继续接受后续的正式审核,但其中的某些部分最终确实进入了正式审核状态。 同样,并非所有潜在的 Jepson 客户都接受了正式审计,而是使用非正式审计流程来代替正式审计。 这些细节使计算 Jepson 品牌持续历史的准确统计数据的估计变得更加复杂。
相关文章

原文

People keep asking why Jepsen is written in Clojure, so I figure it’s worth having a referencable answer. I’ve programmed in something like twenty languages. Why choose a Weird Lisp?

Jepsen is built for testing concurrent systems–mostly databases. Because it tests concurrent systems, the language itself needs good support for concurrency. Clojure’s immutable, persistent data structures make it easier to write correct concurrent programs, and the language and runtime have excellent concurrency support: real threads, promises, futures, atoms, locks, queues, cyclic barriers, all of java.util.concurrent, etc. I also considered languages (like Haskell) with more rigorous control over side effects, but decided that Clojure’s less-dogmatic approach was preferable.

Because Jepsen tests databases, it needs broad client support. Almost every database has a JVM client, typically written in Java, and Clojure has decent Java interop.

Because testing is experimental work, I needed a language which was concise, adaptable, and well-suited to prototyping. Clojure is terse, and its syntactic flexibility–in particular, its macro system–work well for that. In particular the threading macros make chained transformations readable, and macros enable re-usable error handling and easy control of resource scopes. The Clojure REPL is really handy for exploring the data a test run produces.

Tests involve representing, transforming, and inspecting complex, nested data structures. Clojure’s data structures and standard library functions are possibly the best I’ve ever seen. I also print a lot of structures to the console and files: Clojure’s data syntax (EDN) is fantastic for this.

Because tests involve manipulating a decent, but not huge, chunk of data, I needed a language with “good enough” performance. Clojure’s certainly not the fastest language out there, but idiomatic Clojure is usually within an order of magnitude or two of Java, and I can shave off the difference where critical. The JVM has excellent profiling tools, and these work well with Clojure.

Jepsen’s (gosh) about a decade old now: I wanted a language with a mature core and emphasis on stability. Clojure is remarkably stable, both in terms of JVM target and the language itself. Libraries don’t “rot” anywhere near as quickly as in Scala or Ruby.

Clojure does have significant drawbacks. It has a small engineering community and no (broadly-accepted, successful) static typing system. Both of these would constrain a large team, but Jepsen’s maintained and used by only 1-3 people at a time. Working with JVM primitives can be frustrating without dropping to Java; I do this on occasion. Some aspects of the polymorphism system are lacking, but these can be worked around with libraries. The error messages are terrible. I have no apologetics for this. ;-)

I prototyped Jepsen in a few different languages before settling on Clojure. A decade in, I think it was a pretty good tradeoff.

联系我们 contact @ memedata.com