\chapter{Conclusions and Future Work}\label{ch:conc}
We have briefly introduced the JStar in-memory data architecture and described new JStar compiler options to generate a
JStar program into a naive parallel Java implementation, which uses general-purpose concurrent data structures to
construct the Delta tree and the Gamma database. As the default implementation inserts every tuple in both of these two
data storages, the waiting time in the Delta tree and the efficiency of the Gamma database often limits the speedup
of the JStar program. Thus, we developed several inlining optimisations to reduce the total number of tuples in the
Delta tree and the Gamma database. Inlining the Delta nodes (the \flag{noDelta} optimisation) can avoid the waiting time
that a tuple is queued in the Delta tree and trigger the tuple rules immediately when the tuple is created.
Avoiding tuples inserting into the Gamma database (the \flag{noGamma} optimisation) can reduce memory usage as the JVM
does not need to create those tables in the Gamma database.
\par This thesis also defines the performance tuning process for JStar programs. By analyzing the task dependency graphs
and applying the corresponding optimisation strategies, the performance of the parallel and sequential JStar program can
be improved to a certain extent which is shown by the case studies. But further parallelism requires customized data
structures, e.g. light-weight and fixed-sized Java arrays can be used to store the tuples in the Gamma database in some
programs.
In this process, we can test the optimisation strategy or the data structure choice by following the tuning procedures
without needing to change the JStar source program.
\par We followed the performance tuning process to improve the speedups on four case studies: \keyword{PvWatts},
\keyword{ Dijkstra's shortest path}, \keyword{Median-Finding} and \keyword{Matrix Multiplication}. Their benchmark
experiments were conducted on different multi-core machines as the Symphony cluster or the NeSI cluster use an automatic
scheduler to dispatch the parallel tasks. Benchmark results show that three case studies have very good speedups, but
the \keyword{PvWatts} case study has low speedup. These good speedups result from the combination of the optimisation
strategies and the choice of efficient Gamma table data structure.
But the \keyword{PvWatts} case is more complicated than the others, because it involves bulk file input communication
and data summation, which may cause race hazards if the reducers perform their parallel tasks before the readers.
Thus, we implemented the \keyword{Disruptor} version of PvWatts program to pipeline the readers and the reducers to get
a better performance. Compared to the theoretical speedup (Amdahl's law), the Disruptor PvWatts program has a fairly
good speedup and a slightly higher speedup than the standard JStar strategy of using the Delta tree to send tuples
from one rule to other rules.
This shows that the Disruptor ring buffer can be an efficient way of sending tuples between rules and a useful alternative
to the Delta tree for some programs (e.g. when reordering of tuples is not required.) It also shows that JStar
allows a wide variety of parallel implementation strategies without changing the JStar source code.
\paragraph{Future Work}
Our work in this thesis can display the data dependency explicitly and provides a way to customize the data
structures used in the Delta tree or the Gamma table. Possible areas for future work include:
\begin{itemize}
  \item allow the compiler to introduce more aggressive parallelism, for example, by parallelizing \keyword{for}
  loops and \keyword{for} loops with reducers.
  \item allow the users to view the parallelism of the program with more kinds of graphs.
  \item automate the generation of a wider range of the Gamma data structures, involving \class{Hashtable} and Java
  \class{arrays}.
\end{itemize}
\par After the work done in this thesis, we have shown that the JStar compiler with appropriate optimisation options
can generate efficient parallel Java code with reasonably good speedup on multi-core computers. These suggestions
for future work have the potential to make the tuning process easier and allow even more parallelism in programs with
complex rules.
\cleardoublepage
