├── .gitignore ├── README.md ├── images ├── busybox-func.png ├── color-server.png ├── createdialog.jpg ├── dashboard.jpg ├── docker-size.png ├── events.jpg ├── fizzbuzz-js.png ├── fizzbuzz-py.png ├── fizzbuzz-r.png ├── fizzbuzz-rb.png ├── fn-start.png ├── logdestination.jpg ├── logs.jpg ├── micronaut-memory.png ├── micronaut-startup.png ├── micronaut.png ├── native-build.png ├── papertrail-dashboard.png ├── papertrail-logs.png ├── polyglot.png ├── settings.jpg ├── userinput.png ├── visualvm-java.png ├── visualvm-rb.png ├── vnc-login.jpg └── warning.svg └── key.txt /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | .*.sw* 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Table of Contents: 2 | 3 | * [Exercise 0: Getting Started with GraalVM](#exercise-0-getting-started-with-graalvm) 4 | * [Exercise 1: Running Scala applications on GraalVM](#exercise-1-running-scala-applications-on-graalvm) 5 | * [Exercise 2: Building Native Platform binaries from Scala Applications with GraalVM](#exercise-2-building-native-platform-binaries-from-scala-applications-with-graalvm) 6 | * [Exercise 3: Running Scala and R in a Polyglot on GraalVM](#exercise-3-running-scala-and-r-in-a-polyglot-on-graalvm) 7 | * [Appendix](#appendix) 8 | 9 | # Exercise 0: Getting started with GraalVM 10 | 11 | > As you make your way through this lab, look out for this icon. 12 | 13 | ![user input](images/userinput.png) Whenever you see it, it's time for you to 14 | perform an action. 15 | 16 | Hello and welcome to the GraalVM Workshop. 17 | GraalVM offers a high-performance runtime for JVM languages with support for others 18 | like JavaScript, Python, Ruby, R. In this workshop, you'll learn how Scala developers 19 | can benefit from GraalVM. In this workshop we're going to introduce some of the GraalVM 20 | abilities and how you can benefit from using GraalVM for your Scala workloads. 21 | 22 | This workshop assumes you have access to a Linux environment or MacOS 23 | 24 | ## 0.5. Getting started with GraalVM on premise 25 | 26 | a. Navigate to Oracle Technology Network Downloads page and accept the license agreement: 27 | 28 | ![user input](images/userinput.png) 29 | https://www.oracle.com/technetwork/graalvm/downloads/index.html 30 | 31 | b. Select and download Oracle GraalVM Enterprise Edition based on JDK8 for your operating system (19.3.0). 32 | On Windows it is currently recommended for this workshop to use WLS (Linux subsystem) or Docker. 33 | Windows builds are experimental and while JVM and the JIT compiler would most probably work fine, 34 | you can find difficulties with the native image commands. 35 | 36 | c. Extract the archive to your file system. To extract the file to the current directory from the console, type 37 | 38 | ![user input](images/userinput.png) 39 | >```sh 40 | >tar -xvf archive.tar.gz # on Windows – double click to unzip 41 | >``` 42 | 43 | d. There can be multiple JDKs installed on the machine and the next step is to configure the runtime environment. 44 | Note, Contents/Home is a macOS construct, on Windows/Linux the commands would be using: /bin 45 | 46 | Add the GraalVM bin folder to the PATH environment variable: 47 | 48 | ![user input](images/userinput.png) 49 | >```sh 50 | >export PATH=/Contents/Home/bin:$PATH. 51 | >``` 52 | 53 | Verify whether you are using GraalVM with the echo command: 54 | 55 | ![user input](images/userinput.png) 56 | >```sh 57 | >echo $PATH. 58 | >``` 59 | 60 | Set the JAVA_HOME environment variable to resolve to the GraalVM installation directory: 61 | 62 | ![user input](images/userinput.png) 63 | >```sh 64 | >export JAVA_HOME=/Contents/Home 65 | >``` 66 | 67 | e. On Windows skip this step. Download the native image component for your operating system from OTN, 68 | for example for Linux use native-image-installable-svm-svmee-java8-linux-amd64-19.3.0.jar 69 | 70 | f. On Windows skip this step. Install native-image component into GraalVM 19.3. 71 | 72 | ![user input](images/userinput.png) 73 | >```sh 74 | >gu install -L ../native-image-installable-svm-svmee-java8-linux-amd64-19.3.0.jar 75 | >``` 76 | 77 | ## 0.7. Setting up GraalVM and Installing Scala 78 | 79 | a. Check the that the `java` command is now available and its version: 80 | 81 | ![user input](images/userinput.png) 82 | >```sh 83 | >java -version 84 | >``` 85 | 86 | Should Output: 87 | 88 | >```sh 89 | >java version "1.8.0_231" 90 | >Java(TM) SE Runtime Environment (build 1.8.0_231-b11) 91 | >Java HotSpot(TM) 64-Bit GraalVM EE 19.3.0 (build 25.231-b11-jvmci-19.3-b05, mixed mode) 92 | >``` 93 | 94 | b. Change the working directory for convenience 95 | 96 | ![user input](images/userinput.png) 97 | >```sh 98 | >cd .. 99 | >mkdir workshop 100 | >cd workshop 101 | >``` 102 | 103 | c. Install SDKMan for simpler sbt/maven installation:https://sdkman.io/install 104 | 105 | ![user input](images/userinput.png) 106 | >```sh 107 | >curl -s "https://get.sdkman.io" | bash 108 | >source "$HOME/.sdkman/bin/sdkman-init.sh" 109 | >``` 110 | 111 | d. Install sbt: 112 | 113 | ![user input](images/userinput.png) 114 | >```sh 115 | >sdk install sbt 116 | >``` 117 | 118 | e. Check that sbt installed correctly: 119 | 120 | ![user input](images/userinput.png) 121 | >```sh 122 | >sbt -version 123 | >``` 124 | 125 | Should Output: 126 | 127 | >```sh 128 | >sbt version in this project: 1.3.3 129 | >sbt script version: 1.3.3 130 | >``` 131 | 132 | f. Install Scala: 133 | 134 | ![user input](images/userinput.png) 135 | >```sh 136 | >sdk install scala 137 | >``` 138 | 139 | g. Check that Scala installed correctly: 140 | 141 | ![user input](images/userinput.png) 142 | >```sh 143 | >scala -version 144 | >``` 145 | 146 | Should Output: 147 | 148 | >```sh 149 | >Scala code runner version 2.13.1 -- Copyright 2002-2019, LAMP/EPFL and Lightbend, Inc. 150 | >``` 151 | 152 | h. Install a similar version of OpenJDK for comparisons: 153 | 154 | ![user input](images/userinput.png) 155 | >```sh 156 | >sdk install java 8.0.232.hs-adpt 157 | >``` 158 | 159 | i. In a different terminal to the same machine: use that Java version. For enabling that run the following commands: 160 | 161 | ![user input](images/userinput.png) 162 | >```sh 163 | >sdk use java 8.0.232.hs-adpt 164 | >export PATH=$JAVA_HOME/bin:$PATH 165 | >``` 166 | 167 | j. Check this Java version now active: 168 | 169 | ![user input](images/userinput.png) 170 | >```sh 171 | >java -version 172 | >``` 173 | 174 | Should Output: 175 | 176 | >```sh 177 | >java version "1.8.0_231" 178 | >Java(TM) SE Runtime Environment (build 1.8.0_231-b11) 179 | >Java HotSpot(TM) 64-Bit GraalVM EE 19.3.0 (build 25.231-b11-jvmci-19.3-b05, mixed mode) 180 | >``` 181 | 182 | k. Look at the `bin` directory of GraalVM, you can see the common JDK commands there, javac, javap, java, etc. 183 | It also includes GraalVM specific things, for example `node` for running node.js applications: 184 | 185 | ![user input](images/userinput.png) 186 | >```sh 187 | >ls $JAVA_HOME/bin 188 | >``` 189 | 190 | l. Extract the archive to your file system. To extract the file to the current directory from the console, type 191 | 192 | ![user input](images/userinput.png) 193 | >```sh 194 | >tar -xvf archive.tar.gz # on Windows – double click to unzip 195 | >``` 196 | 197 | # Exercise 1: Running Scala Applications on GraalVM 198 | 199 | GraalVM is a JDK distribution and you can use it as such, run you Scala workloads on GraalVM. 200 | GraalVM comes with a different top tier optimizing JIT compiler, so your long running processes 201 | can be optimized better than what other OpenJDK distributions can offer. 202 | 203 | GraalVM operates on the JVM bytecode as in the program is the compiled classes and jar files, 204 | so you don’t need to recompile your applications to get the performance benefits of using GraalVM. 205 | 206 | In this section we’ll run a sample Scala application and apply some load to it to measure the 207 | performance. Please note that this is sample application and while it might be representative 208 | of the real world results you should always be careful when extrapolating benchmark data. 209 | 210 | The GraalVM team runs a lot of benchmarks, for example you can take a look at Renaissance.dev. 211 | Renaissance is a modern, open, and diversified benchmark suite for the JVM, aimed at testing 212 | JIT compilers, garbage collectors, profilers, analyzers and other tools. 213 | 214 | Below is the sample result for Renaissance. You can see some Scala related workloads there: 215 | akka, dotty, finagle, scala-kmeans. 216 | 217 | https://github.com/renaissance-benchmarks/measurements/raw/master/stripe.png 218 | 219 | In this section we’ll run a simpler experiment, we’ll use a hello world play framework application 220 | for our measurements. 221 | 222 | a. Create a sample app 223 | 224 | ![user input](images/userinput.png) 225 | >```sh 226 | >go to https://developer.lightbend.com/start/?group=play&project=play-samples-play-scala-hello-world-tutorial 227 | >click generate project 228 | >``` 229 | 230 | b. Unzip the archive containing the sample project 231 | 232 | ![user input](images/userinput.png) 233 | >```sh 234 | >cd workshop 235 | >unzip play-samples-play-scala-hello-world-tutorial.zip 236 | >cd play-samples-play-scala-hello-world-tutorial 237 | >sbt run 238 | >``` 239 | 240 | c. Create a sample app 241 | 242 | ![user input](images/userinput.png) 243 | >```sh 244 | >go to https://developer.lightbend.com/start/?group=play&project=play-samples-play-scala-hello-world-tutorial 245 | >click generate project 246 | >``` 247 | 248 | d. In another tab in the terminal if running locally). Verify you can access the application: 249 | 250 | ![user input](images/userinput.png) 251 | >```sh 252 | >wget localhost:9000 253 | >``` 254 | 255 | e. Install hey, one of the load testing tools: 256 | 257 | ![user input](images/userinput.png) 258 | >```sh 259 | >wget -O hey https://storage.googleapis.com/hey-release/hey_linux_amd64 260 | >chmod a+x hey 261 | >``` 262 | 263 | If you use Mac, please use this link or homebrew to install. 264 | 265 | >```sh 266 | >wget -O hey https://storage.googleapis.com/hey-release/hey_darwin_amd64 267 | >chmod a+x hey 268 | >``` 269 | 270 | f. Run hey on the application. Notice the results, average req/s for example. 271 | 272 | ![user input](images/userinput.png) 273 | >```sh 274 | >./hey -z 300s -disable-keepalive http://127.0.0.1:9000/ 275 | >``` 276 | 277 | g. You will see a result similar to the below. Notice the Requests/sec value. 278 | 279 | >```sh 280 | >Summary: 281 | > Total: 60.0773 secs 282 | > Slowest: 0.2389 secs 283 | > Fastest: 0.0088 secs 284 | > Average: 0.0359 secs 285 | > Requests/sec: 1170.0767 286 | > Total data: 341573483 bytes 287 | > Size/request: 5221 bytes 288 | >``` 289 | >```sh 290 | >Response time histogram: 291 | >0.009 [1] | 292 | >0.032 [21608] |■■■■■■■■■■■■■■■■■■■■■ 293 | >0.055 [40900] |■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 294 | >0.078 [2020] |■■ 295 | >0.101 [448] | 296 | >0.124 [225] | 297 | >0.147 [106] | 298 | >0.170 [48] | 299 | >0.193 [36] | 300 | >0.216 [26] | 301 | >0.239 [5] | 302 | >``` 303 | >```sh 304 | >Latency distribution: 305 | >10% in 0.0226 secs 306 | >25% in 0.0295 secs 307 | >50% in 0.0350 secs 308 | >75% in 0.0393 secs 309 | >90% in 0.0458 secs 310 | >95% in 0.0531 secs 311 | >99% in 0.0897 secs 312 | >``` 313 | >```sh 314 | >Details (average, fastest, slowest): 315 | >DNS+dialup: 0.0053 secs, 0.0088 secs, 0.2389 secs 316 | >DNS-lookup: 0.0000 secs, 0.0000 secs, 0.0000 secs 317 | >req write: 0.0002 secs, 0.0000 secs, 0.0588 secs 318 | >resp wait: 0.0299 secs, 0.0010 secs, 0.2257 secs 319 | >resp read: 0.0004 secs, 0.0000 secs, 0.0628 secs 320 | >``` 321 | >```sh 322 | >Status code distribution: 323 | >[200] 65423 responses 324 | >``` 325 | 326 | h. Stop the sbt run in the original terminal: 327 | 328 | ![user input](images/userinput.png) 329 | >```sh 330 | >Ctrl + d 331 | >``` 332 | 333 | i. Compare to the performance of another JDK. 334 | 335 | ![user input](images/userinput.png) 336 | >```sh 337 | >Open the terminal where you had OpenJDK installed and configured (see excercise 0.7 h)) 338 | >``` 339 | 340 | j. Run the app with OpenJDK: 341 | 342 | ![user input](images/userinput.png) 343 | >```sh 344 | >sbt run 345 | >``` 346 | 347 | k. In the terminal where you ran `hey` run the load tests and compare the results to the previous run: 348 | 349 | ![user input](images/userinput.png) 350 | >```sh 351 | >./hey -z 300s -disable-keepalive http://127.0.0.1:9000/ 352 | >``` 353 | 354 | ## 1.1. Performance of scalac on Scala projects, on the example of Akka 355 | 356 | a. Clone a sample reasonably large scala project, for example: https://github.com/akka/akka.git 357 | 358 | ![user input](images/userinput.png) 359 | >```sh 360 | >git clone https://github.com/akka/akka.git 361 | >``` 362 | 363 | b. Navigate to akka directory. 364 | 365 | ![user input](images/userinput.png) 366 | >```sh 367 | >cd akka 368 | >``` 369 | 370 | c. Enter `sbt`, run the `clean compile` cycle twice, notice the time it takes for 1 cycle. 371 | `akka >` is the sbt REPL prefix, you don’t have to type it in. 372 | 373 | ![user input](images/userinput.png) 374 | >```sh 375 | >sbt 376 | >akka > clean 377 | >akka > compile 378 | >akka > clean 379 | >akka > compile 380 | >``` 381 | 382 | d. The very first build needs to download dependencies and will be much slower, 383 | please disregard that result, because it’s not representative of the normal 384 | development setup, where you have the dependencies downloaded and cached by sbt. 385 | The second clean compile cycle is representative of the results. 386 | 387 | e. Compare to the results with the performance of OpenJDK. Use the terminal where you 388 | had OpenJDK installed and configured. 389 | 390 | ![user input](images/userinput.png) 391 | >```sh 392 | >sbt 393 | >``` 394 | 395 | f. Build the project repeatedly, notice times: 396 | 397 | ![user input](images/userinput.png) 398 | >```sh 399 | >>clean compile 400 | >>clean compile 401 | >``` 402 | 403 | g. Build times are often cited as an important problem in the Scala community and 404 | speeding up the compilation cycle by using a better performing runtime. 405 | 406 | # Exercise 2: Building Native Platform binaries from Scala Applications with GraalVM 407 | 408 | GraalVM can compile JVM bytecode to native platform binaries (or shared libraries) ahead of time. 409 | The result is then an executable file (or a library) which doesn’t require the JVM to run. 410 | It also doesn’t need to initialize a lot of services and JVM components at startup, because 411 | it has precompiled many things already. 412 | 413 | In this section you’ll learn how to use GraalVM native-image utility to create GraalVM native images 414 | – the native binary. 415 | 416 | The native image capability of GraalVM is available as Early Adopter technology. We have installed it 417 | in the first part of this workshop. 418 | 419 | a. Let’s create a small Scala application to test the native images. Use the following command to initialize the project: 420 | 421 | ![user input](images/userinput.png) 422 | >```sh 423 | >mkdir sbt-example 424 | >cd sbt-example 425 | >touch build.sbt 426 | >mkdir -p src/main/scala/example 427 | >``` 428 | 429 | b. Then in the example directory create the application file `Hello.scala`: 430 | 431 | ![user input](images/userinput.png) 432 | >```sh 433 | >package example 434 | >object Hello extends App { 435 | >println("Hello World!") 436 | >} 437 | >``` 438 | 439 | c. You can use GraalVM native images through various Maven/Gradle/sbt plugins, but in its purest form 440 | it’s a command line utility that takes your application class files and jar files as the input. 441 | Perhaps the simplest way is to build a “fat” jar which contains all the classes which will used in the app. 442 | Add the assembly plugin to the build: 443 | 444 | ![user input](images/userinput.png) 445 | >```sh 446 | >mkdir project 447 | >echo 'addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.10")' > project/plugins.sbt 448 | >``` 449 | 450 | d. Run the build to get the fat jar: 451 | 452 | ![user input](images/userinput.png) 453 | >```sh 454 | >sbt assembly 455 | >``` 456 | 457 | e. Run the native-image utility on the application archive to build the native image: 458 | 459 | ![user input](images/userinput.png) 460 | >```sh 461 | >native-image -cp target/scala-2.12/sbt-example-assembly-0.1.0-SNAPSHOT.jar -H:Class=example.Hello 462 | >``` 463 | 464 | f. Check how much time the application takes when run normally: 465 | 466 | ![user input](images/userinput.png) 467 | >```sh 468 | >/usr/bin/time -v java -jar target/scala-2.12/sbt-example-assembly-0.1.0-SNAPSHOT.jar 469 | >``` 470 | 471 | g. You will see a result similar to the below. 472 | 473 | >```sh 474 | >Hello World! 475 | >Command being timed: "java -jar target/scala-2.12/sbt-example-assembly-0.1.0-SNAPSHOT.jar" 476 | >User time (seconds): 0.54 477 | >System time (seconds): 0.05 478 | >Percent of CPU this job got: 138% 479 | >Elapsed (wall clock) time (h:mm:ss or m:ss): 0:00.42 480 | >Average shared text size (kbytes): 0 481 | >Average unshared data size (kbytes): 0 482 | >Average stack size (kbytes): 0 483 | >Average total size (kbytes): 0 484 | >Maximum resident set size (kbytes): 64640 <- 64M 485 | >Average resident set size (kbytes): 0 486 | >Major (requiring I/O) page faults: 0 487 | >Minor (reclaiming a frame) page faults: 8065 488 | >Voluntary context switches: 1062 489 | >Involuntary context switches: 10 490 | >Swaps: 0 491 | >File system inputs: 0 492 | >File system outputs: 64 493 | >Socket messages sent: 0 494 | >Socket messages received: 0 495 | >Signals delivered: 0 496 | >Page size (bytes): 4096 497 | >Exit status: 0 498 | >``` 499 | 500 | h. Compare with the time it takes to start the native image: 501 | 502 | ![user input](images/userinput.png) 503 | >```sh 504 | >/usr/bin/time -v ./example.hello 505 | >``` 506 | 507 | i. You will see a result similar to the below. 508 | 509 | >```sh 510 | >Hello World! 511 | >Command being timed: "./example.hello" 512 | >User time (seconds): 0.00 513 | >System time (seconds): 0.00 514 | >Percent of CPU this job got: 100% 515 | >Elapsed (wall clock) time (h:mm:ss or m:ss): 0:00.00 516 | >Average shared text size (kbytes): 0 517 | >Average unshared data size (kbytes): 0 518 | >Average stack size (kbytes): 0 519 | >Average total size (kbytes): 0 520 | >Maximum resident set size (kbytes): 4932 <- 4M 521 | >Average resident set size (kbytes): 0 522 | >Major (requiring I/O) page faults: 0 523 | >Minor (reclaiming a frame) page faults: 169 524 | >Voluntary context switches: 1 525 | >Involuntary context switches: 1 526 | >Swaps: 0 527 | >File system inputs: 0 528 | >File system outputs: 0 529 | >Socket messages sent: 0 530 | >Socket messages received: 0 531 | >Signals delivered: 0 532 | >Page size (bytes): 4096 533 | >Exit status: 0 534 | >``` 535 | 536 | j. Go back to the workshop dir: 537 | 538 | ![user input](images/userinput.png) 539 | >```sh 540 | >cd.. 541 | >``` 542 | 543 | k. GraalVM native images have certain runtime properties – they start fast and consume less memory 544 | because they do not include the JIT compilation facilities for the bytecode. They operate under 545 | the closed world assumption – all the bytecodes that are going to be executed need to be analyzed 546 | and compiled at the generation step. This mean that certain dynamic features of the language need 547 | to be configured, for example, Java reflection API usage. Please consult documentation or your 548 | workshop leader for additional information: https://github.com/oracle/graal/tree/master/substratevm 549 | 550 | However that doesn’t mean that useful programs can’t be compiled ahead of time. In the following 551 | example we’ll build the native image of the `scalac` so it doesn’t spend time starting a jvm every 552 | time we call it. 553 | 554 | ## 2.1. Native image of Scalac 555 | 556 | For this particular exercise you need to install Scala 2.12.6. Scala 2.13 would work in a similar fashion, 557 | but currently this issue is blocking it: https://github.com/oracle/graal/issues/877 558 | 559 | a. So please install Scala 2.12.6 (the version that is known to work). 560 | 561 | ![user input](images/userinput.png) 562 | >```sh 563 | >sdk install scala 2.12.6 564 | >``` 565 | 566 | b. It will install scala 2.12.6. If you want to switch between Scala versions, use: 567 | 568 | ![user input](images/userinput.png) 569 | >```sh 570 | >sdk use scala 2.12.6 # or sdk use scala 2.13.1 571 | >``` 572 | 573 | c. Clone the repository with the GraalVM demos: 574 | 575 | ![user input](images/userinput.png) 576 | >```sh 577 | >git clone https://github.com/graalvm/graalvm-demos.git 578 | >``` 579 | 580 | d. Navigate to the scalac-native demo: 581 | 582 | ![user input](images/userinput.png) 583 | >```sh 584 | >cd graalvm-demos/scala-days-2018/scalac-native/ 585 | >``` 586 | 587 | e. Make sure that environment variables SCALA_HOME and GRAALVM_HOME point to Scala 2.12.6 and GraalVM. 588 | Then build the sbt project scalac-substitutions: 589 | 590 | ![user input](images/userinput.png) 591 | >```sh 592 | >export SCALA_HOME=/.sdkman/candidates/scala/2.12.6/ 593 | >export GRAALVM_HOME=/Contents/Home/ 594 | >cd scalac-substitutions 595 | >sbt package 596 | >cd ../ 597 | >``` 598 | 599 | f. To build the native image of the Scala compiler run: 600 | 601 | ![user input](images/userinput.png) 602 | >```sh 603 | >./scalac-image.sh 604 | >``` 605 | 606 | g. The above command builds the native image like in the previous section, but of scalac which is a Scala 607 | program itself. This allows to compile Scala apps without needing to start and warmup the JVM which for 608 | short invocations of scalac can by much faster than otherwise. 609 | 610 | h. Let's see how we compare to the JVM on the first run (scalac-native is a shell script that sets environment 611 | variables and calls native image of scalac): 612 | 613 | ![user input](images/userinput.png) 614 | >```sh 615 | >$ time $SCALA_HOME/bin/scalac HelloWorld.scala 616 | >real 0m2.315s 617 | >user 0m5.868s 618 | >sys 0m0.248s 619 | >``` 620 | >```sh 621 | >time ./scalac-native HelloWorld.scala 622 | >real 0m0.177s 623 | >user 0m0.129s 624 | >sys 0m0.034s 625 | >``` 626 | 627 | i. The time difference is clearly visible and you can expect similar effects. 628 | One project that uses GraalVM native images is Scalafmt, you can read more about it here: 629 | https://scalameta.org/scalafmt/docs/installation.html#native-image 630 | 631 | # Exercise 3: Running Scala and R in a Polyglot on GraalVM 632 | 633 | An example project that demonstrates how to execute R files from Scala using GraalVM 634 | >```sh 635 | >import org.graalvm.polyglot.{Context, Source} 636 | >object Main extends App { 637 | >// We need to initialise a GraalContext that will do the mediation between the JVM languages and R 638 | >val context: Context = Context.newBuilder("R").allowAllAccess(true).build() 639 | >// Next, we need to create a Source, which needs to know what language it features and where to find the code. 640 | >val source: Source = Source.newBuilder("R", Main.getClass.getResource("funHelloWorld.R")).build() 641 | >/* 642 | >* Then, we need to tell our compiler what kind of function this new Source represents. 643 | >* In this case it is a function that doesn't take an argument and returns a String. 644 | >* We use the graal context to convert the source into the function. 645 | >* Because R is very dynamically typed, the compiler cannot help you here: it trusts that you give it correct instructions! 646 | >* This also means that you may want to wrap any call to this function in a Try! 647 | >*/ 648 | >val rHelloWorld: () => String = context.eval(source).as(classOf[() => String]) 649 | >/* 650 | >* Finally, we can run the function. Because it doesn't take any arguments, we don't provide any. 651 | >* Let's also print the returned String, for good measure. 652 | >*/ 653 | >println(s"Also printing the return String: ${rHelloWorld()}") 654 | >} 655 | >``` 656 | 657 | https://medium.com/codestar-blog/in-search-of-the-holy-graalvm-putting-the-r-in-scala-or-java-or-b057494f77 658 | 659 | a. Install R 660 | 661 | ![user input](images/userinput.png) 662 | >```sh 663 | >cd /Users/adhillon/Desktop/InJapan/GraalVM-latest/graalvm-ee-java8-19.3.0/Contents/Home/bin 664 | >gu install R 665 | >cd /usr/local 666 | >sudo mkdir include 667 | >sudo chown -R $(whoami) $(brew --prefix)/include 668 | >brew link gcc@4.9 669 | >/Users/adhillon/Desktop/InJapan/GraalVM-latest/graalvm-ee-java8-19.3.0/Contents/Home/jre/languages/R/bin/configure_fastr 670 | >R 671 | >R version 3.6.1 (FastR) 672 | >``` 673 | 674 | b. Clone the following project into current directory: 675 | 676 | ![user input](images/userinput.png) 677 | >```sh 678 | >git clone https://github.com/NRBPerdijk/example-graalvm-r-scala.git 679 | >``` 680 | 681 | c. Run sbt 682 | 683 | ![user input](images/userinput.png) 684 | >```sh 685 | >sbt run 686 | >``` 687 | 688 | d. See Output 689 | >```sh 690 | >example-graalvm-r-scala-master adhillon$ sbt run 691 | >[info] Updating ... 692 | >[info] Done updating. 693 | >[info] Compiling 1 Scala source to /Users/adhillon/Desktop/InJapan/GraalVM-latest/example-graalvm-r-scala 694 | >[info] Done compiling. 695 | >[info] Packaging /Users/adhillon/Desktop/InJapan/GraalVM-latest/example-graalvm-r-scala-master/target/scala-2.12/example- graalvm-r-scala-master_2.12-0.1.0-SNAPSHOT.jar ... 696 | >[info] Done packaging. 697 | >[info] Running Main 698 | >[1] "Hello, World!" 699 | >Also printing the return String: Hello, World! executed in R 700 | >[success] 701 | >``` 702 | 703 | ### Conclusions 704 | 705 | You have seen GraalVM in action with Scala, Please provide us feedback! 706 | 707 | ## Appendix 708 | 709 | 710 | -------------------------------------------------------------------------------- /images/busybox-func.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amitpal-source/Scala-workshop/5fdee5bd4906325ac0263ac917cc0a0a61d63014/images/busybox-func.png -------------------------------------------------------------------------------- /images/color-server.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amitpal-source/Scala-workshop/5fdee5bd4906325ac0263ac917cc0a0a61d63014/images/color-server.png -------------------------------------------------------------------------------- /images/createdialog.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amitpal-source/Scala-workshop/5fdee5bd4906325ac0263ac917cc0a0a61d63014/images/createdialog.jpg -------------------------------------------------------------------------------- /images/dashboard.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amitpal-source/Scala-workshop/5fdee5bd4906325ac0263ac917cc0a0a61d63014/images/dashboard.jpg -------------------------------------------------------------------------------- /images/docker-size.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amitpal-source/Scala-workshop/5fdee5bd4906325ac0263ac917cc0a0a61d63014/images/docker-size.png -------------------------------------------------------------------------------- /images/events.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amitpal-source/Scala-workshop/5fdee5bd4906325ac0263ac917cc0a0a61d63014/images/events.jpg -------------------------------------------------------------------------------- /images/fizzbuzz-js.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amitpal-source/Scala-workshop/5fdee5bd4906325ac0263ac917cc0a0a61d63014/images/fizzbuzz-js.png -------------------------------------------------------------------------------- /images/fizzbuzz-py.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amitpal-source/Scala-workshop/5fdee5bd4906325ac0263ac917cc0a0a61d63014/images/fizzbuzz-py.png -------------------------------------------------------------------------------- /images/fizzbuzz-r.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amitpal-source/Scala-workshop/5fdee5bd4906325ac0263ac917cc0a0a61d63014/images/fizzbuzz-r.png -------------------------------------------------------------------------------- /images/fizzbuzz-rb.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amitpal-source/Scala-workshop/5fdee5bd4906325ac0263ac917cc0a0a61d63014/images/fizzbuzz-rb.png -------------------------------------------------------------------------------- /images/fn-start.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amitpal-source/Scala-workshop/5fdee5bd4906325ac0263ac917cc0a0a61d63014/images/fn-start.png -------------------------------------------------------------------------------- /images/logdestination.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amitpal-source/Scala-workshop/5fdee5bd4906325ac0263ac917cc0a0a61d63014/images/logdestination.jpg -------------------------------------------------------------------------------- /images/logs.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amitpal-source/Scala-workshop/5fdee5bd4906325ac0263ac917cc0a0a61d63014/images/logs.jpg -------------------------------------------------------------------------------- /images/micronaut-memory.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amitpal-source/Scala-workshop/5fdee5bd4906325ac0263ac917cc0a0a61d63014/images/micronaut-memory.png -------------------------------------------------------------------------------- /images/micronaut-startup.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amitpal-source/Scala-workshop/5fdee5bd4906325ac0263ac917cc0a0a61d63014/images/micronaut-startup.png -------------------------------------------------------------------------------- /images/micronaut.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amitpal-source/Scala-workshop/5fdee5bd4906325ac0263ac917cc0a0a61d63014/images/micronaut.png -------------------------------------------------------------------------------- /images/native-build.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amitpal-source/Scala-workshop/5fdee5bd4906325ac0263ac917cc0a0a61d63014/images/native-build.png -------------------------------------------------------------------------------- /images/papertrail-dashboard.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amitpal-source/Scala-workshop/5fdee5bd4906325ac0263ac917cc0a0a61d63014/images/papertrail-dashboard.png -------------------------------------------------------------------------------- /images/papertrail-logs.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amitpal-source/Scala-workshop/5fdee5bd4906325ac0263ac917cc0a0a61d63014/images/papertrail-logs.png -------------------------------------------------------------------------------- /images/polyglot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amitpal-source/Scala-workshop/5fdee5bd4906325ac0263ac917cc0a0a61d63014/images/polyglot.png -------------------------------------------------------------------------------- /images/settings.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amitpal-source/Scala-workshop/5fdee5bd4906325ac0263ac917cc0a0a61d63014/images/settings.jpg -------------------------------------------------------------------------------- /images/userinput.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amitpal-source/Scala-workshop/5fdee5bd4906325ac0263ac917cc0a0a61d63014/images/userinput.png -------------------------------------------------------------------------------- /images/visualvm-java.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amitpal-source/Scala-workshop/5fdee5bd4906325ac0263ac917cc0a0a61d63014/images/visualvm-java.png -------------------------------------------------------------------------------- /images/visualvm-rb.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amitpal-source/Scala-workshop/5fdee5bd4906325ac0263ac917cc0a0a61d63014/images/visualvm-rb.png -------------------------------------------------------------------------------- /images/vnc-login.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amitpal-source/Scala-workshop/5fdee5bd4906325ac0263ac917cc0a0a61d63014/images/vnc-login.jpg -------------------------------------------------------------------------------- /images/warning.svg: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /key.txt: -------------------------------------------------------------------------------- 1 | -----BEGIN RSA PRIVATE KEY----- 2 | MIIEowIBAAKCAQEAywdqSGo9GT71U2Hxg72sxY/Fpm2UlGnxFHeqsENwafujOFI1 3 | QXWqwyCI1ysdeOWtcASaGEh0Or72dGbBdAak2vsiwJzgQC924S/0eXsM5B0utte1 4 | hN91Bkuuv6OZgGUNjHr4zNem02YLyu4AH+G62bXJmpw7OJFjx2xK7ss/ncziLp3C 5 | c0nMOgPdxz2ZW26yZN9OgdfMle7bV92syaUgCm9SJVEDp47PEaDI6pR2dKzu14AT 6 | 4l8DkWqv/G77lLpwRpD0pFNrLRITRYadEu1HmEBYB4sm4T2roUiQGtdyyAZReJdF 7 | qr+l2laVgqaY35LEht6JyrBVEU5T8/IJSOHw0wIDAQABAoIBAB/3r+1tBOfHuPsD 8 | DfMPV3fX9mgJEv73W2U8nlyYkceuPnnsv8Pp0hRdOA6hFEfn6hIcN2MhbWOek9Gq 9 | KEWrkiOErWkkik6w6of0dAr4rAPy8FsLxeIBCT0Ph5lXGiFUR/jZl/kw72yTwcGX 10 | Dd/3O+Nxsyer98slYU+SJo5I5GBlDVZJzmbKJM95hwq9J/Jhk5oU5+Xb0YKG1fJF 11 | tnEXIi/Zmi1qMz2WlVxw5ijro2c9xHrIdD75Cl7p6FFOPR/dGw/0yfH1AKnnLoDu 12 | fh/dnUigZUqHY5oh5+xUiYT7qYME2gBbRq99eTwD95Ri7Mv+s/62isDnQHIqLzYC 13 | SBgHWGkCgYEA69WTfB0VlMrcl2p095EanGJHGFKrtPIXGQ99jdfgCHsbmgD9ClxY 14 | iYxwonJRojBdfS1FveZHinpIJkM6Io+ikZMtRwDCo2NaSBcPpgsWubkM6d81ozRR 15 | tVA3D3fRxxmw6xzO+gb6OzOmniu43oFx3ysZURPS6WlfkAoQRN4rayUCgYEA3GO6 16 | pZZFZN5DRV0NPE9QfTjwCN1ioyexJR4V04Ge55rxU+PQ99XYy0NKO+isgXvHM7qg 17 | xReF3N8o6HZVXHQOccoXyowZEEGY0ov+RQt3dYdWNslf5+oDQY4pGWUx0VLUl9Jc 18 | U868V+7szpH8QuQ05FS8ejKvPjiZz7FhZ6yxZpcCgYAkziw6Tn+zvQU4TFD84hR5 19 | G41k6mIJ105rhtNdc7dvG2dvXYAgQdE/hj992sGKwmmUw6ACxxGbNwJTlmJYSnpg 20 | pcuHLUMzJKpOXer/SvO9AHhXd5JzahLmbSJqs5R1sji+OLzEoJok6yaxwLkVYLZY 21 | 0e0dji54Zw2W+TsYxGOaUQKBgQC5SPcQY6fvx5US6cpI2/21aXsUWNumg6ZAqGx9 22 | J0qrOO6PMsbqtdTP/sCYYWM2cRPmf47OZJpcORmxZlsZoVDLhbY+yU4BBsUurheV 23 | gLBsFN38rYx985XNNXGEMjmR3GtzQJ3yr6pU20An40AMFMQK+tqCeb4vN3LI1D4p 24 | 5Vw3/QKBgE9omsh+VXJc6zPVziDop4QEXXAksRd2YeDYpUE9MBnGmZXnOb0TiVn6 25 | DlvkbMBfaPucKAfZwKIuhfmu7Sf4J6aqKLzaDrAIw7Dzh6i0GAWj+N7i7nb8Fpzv 26 | u2cEAy1Je+k77/+5CSCO1yBSX5Eohy9PBfxI2gmtQ3G5TgJ/pp/y 27 | -----END RSA PRIVATE KEY----- 28 | --------------------------------------------------------------------------------