SPECJVM2008使用方法

1.工具介绍

SPECjvm2008 (Java Virtual Machine Benchmark)是一个评估JRE运行性能的基准测试套件。包含几个现实生活中的应用和专注于核心java功能的基准的测量基准套件。该套件侧重于JRE执行一个单一的应用程序;它反映了硬件处理器和内存子系统的性能,与文件系统I/O和网络I/O关系不大。SPECjvm2008负载模仿各种常见用途的应用计算。这些特征反映了这一基准适用于测量基本 Java 性能上种类繁多的客户端和服务器系统。 套件包含21个基准测试,其中每个基准测试均包含一个2分钟的热身测试和4分钟的正式测试。由于测试过程中程序并不中断基准测试的执行,所以测试时间至少为126分钟,根据Java性能的不同,测试时间会有所不同。关于21个基准测试的具体内容将在文档最后进行介绍。

官网:http://www.spec.org/jvm2008/

2工具安装

2.1下载

下载SPECjvm2008测试套件:

#wget ftp://ftp.spec.org/dist/osg/java/SPECjvm2008_1_01_setup.jar
2.2安装
#java -jar SPECjvm2008_1_01_setup.jar -i console

选择默认的内容进行安装,直至完成。默认的安装路径会是/SPECjvm2008

2.3调试

在/etc/profile中加入环境变量

JAVA_HOME=/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0/
CLASSPATH=.:$JAVA_HOME/lib/tools.jar:/lib.dt.jar
PATH=$JAVA_HOME/bin:$PATH
export JAVA_HOME CLASSPATH PATH

保存后,执行 source /etc/profile即可。

安装目录下有一个脚本,linux对应的是run-specjvm.sh,windows对应的是 run-specjvm.cmd

执行如下命令,用以测试安装或环境是否ok

./run-specjvm.sh startup.helloworld -ikv

startup.helloworld 是测试helloworld程序的启动时间,选择这个测试用例是考虑到运行速度比较快。

-ikv的意思是跳过签名检查,那个过程有点慢。

2.4 配置

默认情况,我们只需要修改安装目录下 props/specjvm.properties 和 props/specjvm.reporter.properites 这两个配置文件就行了。

specjvm.properties主要负责对整个套件的运行进行调整。比如,指定需要运行的测试用例,测试迭代次数,每个用例跑完是否要GC等。

specjvm.reporter.properites主要用来丰富报表输出内容,一般是一些无法通过自动检测得到的环境信息。比如,主机的内存型号,cpu逻辑个数,主板提供商等。

官方对specjvm.properties的内容是遵循COC原则设计的。所以,我们只需要修改特定的参数就可以了。

下面是我测试时修改的一些参数。

specjvm.additional.properties.file=props/specjvm.reporter.properties      // 指定报表配置文件路径
specjvm.benchmark.analyzer.names=HeapMemoryFreeAnalyzer HeapMemoryTotalAnalyzer            // heap分析器
specjvm.home.dir=/home/admin/SPECjvm2008 // SPEC_HOME路径
specjvm.iteration.time=240s        // 迭代时长
specjvm.startup.jvm_options=-Xms1024m -Xmx1024m -XX:+UseConcMarkSweepGC         // JVM switches

specjvm.reporter.properties这个配置文件就不多做介绍了,你甚至可以不做任何修改。

3 工具使用说明

3.1 命令及参数说明

通常的命令执行格式

java [<jvm options>] -jar SPECjvm2008.jar [<SPECjvm2008 options>] [<benchmark name> ...]

可用参数查询:java -jar SPECjvm2008.jar --help

Arg Long arg    Value   Property name   Description

-h   --help         Show this help.
     --version          Print SPECjvm2008 version and exit.
-sv  --showversion          Print SPECjvm2008 version and continue.
     --base         Run the base compliant run of SPECjvm2008 (default, unless jvm args are specified).
     --peak         Run the peak compliant run of SPECjvm2008.
     --lagom            Run the Lagom benchmark suite, a version, of SPECjvm2008 that uses a fixed workload.
