Join patterns are a high-level programming construct for message-passing applications. They offer an intuitive and declarative approach for specifying how concurrent and distributed components coordinate, possibly depending on complex conditions over combinations of messages. Join patterns have inspired many implementations -- but most of them are not available as libraries: rather, they are domain-specific languages that can be hard to integrate into pre-existing ecosystems. Moreover, all implementations ship with a predefined matching algorithm, which may not be optimal depending on the application requirements. These limitations are addressed by `JoinActors`, a recently published library which integrates join patterns in the off-the-shelf Scala 3 programming language, and is designed to be modular w.r.t. the matching algorithm in use. In this work we address the problem of designing, developing, and evaluating a modular join pattern matching toolkit that (1) can be used as a regular library with a developer-friendly syntax within a pre-existing programming language, and (2) has an extensible design that supports the use and comparison of different matching algorithms. We analyse how `JoinActors` achieves goals (1) and (2) above. The paper that introduced `JoinActors` only briefly outlined its design and implementation (as its main goal was formalising its novel fair matching semantics*). In this work we present and discuss in detail an improved version of `JoinActors`, focusing on its use of metaprogramming (which enables an intuitive API resembling standard pattern matching) and on its modular design. We show how this enables the integration of multiple matching algorithms with different optimisations and we evaluate their performance via benchmarks covering different workloads. We illustrate a sophisticated use of Scala 3's metaprogramming for the integration of an advanced concurrent programming construct within a pre-existing language. In addition, we discuss the insights and "lessons learned" in optimising join pattern matching, and how they are facilitated by `JoinActors`'s modularity -- which allows for the systematic comparison of multiple matching algorithm implementations. We adopt the fair join pattern matching semantics and the benchmark suite from the paper that originally introduced `JoinActors`. Through extensive testing we ensure that our new optimised matching algorithms produce exactly the same matches as the original `JoinActors` library, while achieving significantly better performance. The improved version of `JoinActors` is the companion artifact of this paper. This work showcases the expressiveness, effectiveness, and usability of join patterns for implementing complex coordination patterns in distributed message-passing systems, within a pre-existing language. It also demonstrates promising performance results, with significant improvements over previous work. Besides the practical promise, `JoinActors`'s modular design offers a research playground for exploring and comparing new join pattern matching algorithms, possibly based on entirely different semantics.
翻译:Join模式是一种用于消息传递应用程序的高级编程构造。它提供了一种直观且声明式的方法,用于指定并发和分布式组件如何协调,这种协调可能依赖于消息组合上的复杂条件。Join模式已经启发了许多实现——但其中大多数并未以库的形式提供:相反,它们是领域特定语言,可能难以集成到已有的生态系统中。此外,所有实现都附带预定义的匹配算法,这可能并非所有应用场景下的最优选择。`JoinActors` 是一个最近发布的库,它解决了这些限制,将Join模式集成到现成的Scala 3编程语言中,并且设计上对所使用的匹配算法是模块化的。在这项工作中,我们解决了设计、开发和评估一个模块化Join模式匹配工具包的问题,该工具包(1)可以作为具有开发者友好语法的常规库在已有编程语言中使用,并且(2)具有可扩展的设计,支持使用和比较不同的匹配算法。我们分析了`JoinActors`如何实现上述目标(1)和(2)。介绍`JoinActors`的论文仅简要概述了其设计和实现(因为其主要目标是形式化其新颖的公平匹配语义*)。在这项工作中,我们详细展示并讨论了一个改进版本的`JoinActors`,重点在于其对元编程的使用(这使得API类似于标准模式匹配,非常直观)及其模块化设计。我们展示了这如何实现集成具有不同优化的多种匹配算法,并通过涵盖不同工作负载的基准测试评估了它们的性能。我们阐释了如何巧妙运用Scala 3的元编程,将一种高级并发编程构造集成到已有语言中。此外,我们讨论了在优化Join模式匹配过程中获得的见解和“经验教训”,以及`JoinActors`的模块化如何促进了这些工作——它允许对多种匹配算法实现进行系统比较。我们采用了最初介绍`JoinActors`的论文中提出的公平Join模式匹配语义和基准测试套件。通过大量测试,我们确保新的优化匹配算法产生的匹配结果与原始`JoinActors`库完全相同,同时实现了显著更好的性能。改进版的`JoinActors`是本文的配套成果。这项工作展示了在已有语言中,使用Join模式实现分布式消息传递系统中复杂协调模式的表达能力、有效性和可用性。它还展示了有前景的性能结果,相比之前的工作有显著提升。除了实际应用前景,`JoinActors`的模块化设计为探索和比较新的Join模式匹配算法(可能基于完全不同的语义)提供了一个研究平台。