分析和优化Java流
Profiling and Optimizing Java Streams
摘要:
Java 8中添加了Stream API,以允许数据处理逻辑的声明式表达,通常是集合和数据集上的类似于map-reduce的数据转换。Stream API引入了两个关键的抽象。流是数据源中可用的元素序列,流管道包含操作(例如,map、filter、reduce),在执行时应用于流中的元素。流在Java开发人员中越来越流行,因为它们利用了函数式编程的简洁性并简化了数据处理的并行化。尽管流有很多好处,但与依赖命令式代码的数据处理相比,流可能会引入大量的开销,这主要是由额外的对象分配和回收以及虚拟方法调用的使用引起的。因此,开发人员需要研究流的运行时行为的方法,以减轻这种抽象开销并优化流处理。不幸的是,缺乏能够动态分析流的专用工具,以帮助开发人员专门定位降低应用程序性能的问题。在本文中,我们解决了流的分析和优化。我们提出了一种新的分析技术,用于测量的计算由流在过去的参考周期,我们用它来定位有问题的流与应用程序的性能产生重大影响。虽然准确性对于这一点至关重要,但插入的插装代码会导致执行额外的周期,这些周期部分包含在配置文件中。为了缓解这个问题,我们估计并补偿由插入的插装代码引起的额外周期。我们在StreamProf中实现了我们的方法,据我们所知,StreamProf是Java虚拟机(JVM)的第一个专用流分析器。与StreamProf,我们发现,周期分析是有效的,以检测有问题的流,其优化可以使显着的性能增益。我们还发现,支持并行流处理的任务的准确分析允许诊断负载不平衡,根据流相关的周期在线程级别的分布。我们对三个不同来源中公开提供的基于顺序和并行流的工作负载进行了评估。评估表明,我们的剖析技术是有效的,并产生准确的配置文件。此外,我们通过在文艺复兴时期的两个工作负载上引导与流相关的优化来展示我们的配置文件的可操作性。我们的优化只需要修改几行代码,同时实现高达5倍的加速。Java流在最近的工作中得到了广泛的研究,重点是开发人员如何使用流以及如何优化它们。当前的流优化方法主要依赖于静态分析技术,这些技术忽略了运行时信息,在检测由Java应用程序执行的所有流方面受到重要的限制,或者不适合于并行流的分析。了解顺序和并行流处理的动态行为及其对应用程序性能的影响对于帮助用户在使用流时做出更好的决策至关重要。
英文摘要:
The Stream API was added in Java 8 to allow the declarative expression of data-processing logic, typically map-reduce-like data transformations on collections and datasets. The Stream API introduces two key abstractions. The stream, which is a sequence of elements available in a data source, and the stream pipeline, which contains operations (e.g., map, filter, reduce) that are applied to the elements in the stream upon execution. Streams are getting popular among Java developers as they leverage the conciseness of functional programming and ease the parallelization of data processing. Despite the benefits of streams, in comparison to data processing relying on imperative code, streams can introduce significant overheads which are mainly caused by extra object allocations and reclamations, and the use of virtual method calls. As a result, developers need means to study the runtime behavior of streams in the goal of both mitigating such abstraction overheads and optimizing stream processing. Unfortunately, there is a lack of dedicated tools able to dynamically analyze streams to help developers specifically locate issues degrading application performance. In this paper, we address the profiling and optimization of streams. We present a novel profiling technique for measuring the computations performed by a stream in terms of elapsed reference cycles, which we use to locate problematic streams with a major impact on application performance. While accuracy is crucial to this end, the inserted instrumentation code causes the execution of extra cycles, which are partially included in the profiles. To mitigate this issue, we estimate and compensate for the extra cycles caused by the inserted instrumentation code. We implement our approach in StreamProf that, to the best of our knowledge, is the first dedicated stream profiler for the Java Virtual Machine (JVM). With StreamProf, we find that cycle profiling is effective to detect problematic streams whose optimization can enable significant performance gains. We also find that the accurate profiling of tasks supporting parallel stream processing allows the diagnosis of load imbalance according to the distribution of stream-related cycles at a thread level. We conduct an evaluation on sequential and parallel stream-based workloads that are publicly available in three different sources. The evaluation shows that our profiling technique is efficient and yields accurate profiles. Moreover, we show the actionability of our profiles by guiding stream-related optimizations on two workloads from Renaissance. Our optimizations require the modification of only a few lines of code while achieving speedups up to a factor of 5x. Java streams have been extensively studied by recent work, focusing on both how developers are using streams and how to optimize them. Current approaches in the optimization of streams mainly rely on static analysis techniques that overlook runtime information, suffer from important limitations to detect all streams executed by a Java application, or are not suitable for the analysis of parallel streams. Understanding the dynamic behavior of both sequential and parallel stream processing and its impact on application performance is crucial to help users make better decisions while using streams.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。