-pf  --propfile  string specjvm.propfile    Use this properties file.
-i   --iterations    int    specjvm.miniter, specjvm.maxniter   How many iterations to run. 'inf' means an infinite number.
-mi  --miniter   int    specjvm.miniter Minimum number of iterations.
-ma  --maxiter   int    specjvm.maxniter    Maximum number of iterations.
-it  --iterationtime     time   specjvm.iteration.time  How long one iteration should be. The time is specified as an integer, and assumed to be in seconds, or an integer with unit, for example 4m (4 minutes). Units available are ms, s, m and h. If the iteration time is too short, based on the warmup result, it will be adjusted to expect to finish at least 5 operations.
-fit     --forceIterationIime    time   specjvm.iteration.time, specjvm.iteration.time.forced   As iteration time, but the time will not be adjusted based on the warmup result.
-ja  --jvmArgs   string specjvm.startup.jvm_options JVM options used for startup subtests.
-jl  --jvmLauncher   path   specjvm.benchmark.startup.launcher  JVM launcher used for startup subtests.
-wt  --warmuptime    time   specjvm.benchmark.warmup.time   How long warmup time. The time format is the same as in iteration time.
-ops     --operations    int    specjvm.fixed.operations, specjvm.run.type  How many operations each iteration will consist of. It will then be a fixed workload and iteration time is ignored.
-bt  --benchmarkThreads  int    specjvm.benchmark.threads   How many benchmark threads to use.
-r   --reporter  raw file name      Invokes the reporter with given file(s). The benchmarks will not be run.
-v   --verbose      specjvm.print.verbose, specjvm.print.progress   Print verbose info (harness only).
-pja     --parseJvmArgs         Parse jvm arguments info from command line, including heap settings (uses JMXBean info). This is not done by default.
-coe     --continueOnError      specjvm.continue.on.error   Continue to run suite, even if one test fails.
-ict     --ignoreCheckTest      specjvm.run.initial.check   Do not run check benchmark.
-ikv     --ignoreKitValidation      specjvm.run.checksum.validation Do not run checksum validition of benchmark kit.
-crf     --createRawFile     boolean    specjvm.create.xml.report   Whether to generate a raw file.
-ctf     --createTextFile    boolean    specjvm.create.txt.report   Whether to generate text report. If raw is disabled, so is txt.
-chf     --createHtmlFile    boolean    specjvm.create.html.report  Whether to generate html report. If raw is disabled, so is html.
-xd  --xmlDir    path   specjvm.benchmark.xml.validation.input.dir  To set path to xml input files
    <benchmark(s)>      specjvm.benchmarks  Name of benchmark(s) to run. By default all submission benchmarks will be selected. 'all' means all sumission benchmarks will be run. See SPECjvm2008 workload names for all values.

3.2 基准测试用例介绍

SPECjvm2008的benchmarks测试用例列表如下:

(单位 ops/m 每分钟操作数)

Benchmark Name Description

startup.helloworld  测试helloworld程序从运行开始到结束所需的时间
startup.compiler.compiler   普通java编译所需要的时间
startup.compiler.sunflow    编译sunflow图像渲染引擎所需要的时间
startup.compress    测试压缩程序,单次压缩所需的时间
startup.crypto.aes  测试AES/DES加密算法,单次加解密所需的时间
输入数据长度为 100 bytes , 713KB
startup.crypto.rsa  测试RSA加密算法,单次加解密需要的时间
输入数据长度为 100 bytes, 16KB 
startup.crypto.signverify   测试单次使用MD5withRSA, SHA1withRSA, SHA1withDSA, SHA256withRSA来签名,识别所需要的时间。
输入数据长度为 1KB, 65KB, 1MB
startup.mpegaudio   单次mpeg音频解码所需的时间
startup.scimark.fft 单次快速傅立叶变换所需的时间
startup.scimark.lu  单次LU分解所需的时间
startup.scimark.monte_carlo 单次运行蒙特卡罗算法所需的时间
startup.scimark.sor 单次运行jacobi逐次超松弛迭代法所需的时间
startup.scimark.sparse  单次稀疏矩阵乘积所需的时间
startup.serial  单次通过socket传输java序列化对象到对端反序列化完成所需的时间(基于jboss serialization benchmark)
startup.sunflow 单次图片渲染处理所需的时间
startup.xml.transform   单次xml转换所需的时间,转换包括dom,sax,stream方式
startup.xml.validation  单次xml schema校验所需的时间
compiler.compiler   在规定时间内,多线程迭代测试普通java编译,得出 ops/m
compiler.sunflow    在规定时间内,多线程迭代测试sunflow图像渲染,得出 ops/m
compress    在规定时间内,多线程迭代测试压缩,得出 ops/m
crypto.aes  在规定时间内,多线程迭代测试AES/DES加解密算法,得出 ops/m
crypto.rsa  在规定时间内,多线程迭代测试RSA加解密算法,得出 ops/m
crypto.signverify   在规定时间内,多线程迭代测试使用MD5withRSA, SHA1withRSA, SHA1withDSA, SHA256withRSA来签名,识别,得出 ops/m
derby   在规定时间内,迭代测试数据库相关逻辑,包括数据库锁,BigDecimal计算等,最后得出 ops/m
mpegaudio   在规定时间内,多线程迭代mpeg音频解码,得出 ops/m
scimark.fft.large   在规定时间内,多线程迭代测试快速傅立叶变换,使用32M大数据集,最后得出 ops/m
scimark.lu.large    在规定时间内,多线程迭代测试LU分解,使用32M大数据集,最后得出 ops/m
scimark.sor.large   在规定时间内,多线程迭代测试jacobi逐次超松弛迭代法,使用32M大数据集,最后得出 ops/m
scimark.sparse.large    在规定时间内,多线程迭代测试稀疏矩阵乘积,使用32M大数据集,最后得出 ops/m
scimark.fft.small   在规定时间内,多线程迭代测试快速傅立叶变换,使用512K小数据集,最后得出 ops/m
scimark.lu.small    在规定时间内,多线程迭代测试LU分解,使用512KB小数据集,最后得出 ops/m
scimark.sor.small   在规定时间内,多线程迭代测试jacobi逐次超松弛迭代法,使用512KB小数据集,最后得出 ops/m
scimark.sparse.small    在规定时间内,多线程迭代测试稀疏矩阵乘积,使用512KB小数据集,最后得出 ops/m
scimark.monte_carlo 在规定时间内,多线程迭代测试蒙特卡罗算法,得出 ops/m
serial  在规定时间内,多线程迭代测试通过socket传输java序列化对象到对端反序列化(基于jboss serialization benchmark),得出 ops/m
sunflow 在规定时间内,利用sunflow多线程迭代测试图片渲染,得出 ops/m
xml.transform   在规定时间内,多线程迭代测试xml转换,得出ops/m
xml.validation  在规定时间内,多线程迭代测试xml schema验证,得出 ops/m

4执行基准测试

官方提供了三种基准测试方式,常用的有两种,一种是base,一种是peak,区别在于前者是不允许做任何vm参数调整。后者可以添加vm调优参数。 默认启动方式:

java -jar SPECjvm2008.jar

此测试将完整的测试21个用例。

可以选择特定的用例进行测试

如:java -jar SPECjvm2008.jar startup.helloworld

根据需要可以进行vm参数调整,调整后需要使用-peak参数。

如:java -Xms256M -Xmx1024M -jar SPECjvm2008.jar -peak -ikv

5结果查看

测试结果默认的输出路径是安装目录的results 目录下。内部根据你执行测试套件的顺序,又分了不同的子文件夹。进入某个子文件夹,查看html格式的结果就行了。

6参考的URL

用户手册

运行和报告规范

http://www.spec.org/jvm2008/docs/RunRules.html

已知问题

http://www.spec.org/jvm2008/docs/KnownIssues.html

7 总结

1)如果选了base,又修改了vm options怎么办?

套件在运行时,会给你警告。并且,在你的测试结果上会显示大大的一行Run is not compliant。另外,如果你想将测试结果提交官方,某些参数必须符合官方要求,否则同样是警告。

2)哪些参数有官方要求?

默认配置文件props/specjvm.properties 里,注释了Permitted for的就是。

3)如何指定配置文件路径?

-pf指定配置文件路径,默认使用的是安装目录下的 props/specjvm.properties,(日志里会打印出使用文件的路径)

by 李鹏