Erjang already runs the Eshell, and self-hosts the Erlang compiler, and to some extend also runs
mochiweb. Last weekend was spent running micro-benchmarks and optimizing some tight loop stuff such as small integer performance, loops and function application. This has resulted in an over-all improvement for the "estone" Erlang performance test by a whopping 50%; and Erjang now consistently outperforms BEAM in the estone test suite. We're getting somewhere.
These numbers have been achieved despite significant congestion in the scheduler, which is the next thing to go "fix". There are many elements of performance where Erjang is far behind BEAM. One such example is message passing/context shift, where Erjang on a multi core is 5x behind BEAM. However, single-core performance of the same measure is at-par with BEAM. These test results indicate that this could possibly be fixed.
Below I've written some details about various things I've done to achieve these numbers, ... feel free to comment and/or ask questions.
- Floating point arithmetics is now largely "on the metal" in the sense that it generates roughly straight Java code. This means we're vastly faster than beam in this area (estones says 780%).
- Integer arithmetics is now ~2 times faster than before, now being close to BEAM performance (estone says 80% of BEAM). For some micro benchmarks we can show up to 3x beam performance for integers.
- Some special case optimizations involving
X=:=0improve loop performance: All
EObjects now respond to
- String manipulation got a lot faster by introducing a pool of
ESmallrepresenting bytes in the range
- JVM Code size is reduced by ~33% by a better code analysis that omits certain unnecessary code gen; this means smaller footprint and faster startup.
- Lots of specifics of BIFs, packet parsers, network-IO, file-IO, and other internal features added to support
Major missing bits
Here is a list of the features I see as the most important ones still not in Erjang:
- UDP+Multicast support. Should be rather straight-forward but there are a lot of details; I think we'll wait with Multicast till Java 7 comes out with a new non-blocking Multicast API.
- List comprehensions generate non-tail-recursive code, which is sometimes an issue because stacks become too deep.
- A few instructions are still missing; it would be nice to get that list removed.
Future Improvements: SMP
As you will see in the numbers below, if I disable SMP in Erjang it runs yet another 30% faster, and this leads me to believe that the next leap forward is to improve the scheduler and the code involved in sending messages. Running multiple threads slows things down in congestion, lock, timers etc.
The graph below shows how big a performance gain to expect if this scheduling code could be made perfect; and on top of this you would get the actual concurrency win. It shows the performance gain of the estone components with 1 thread in the thread pool, vs. running with 15. More threads makes it run slower! The port_io test is excluded because it currently cannot run with just one thread in the pool.
In the graph below you can see more details, comparing the results of running the "estone" suite with Erjang comparing some different configurations. Both the BEAM and the Erjang numbers are from on the same
Erlang R14A (erts-5.8) release.
The breakdown into the estone parts is shown below for the three different setups. Bigger is better. As you can see there are still many areas where we need to improve.
I put up a minimal self-contained Erjang/OTP R14A release here. You should be able to run it anywhere you have a Java6+ runtime environment. The performance tests themselves are in the [git repo], not in that tar ball.
Installing the pre-fabricated Erjang/R14A release
prompt$ wget http://github.com/downloads/krestenkrab/erjang/erjang-0.2.tgz prompt$ tar xzf erjang-0.2.tgz tar xvzf ../erjang-0.2.tgz x erjang-0.2/ x erjang-0.2/bin/ x erjang-0.2/erts-5.8/ x erjang-0.2/Install x erjang-0.2/lib/ x erjang-0.2/misc/ x erjang-0.2/README ... prompt$ cd erjang-0.2 promtp$ ./Install `pwd` prompt$ ./bin/erl <----- Make sure Erjang can launch! Eshell V5.8 (abort with ^G) may also report SASL startup msgs. 1> init:stop(). ... it works!
Getting and running the estone tests
prompt$ git clone git://github.com/krestenkrab/erjang.git prompt$ cd erjang/test_server prompt$ erlc estone_SUITE.erl prompt$ ../../erjang-0.2/bin/erl <---- Launches Erjang! Eshell V5.8 (abort with ^G) 1> ts:run(estone). ...
And off you go!
See you at Erjang Factory :-)