GraalVM是一个非常热门的OSS。它已成为各个地方的热门话题。
通过单个运行时即可实现Oracle,Java,JavaScript,Ruby,Python等多语言支持的" GraalVM"作为开源发布。 Twitter在生产环境中采用
http://www.publickey1.jp/blog/18/javajavascriptrubypythongraalvmtwitter.html
易于介绍,因此我将其保留。彡(?)(?)
下载并安装GraalVM
在下面的链接(入门)?下载?社区版(CE)
下载" graalvm-ce-1.0.0-rc1-linux-amd64.tar.gz"
GraalVM入门
https://www.graalvm.org/docs/getting-started/
社区版(CE)
https://www.graalvm.org/downloads/
提取到VirtualBox来宾OS的适当目录(本文使用Linux,OEL6)。
这次,它在" / home / oracle / work"下展开。超级容易。彡(?)(?)
1 | tar xvzf graalvm-ce-1.0.0-rc1-linux-amd64.tar.gz |
安装Graal Python组件
将PATH放在GraalVM的bin目录中。也可以在GraalVM部署目录中设置JAVA_HOME(可选)。
1 2 | export PATH=/home/oracle/work/graalvm-1.0.0-rc1/bin:$PATH export JAVA_HOME=/home/oracle/work/graalvm-1.0.0-rc1 |
根据手册
使用gu命令(Graal更新程序)安装python组件
1 2 3 4 5 6 | gu -c install org.graalvm.python Downloading: Component catalog Processing component archive: Component org.graalvm.python Downloading: Component org.graalvm.python Installing new component: Graal.python (org.graalvm.python, version 1.0.0-rc1) |
运行Graal Python
首先,从命令行参考以下手册。
GraalVM --Python 3
https://www.graalvm.org/docs/reference-manual/languages/python/#python-3
使用
graalpython命令启动命令行。
打印语句的第一个是慢彡(?)(?)
,可能是因为VM正在运行。
1 2 3 4 5 6 7 8 | graalpython Please note: This Python implementation is in the very early stages, and can run little more than basic benchmarks at this point. >>> print ("1+2=", 1 + 2) 1+2= 3 >>> print ("1+2=", 1 + 2) 1+2= 3 : |
接下来,尝试运行以下python脚本。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | cat py3test.py # -*- coding: utf-8 -*- print("Hello World!") for i in range(0,6): print(i,"Hello World!") for i in range(0,6): if i%2==0: print(i," is even number.") else: print(i," is odd number.") |
脚本执行命令在下面,该命令...有效!彡(?)(?)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | graalpython --jvm --polyglot py3test.py Please note: This Python implementation is in the very early stages, and can run little more than basic benchmarks at this point. Hello World! 0 Hello World! 1 Hello World! 2 Hello World! 3 Hello World! 4 Hello World! 5 Hello World! 0 is even number. 1 is odd number. 2 is even number. 3 is odd number. 4 is even number. 5 is odd number. |
嗯,这个很棒。其他语言似乎可行,多语言是一项功能
似乎即使语言是混合的,它们也会同时工作。我必须尝试一下。 .. ..彡(?)(?)
Java模块的本机映像(* 4/25附言)
尽管GraalVM与python执行没有直接关系,但它被称为本机映像
有一个称为加速的功能,因此我尝试了一下,因此请记下。
首先,在Wai环境中,执行native-image命令,
我需要安装gcc和zlib-devel彡(?)(?)
1 2 | yum install gcc yum install zlib-devel |
编译以下java并转换为Native Image彡(?)(?)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | cat HelloGraalJava.java import org.graalvm.polyglot.*; class HelloGraalJava { public static void main(String[] args) { System.out.println("Hello, Graal Java!"); } } javac HelloGraalJava.java native-image HelloGraalJava Build on Server(pid: 3847, port: 26682) classlist: 909.56 ms (cap): 3,249.39 ms setup: 5,206.04 ms (typeflow): 15,378.97 ms (objects): 6,795.22 ms (features): 152.68 ms analysis: 22,692.12 ms universe: 1,248.48 ms (parse): 6,206.26 ms (inline): 3,647.32 ms (compile): 27,832.51 ms compile: 39,458.58 ms image: 3,222.35 ms write: 646.89 ms [total]: 73,892.84 ms |
ALL生成了一个名为" hellograal java"的小写二进制文件。
我试图用time命令执行它。我看到彡(?)(?)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | #通常のjava実行 time java HelloGraalJava Hello, Graal Java! real 0m0.187s user 0m0.140s sys 0m0.043s #Native Image実行 time ./hellograaljava Hello, Graal Java! real 0m0.017s user 0m0.003s sys 0m0.011s |
native-image命令也具有与python相关的选项,但
我不知道该怎么用。将来需要验证(?)(?)
1 2 3 4 5 | native-image --help : Available macro-options are: --language:python : |