Skip to content
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

Weather Predictor and weatherInit.rb issue #3

Open
himanshumps opened this issue Feb 28, 2018 · 13 comments
Open

Weather Predictor and weatherInit.rb issue #3

himanshumps opened this issue Feb 28, 2018 · 13 comments

Comments

@himanshumps
Copy link

himanshumps commented Feb 28, 2018

Example: examples/weather_predictor/
Graal VM version: 0.31
OS: RHEL7 docker image with gcc installed
Issue:
The code in weatherServer.js does not include weatherInit.rb file and due to which openweather api is never getting called. If I add the weatherInit.rb file to weatherServer.js file, I get error asking for installtion of llvm and libc++abi file.

This is how I imported the weatherInit.rb in weatherServer.js file

// Load the Ruby module
console.log("Initializing Openweather");
var weatherInitScript = fs.readFileSync("weatherInit.rb", "utf8");
Interop.eval("application/x-ruby", weatherInitScript);

weatherInit.rb

require 'openweather2'

Openweather2.configure do |config|
  # This is the endpoint and API key from the tests in the Openweather2 gem
  config.endpoint = 'http://api.openweathermap.org/data/2.5/weather'
  config.apikey = '7295c67949009c1bee1902192a08ccf1'
end

def tempInCity(name) 
  weather = Openweather2.get_weather(city: Truffle::Interop.from_java_string(name), units: 'metric')
  weather.temperature; 
end

Truffle::Interop.export('tempInCity', method(:tempInCity))

Error Trace:


Initializing Openweather
--
  | com.oracle.truffle.llvm.runtime.LLVMContext$ExternalLibrary@a86168cc not found!
  | libc++abi.so.1: cannot open shared object file: No such file or directory
  | org.truffleruby.language.control.RaiseException: you may need to install LLVM and libc++abi - see doc/user/installing-llvm.md (libc++abi.so.1: cannot open shared object file: No such file or directory) (RuntimeError)
  | unknown:0
  | unknown
  | ^
  | Error: you may need to install LLVM and libc++abi - see doc/user/installing-llvm.md (libc++abi.so.1: cannot open shared object file: No such file or directory) (RuntimeError)
@chrisseaton
Copy link

I get error asking for installtion of llvm and libc++abi file

So did you try installing them then?

The documentation is here https://github.com/oracle/truffleruby/blob/master/doc/user/installing-llvm.md. We should make sure that error message refers you to the Ruby documentation specifically.

@himanshumps
Copy link
Author

Is there a docker image that comes with LLVM and libc++abi libraries. I can use those to build the application.

@chrisseaton
Copy link

There is a GraalVM Docker image but it's focused on Java use and doesn't include these dependencies.

TruffleRuby includes Docker images that you could use:

https://github.com/oracle/truffleruby/tree/master/test/truffle/docker

It's probably best to just look at how those work and copy it locally.

But installing these libraries is fairly easy - that documentation page includes instructions for Oracle Linux, Ubuntu and Fedora, and you can guess at what you need in other distributions from that.

The need for these slightly unusual dependencies for Ruby should go away soon.

@himanshumps
Copy link
Author

himanshumps commented Feb 28, 2018

I went through the documentation. It does not have RHEL 7 way. I think I will have to use the fedora image because that's the one which is similar to RHEL7.

Are you aware of what package I can use via yum which can install these dependencies on RHEL7?

@chrisseaton
Copy link

RHEL 7 should be very similar to Oracle Linux 7... but that's the one where there aren't good packages, I see your problem now...

I can only recommend installing LLVM from scratch, as per our Oracle Linux 7 Dockerfile. I know that's a bad solution, sorry.

It might be best to run it in a Docker image based on Fedora.

@himanshumps
Copy link
Author

I wanted to show the GrallVM in one of the hackathon's within the company .. I think keeping time in mind (as it is due day after tomorrow) I will go with fedora (less steps) and use the latest version of graalvm. Hopefully that should work. Will post on this thread once I have completed that.

Thanks for the inputs though and showing the right path.

@himanshumps
Copy link
Author

himanshumps commented Feb 28, 2018

After using fedora image, getting a different error

Initializing Openweather
java.lang.IllegalStateException: Multi threaded access requested by thread Thread[Ruby Thread id=24 from finalizer,5,main] but is not allowed for language(s) js.
	at com.oracle.truffle.api.vm.PolyglotContextImpl.throwDeniedThreadAccess(PolyglotContextImpl.java:517)
	at com.oracle.truffle.api.vm.PolyglotContextImpl.checkAllThreadAccesses(PolyglotContextImpl.java:435)
	at com.oracle.truffle.api.vm.PolyglotContextImpl.enterThreadChanged(PolyglotContextImpl.java:357)
	at com.oracle.truffle.api.vm.PolyglotContextImpl.enter(PolyglotContextImpl.java:315)
	at com.oracle.truffle.api.vm.PolyglotLanguageContext.enter(PolyglotLanguageContext.java:130)
	at com.oracle.truffle.api.vm.PolyglotLanguageContext.enterThread(PolyglotLanguageContext.java:179)
	at com.oracle.truffle.api.vm.PolyglotThread.run(PolyglotThread.java:51)

@chrisseaton
Copy link

Add --jvm.Dtruffleruby.single_threaded=true to run.sh. I'm not sure why that option isn't there. It won't be needed in 0.32 at least.

https://github.com/oracle/truffleruby/blob/vm-enterprise-0.31/doc/user/interop.md#threading-and-interop

@himanshumps
Copy link
Author

Will try and post back in case of issues

It takes around 30-45 minutes for one round of testing

@himanshumps
Copy link
Author

At least it is not giving any error .. But it is still not fetching the real temperature .. Looking at the code to see if I missed something

@himanshumps
Copy link
Author

Is there any flag to see the debug logs of ruby operation ?

I am not a ruby person so asking such silly questions.

@himanshumps
Copy link
Author

Working now. The tempInCity method was overridden in weatherServer.js

@chrisseaton
Copy link

I think it's got some logic to make it work offline or something.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants