-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[jsscripting] GraalVM's optimised compiler or find another solution #15600
Comments
This issue has been mentioned on openHAB Community. There might be relevant details there: https://community.openhab.org/t/blockly-rules-after-upgrade-to-oh-4-0-1-very-slow/148503/55 |
Thinking a bit of it, I have changed the title of the issue to also discuss other solutions here. The community discussion IMO is getting to off-topic with some people not contributing to the technical solution of the problem but instead being very rude. |
Here are some tests I did today. Note that my dev and prod system are not equal. The prod system has hundreds of items and things, while the TEST system is minimal. Full Disclore: I used a very simple rule for the test intentionally. Let's start to measure the 32 Bit debian on a 64 bit Arm RP4
Let's start to measure the 64 Bit debian on a 64 bit Arm RP4 Here is the comprehensive test on my dev system which has a 64 Bit ARM PI4 and the Debian is also on ARM64. I installed two different JDKs .../17.0.7-graalce/bin/java The results are
openjdk 17.0.7 WITH caching: I then used a more complex rule and the result is more or less the same. openjdk 17.0.7 Without caching: -> So, it seems that if we assume that the openHAB setup itself does not have an impact, that JDK 64 Bit is MUCH FASTER So, how about GraalVM, will it be the holy Grail? The results are graalvm-ce 17.0.7 WITHOUT caching: graalvm-ce 17.0.7 WITH caching: -> So, it seems that if we assume that the openHAB setup itself does not have an impact, that graalVM 64 Bit is also much faster So, my take is
My take is that I go with the standard Java Zulu 64 bit implementation based on openhabian 64 bit as, in particular with caching on, it is more than fast enough even in development. I would be vary happy if someone would be able to verify the above results by doing the same or similar test on two different machines with the setup I described above. |
This issue has been mentioned on openHAB Community. There might be relevant details there: |
thanks for doing those measurements. I am not sure I interpret the results correctly (e.g. what 32bit and 64bit versions you compare on what machines, and whether you use OpenJDK OR Zulu). I am missing a lot of context here, basically your whole setup (what exactly do you mean by caching, what do you cache? how do you call into the script (likely with javax.script.ScriptEngine?) Do you execute the same script repeatedly, or just one script once?). In general, I strongly believe that a benchmark that runs for 2 seconds only is way to short in a Java environment. You will have a huge impact by startup and warmup effects. Christian |
The whole point is to measure those startup warmup effects. Subsequent runs of the rule are fast and if one were to run multiple times it would obscure what we are trying to measure in the first place. It's that first run after being loaded where the Helper Library is injected that is the problem that we are attempting to solve. We are trying to eliminate the 20-30 second delay between editing a rule and that first run of the rule. So we are only measuring that first run of the rule.
Caching refers to the helper library. The first time the script is run /~https://github.com/openhab/openhab-js gets loaded into the script. This library converts the native Java API to openHAB into JavaScript to allow for a smoother and more language pure environment. It is the loading of that library that is causing the 20-30 second delay. Subsequent runs reuses the script and that penalty is no longer an issue. As for the details on how that caching is done I can't say.
What is being shown is that by using GraalVM it brings that first run of the rule from 20 seconds down to 2 seconds. If I put @stefan-hoehn's result in a table (Raspberry Pi 4):
|
Hi @wirthi, if you have any questions about the implementation of the JS Scripting add-on, feel free to ask @digitaldan and me! When running a script using the JS Scripting add-on, a new This is the place where a In the next step, our helper library called openhab-js is injected to allow easy access to the openHAB Java APIs. It takes care of type conversions between Java and JS and provides easy access to openHAB.
To inject the library, the add-on bundle ships two different webpack bundled versions of the library: One that is compatible with require and one that exports the library's namespaces onto the global object.
Exactly to the point! |
For reference: „Caching“ of the openhab-js has been introduced with #14135. |
This issue has been mentioned on openHAB Community. There might be relevant details there: |
This issue has been mentioned on openHAB Community. There might be relevant details there: https://community.openhab.org/t/yet-another-js-scripting-first-run-delay-test-pi5/152774/2 |
Just wanted to mention another test I did:
Config:
|
I recently updated from openHAB 3.3 to 4.1, I'm running Raspberry Pi 4. Some of my Javascript Rules were very slow after the update (tens of seconds, when they were completing in a matter of seconds on OH3.3). This was also after they had been cached. It turned out to be the 32-bit vs. 64-bit thing mentioned here. My OH3.3 was running on 32-bit version of the openHABian SD image (as was recommended back in the days when I installed OH3). Obviously it was still 32-bit version after I had updated OH to 4.1. Based on the information in this thread I re-installed a second SD card with 64-bit edition of openHABian and now the same Javascript Rules are performing on the expected level again. Do you guys agree that this documentation is outdated and should be updated: Cheers, |
I think we agree here but I'm not sure that the maintainer of openHABian would agree. I think opening an issue for discussion is warranted as I think we have enough evidence here to show that using 64-bit is worth a recommendation. But there is a balance. If you are on an RPi 3, merely switching to 64-bit is likely to cause you to run out of RAM while running OH and 64-bits does make even the 4 GB on an RPi 4 a little tight. So it can't just be a simple "always use 64-bit". |
|
It's no panacea and comes with it's own issues even on machines with 4GB RAM like an RPi 4.
It's technically challenging and no one has volunteered to implement and support it.
Bookworm breaks a lot of stuff that openHABian relied upon to work. Support for bookworm is still in progress but it's way more than just copy the old stuff onto the new OS. Whole parts of openHABian are needing to be reimplemented. |
Well it's true that things have changed since those docs were written and I'll change them into a more balanced statement. This statement, however
is dead wrong, clearly not balanced and, sorry for the pun, too egoistic as to become part of any recommendation. openHABian is for everyone and in particular for all those that don't care about hardware but just want a working base system to focus on the application level, OH that is. And holding off not to comment on the openHABian bashing. |
I followed the discussion and the status of bookworm support of openahbian. Again, I think it is not a good idea to wait until sometimes in the future homegear and InfluxData runs on bookworm which is currently one of the reason why bookworm is not supported by openhab(ian). |
@mstormi |
There is a huge overlap between those users who would find it challenging to install all that stuff manually and users of openHABian. And it's those less technically capable users who are the audience of openHABian. Unfortunately, these are also the same users who will be using Blockly where 64-bit is needed to get acceptable performance on the first run of a rule. So it's a challenging situation. These are the users least able to adjust to changes. These are the users least able to do stuff manually. And not all of these users are new users and legacy support is a worthy consideration. Also, don't confuse recommendations on the openHABian docs with general recommendations. As soon as you enter "having to install openhab manually" you are out of scope for openHABian. You are now in scope of whatever OS you are installing on (e.g. https://www.openhab.org/docs/installation/linux.html) and the Prerequisites: https://www.openhab.org/docs/installation/#prerequisites. There we find the following:
So do we just throw some bindings under the bus? Does anyone know which bindings they are? If we "clearly recommend only 64-bit" we are clearly recommending a configuration that is known not to work for some officially supported add-ons. If we continue to clearly recommend 32-bit for ARM, we suffer performance problems for JS Scripting. Which set of users do we lead down the wrong path? Unless something changes, I don't think we can make a clear recommendation either way. And to make it even more complicated the information the first time user is going to need to make a good decision is likely to be information they won't have until they've already installed and worked with OH for a bit. So I propose the following:
Unless and until all bindings work in 64-bit on ARM we cannot just make a blanket "use 64-bit" recommendation. Unless and until we completely drop support for RPi 3s we cannot just make a blanket "use 64-bit" recommendation. Not until both of these occur can we switch to a 64-bit first approach. |
Good point Rich.
|
@egoist6 : The performance issue with Javascript on openHAB 4 is not limited to the first run of the script / rule. Some of my more performance expensive scripts (which involve quite heavy calculations) were running almost a minute on a 32-bit openHABian even after the first run. Execution time on 64-bit openHABian is a couple of seconds, and most of this time is spent in calling influxDB API on another server. |
Incredible. Wasn’t aware of this huge discrepancy. Thanks for letting us know. |
That was totally new to me actually. Do you know any particular add-on that is known not to be working and maybe even why? |
Which add-ons are 32bit only? |
Perhaps @wborn can remember? That sentence was added in openhab/openhab-docs#1067 (more than four years ago) |
The Telldus binding mentions using 32-bit: /~https://github.com/openhab/openhab-addons/tree/main/bundles/org.openhab.binding.tellstick#telldus-core-bridge Some dependencies like Netty and Google/AWS SDKs and anything using JNA also use native libraries. It is probably less of an issue nowadays because running a 64-bit ARM OS is more common nowdays compared to 4 years ago. |
Netty provides AARCH_64, X86_64 and RISCV64 bundles for |
@dabj123 - are you running 32 bit or 64 bit with the Tellstick binding? I found this almost six years old post where it seemed like 64 bit was working, but broke 32 bit support: https://community.openhab.org/t/oh2-tellstick-and-64-bit-debian/42469/17. However, that was with JNA > 4.1.0, and we are at 4.5.2 now (and passed 4.1 many years ago, #5335): openhab-addons/bundles/org.openhab.binding.tellstick/pom.xml Lines 23 to 29 in 51109f4
|
As we decided to drop 32-bit support for openHAB 5, the slow performance issue on 32-but is gone, and as we have added pre-compilation of all scrips at startup, the delay when running a script the first time is gone. I will therefore close this issue now as the issue that caused its creation will be fixed soon. |
Coming from https://community.openhab.org/t/blockly-rules-after-upgrade-to-oh-4-0-1-very-slow/148503/43?u=florian-h05, where users reported bad performance of JS Scripting/GraalJS.
As @wirthi, a GraalVM developer, explained, this is because we do not run GraalJS on GraalVM, you should at least use its optimised compiler.
GraalVM provided an example of how to run it on a stock JDK (https://www.graalvm.org/latest/reference-manual/js/RunOnJDK/), and even a Maven example: /~https://github.com/graalvm/graal-js-jdk11-maven-demo.
Regarding size limitations of the add-on: JS Scripting already is a pretty large add-on compared to the average, but if we can improve performance, I see no problem adding more MBs.
FYI our JavaScript Scripting add-on bundle is here: /~https://github.com/openhab/openhab-addons/tree/main/bundles/org.openhab.automation.jsscripting, there you can also find the Maven POM.
I've created this issue to discuss the inclusion of the GraalVM optimised compiler and focus on the technical aspects, for which IMO GitHub is better suited than our community forum.
@wirthi and @digitaldan, I'm neither a GraalVM expert nor a Maven expert, would be great if you both could have a look and check whether it is possible to include the compiler from the add-on, or this would be something to be done from openhab-distro side.
The text was updated successfully, but these errors were encountered: