├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── settings.gradle ├── src └── main │ └── java │ └── org │ └── wjw │ └── vertx │ └── performance │ ├── WithoutClusterStarter.java │ ├── AbstractVertxStarter.java │ ├── WithClusterStarter.java │ ├── ConsumerVerticle.java │ └── ProducerVerticle.java ├── .gitignore ├── gradlew.bat ├── README.md └── gradlew /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wjw465150/vertx-cluster-performance/master/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.1-bin.zip 4 | networkTimeout=10000 5 | zipStoreBase=GRADLE_USER_HOME 6 | zipStorePath=wrapper/dists 7 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'vertx-cluster-performance' 2 | if (!JavaVersion.current().java8Compatible) { 3 | throw new IllegalStateException('''A Vert.x App: 4 | | This needs Java 8, 5 | | You are using something else, 6 | | Refresh. Try again.'''.stripMargin()) 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/org/wjw/vertx/performance/WithoutClusterStarter.java: -------------------------------------------------------------------------------- 1 | package org.wjw.vertx.performance; 2 | 3 | import io.vertx.core.Vertx; 4 | 5 | public class WithoutClusterStarter extends AbstractVertxStarter { 6 | 7 | public static void main(String... args) { 8 | System.out.println("Starting in non-clustered mode"); 9 | Vertx vertx = Vertx.vertx(); 10 | deployVerticles(vertx); 11 | } 12 | 13 | } -------------------------------------------------------------------------------- /src/main/java/org/wjw/vertx/performance/AbstractVertxStarter.java: -------------------------------------------------------------------------------- 1 | package org.wjw.vertx.performance; 2 | 3 | import io.vertx.core.DeploymentOptions; 4 | import io.vertx.core.Vertx; 5 | 6 | public class AbstractVertxStarter { 7 | 8 | static void deployVerticles(Vertx vertx) { 9 | vertx.deployVerticle( 10 | new ConsumerVerticle(), 11 | new DeploymentOptions().setWorker(true)); 12 | 13 | vertx.deployVerticle( 14 | new ProducerVerticle(), 15 | new DeploymentOptions().setWorker(true)); 16 | } 17 | 18 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .gradle 2 | /build/ 3 | /bin/ 4 | /classes/ 5 | /config-repo/ 6 | !gradle/wrapper/gradle-wrapper.jar 7 | 8 | ### STS ### 9 | .apt_generated 10 | .classpath 11 | .factorypath 12 | .project 13 | .settings 14 | .springBeans 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | nbproject/private/ 24 | build/ 25 | nbbuild/ 26 | dist/ 27 | nbdist/ 28 | .nb-gradle/ 29 | 30 | # logs 31 | /test/reports 32 | /logs 33 | *.log 34 | *.log.* 35 | 36 | # IDE support files 37 | /.classpath 38 | /.launch 39 | /.project 40 | /.settings 41 | /*.launch 42 | /*.tmproj 43 | /ivy* 44 | /eclipse -------------------------------------------------------------------------------- /src/main/java/org/wjw/vertx/performance/WithClusterStarter.java: -------------------------------------------------------------------------------- 1 | package org.wjw.vertx.performance; 2 | 3 | import java.io.IOException; 4 | 5 | import io.vertx.core.Vertx; 6 | import io.vertx.core.VertxOptions; 7 | import io.vertx.core.spi.cluster.ClusterManager; 8 | import io.vertx.spi.cluster.redis.RedisClusterManager; 9 | 10 | public class WithClusterStarter extends AbstractVertxStarter { 11 | 12 | public static void main(String... args) throws Exception { 13 | System.out.println("Starting in clustered mode"); 14 | ClusterManager mgr = new RedisClusterManager(); 15 | 16 | VertxOptions options = new VertxOptions().setClusterManager(mgr); 17 | Vertx.clusteredVertx(options, resultHandler -> { 18 | Vertx vertx = resultHandler.result(); 19 | deployVerticles(vertx); 20 | }); 21 | } 22 | } -------------------------------------------------------------------------------- /src/main/java/org/wjw/vertx/performance/ConsumerVerticle.java: -------------------------------------------------------------------------------- 1 | package org.wjw.vertx.performance; 2 | 3 | import io.vertx.core.AbstractVerticle; 4 | 5 | public class ConsumerVerticle extends AbstractVerticle { 6 | 7 | public static final String ADDRESS = "cluster-test"; 8 | boolean firstMessageReceived; 9 | 10 | @Override 11 | public void start() throws Exception { 12 | System.out.println("Starting " + this.getClass().getSimpleName()); 13 | long start = System.currentTimeMillis(); 14 | 15 | vertx.eventBus().consumer(ADDRESS).handler(message -> { 16 | if (!firstMessageReceived) { 17 | System.out.println("Received first message after " + (System.currentTimeMillis() - start) + " ms"); 18 | firstMessageReceived = true; 19 | } 20 | 21 | message.reply("OK"); 22 | }).completionHandler(result -> System.out.println("Consumer registered after " + (System.currentTimeMillis() - start) + " ms")); 23 | } 24 | 25 | } -------------------------------------------------------------------------------- /src/main/java/org/wjw/vertx/performance/ProducerVerticle.java: -------------------------------------------------------------------------------- 1 | package org.wjw.vertx.performance; 2 | 3 | import io.vertx.core.AbstractVerticle; 4 | import io.vertx.core.AsyncResult; 5 | import io.vertx.core.eventbus.Message; 6 | 7 | import java.util.stream.IntStream; 8 | 9 | public class ProducerVerticle extends AbstractVerticle { 10 | 11 | private static final int NUM_MESSAGES = 500_000; 12 | 13 | private long replyCount = 0; 14 | private long start; 15 | 16 | @Override 17 | public void start() throws Exception { 18 | System.out.println("Starting " + this.getClass().getSimpleName()); 19 | start = System.currentTimeMillis(); 20 | 21 | System.out.println("Starting to send messages."); 22 | IntStream.range(0, NUM_MESSAGES).forEach(i -> { 23 | if (i > 0 && i % 20000 == 0) { 24 | System.out.println(i + " eventbus messages sent in " + (System.currentTimeMillis() - start) + " ms."); 25 | } 26 | 27 | vertx.eventBus() 28 | .request( 29 | ConsumerVerticle.ADDRESS, 30 | "dummy message", 31 | this::onReply); 32 | }); 33 | System.out.println(NUM_MESSAGES + " eventbus messages sent in " + (System.currentTimeMillis() - start) + " ms."); 34 | 35 | } 36 | 37 | private void onReply(AsyncResult> reply) { 38 | if (reply.result() != null && "OK".equals(reply.result().body())) { 39 | replyCount++; 40 | 41 | // log progress for the impatient ;-) 42 | if (replyCount % 10000 == 0) { 43 | System.out.println("replyCount: " + replyCount + " after " + (System.currentTimeMillis() - start) + " ms"); 44 | } 45 | 46 | // stop when the number of received replies is equal to the number of sent messages 47 | if (replyCount == NUM_MESSAGES) { 48 | System.out.println("all replies received in " + (System.currentTimeMillis() - start) + " ms"); 49 | System.exit(0); 50 | } 51 | } 52 | } 53 | } -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%"=="" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%"=="" set DIRNAME=. 29 | @rem This is normally unused 30 | set APP_BASE_NAME=%~n0 31 | set APP_HOME=%DIRNAME% 32 | 33 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 34 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 35 | 36 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 37 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 38 | 39 | @rem Find java.exe 40 | if defined JAVA_HOME goto findJavaFromJavaHome 41 | 42 | set JAVA_EXE=java.exe 43 | %JAVA_EXE% -version >NUL 2>&1 44 | if %ERRORLEVEL% equ 0 goto execute 45 | 46 | echo. 47 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 48 | echo. 49 | echo Please set the JAVA_HOME variable in your environment to match the 50 | echo location of your Java installation. 51 | 52 | goto fail 53 | 54 | :findJavaFromJavaHome 55 | set JAVA_HOME=%JAVA_HOME:"=% 56 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 57 | 58 | if exist "%JAVA_EXE%" goto execute 59 | 60 | echo. 61 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 62 | echo. 63 | echo Please set the JAVA_HOME variable in your environment to match the 64 | echo location of your Java installation. 65 | 66 | goto fail 67 | 68 | :execute 69 | @rem Setup the command line 70 | 71 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 72 | 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if %ERRORLEVEL% equ 0 goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | set EXIT_CODE=%ERRORLEVEL% 85 | if %EXIT_CODE% equ 0 set EXIT_CODE=1 86 | if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% 87 | exit /b %EXIT_CODE% 88 | 89 | :mainEnd 90 | if "%OS%"=="Windows_NT" endlocal 91 | 92 | :omega 93 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # vertx-cluster-performance 2 | 3 | > 作者: 白石(https://github.com/wjw465150/vertx-cluster-performance) 4 | 5 | Reproducer for performance degradation when running Vert.x 4 in clustered mode. 6 | 7 | Setup: 8 | 9 | - **ConsumerVerticle** listens on the eventbus and replies to messages it receives. 10 | - **ProducerVerticle** sends 500k eventbus messages and logs the duration of replies. 11 | - **WithClusterStarter** starts Vert.x in clustered mode and deploys both verticles. 12 | - **WithoutClusterStarter** starts Vert.x in non clustered mode and deploys both verticles. 13 | 14 | The only difference between the two scenario's is Vert.x is started with or without cluster. 15 | Both verticles are deployed as worker verticles to rule out eventloop blocking issues. 16 | 17 | Timings (on my 2020 ThinkPad T41): 18 | ## without cluster 19 | first message received after `10ms`, done after `2420ms`. 20 | 21 | ``` 22 | Starting in non-clustered mode 23 | Starting ConsumerVerticle 24 | Starting ProducerVerticle 25 | Starting to send messages. 26 | Consumer registered after 7 ms 27 | Received first message after 10 ms 28 | 20000 eventbus messages sent in 106 ms. 29 | 40000 eventbus messages sent in 176 ms. 30 | 60000 eventbus messages sent in 216 ms. 31 | 80000 eventbus messages sent in 260 ms. 32 | 100000 eventbus messages sent in 310 ms. 33 | 120000 eventbus messages sent in 380 ms. 34 | 140000 eventbus messages sent in 402 ms. 35 | 160000 eventbus messages sent in 423 ms. 36 | 180000 eventbus messages sent in 446 ms. 37 | 200000 eventbus messages sent in 554 ms. 38 | 220000 eventbus messages sent in 573 ms. 39 | 240000 eventbus messages sent in 592 ms. 40 | 260000 eventbus messages sent in 612 ms. 41 | 280000 eventbus messages sent in 688 ms. 42 | 300000 eventbus messages sent in 708 ms. 43 | 320000 eventbus messages sent in 729 ms. 44 | 340000 eventbus messages sent in 749 ms. 45 | 360000 eventbus messages sent in 772 ms. 46 | 380000 eventbus messages sent in 799 ms. 47 | 400000 eventbus messages sent in 902 ms. 48 | 420000 eventbus messages sent in 926 ms. 49 | 440000 eventbus messages sent in 1919 ms. 50 | 460000 eventbus messages sent in 1938 ms. 51 | 480000 eventbus messages sent in 1958 ms. 52 | 500000 eventbus messages sent in 1980 ms. 53 | replyCount: 10000 after 2010 ms 54 | replyCount: 20000 after 2026 ms 55 | replyCount: 30000 after 2038 ms 56 | replyCount: 40000 after 2046 ms 57 | replyCount: 50000 after 2055 ms 58 | replyCount: 60000 after 2063 ms 59 | replyCount: 70000 after 2072 ms 60 | replyCount: 80000 after 2081 ms 61 | replyCount: 90000 after 2089 ms 62 | replyCount: 100000 after 2098 ms 63 | replyCount: 110000 after 2107 ms 64 | replyCount: 120000 after 2115 ms 65 | replyCount: 130000 after 2124 ms 66 | replyCount: 140000 after 2132 ms 67 | replyCount: 150000 after 2141 ms 68 | replyCount: 160000 after 2149 ms 69 | replyCount: 170000 after 2158 ms 70 | replyCount: 180000 after 2166 ms 71 | replyCount: 190000 after 2175 ms 72 | replyCount: 200000 after 2183 ms 73 | replyCount: 210000 after 2192 ms 74 | replyCount: 220000 after 2200 ms 75 | replyCount: 230000 after 2208 ms 76 | replyCount: 240000 after 2216 ms 77 | replyCount: 250000 after 2224 ms 78 | replyCount: 260000 after 2232 ms 79 | replyCount: 270000 after 2241 ms 80 | replyCount: 280000 after 2249 ms 81 | replyCount: 290000 after 2257 ms 82 | replyCount: 300000 after 2266 ms 83 | replyCount: 310000 after 2274 ms 84 | replyCount: 320000 after 2283 ms 85 | replyCount: 330000 after 2292 ms 86 | replyCount: 340000 after 2301 ms 87 | replyCount: 350000 after 2309 ms 88 | replyCount: 360000 after 2318 ms 89 | replyCount: 370000 after 2326 ms 90 | replyCount: 380000 after 2335 ms 91 | replyCount: 390000 after 2343 ms 92 | replyCount: 400000 after 2352 ms 93 | replyCount: 410000 after 2360 ms 94 | replyCount: 420000 after 2368 ms 95 | replyCount: 430000 after 2377 ms 96 | replyCount: 440000 after 2384 ms 97 | replyCount: 450000 after 2390 ms 98 | replyCount: 460000 after 2396 ms 99 | replyCount: 470000 after 2402 ms 100 | replyCount: 480000 after 2408 ms 101 | replyCount: 490000 after 2414 ms 102 | replyCount: 500000 after 2420 ms 103 | all replies received in 2420 ms 104 | ``` 105 | 106 | 107 | 108 | ## with cluster 109 | first message received after `51ms`, done after `4546ms`. 110 | 111 | ``` 112 | Starting in clustered mode 113 | 二月 12, 2023 10:27:21 上午 com.hazelcast.system 114 | 信息: [192.168.56.1]:5701 [dev] [4.2.6] Hazelcast 4.2.6 (20221125 - 622d299) starting at [192.168.56.1]:5701 115 | 二月 12, 2023 10:27:21 上午 com.hazelcast.spi.discovery.integration.DiscoveryService 116 | 信息: [192.168.56.1]:5701 [dev] [4.2.6] No discovery strategy is applicable for auto-detection 117 | 二月 12, 2023 10:27:22 上午 com.hazelcast.instance.impl.Node 118 | 信息: [192.168.56.1]:5701 [dev] [4.2.6] Using Multicast discovery 119 | 二月 12, 2023 10:27:22 上午 com.hazelcast.cp.CPSubsystem 120 | 警告: [192.168.56.1]:5701 [dev] [4.2.6] CP Subsystem is not enabled. CP data structures will operate in UNSAFE mode! Please note that UNSAFE mode will not provide strong consistency guarantees. 121 | 二月 12, 2023 10:27:22 上午 com.hazelcast.internal.diagnostics.Diagnostics 122 | 信息: [192.168.56.1]:5701 [dev] [4.2.6] Diagnostics disabled. To enable add -Dhazelcast.diagnostics.enabled=true to the JVM arguments. 123 | 二月 12, 2023 10:27:22 上午 com.hazelcast.core.LifecycleService 124 | 信息: [192.168.56.1]:5701 [dev] [4.2.6] [192.168.56.1]:5701 is STARTING 125 | 二月 12, 2023 10:27:25 上午 com.hazelcast.internal.cluster.ClusterService 126 | 信息: [192.168.56.1]:5701 [dev] [4.2.6] 127 | 128 | Members {size:1, ver:1} [ 129 | Member [192.168.56.1]:5701 - 7aea407b-bdbb-41f3-b5f3-d7b3752ad068 this 130 | ] 131 | 132 | 二月 12, 2023 10:27:25 上午 com.hazelcast.core.LifecycleService 133 | 信息: [192.168.56.1]:5701 [dev] [4.2.6] [192.168.56.1]:5701 is STARTED 134 | 二月 12, 2023 10:27:25 上午 com.hazelcast.internal.partition.impl.PartitionStateManager 135 | 信息: [192.168.56.1]:5701 [dev] [4.2.6] Initializing cluster partition table arrangement... 136 | Starting ConsumerVerticle 137 | Starting ProducerVerticle 138 | Starting to send messages. 139 | Consumer registered after 18 ms 140 | Received first message after 51 ms 141 | 20000 eventbus messages sent in 254 ms. 142 | 40000 eventbus messages sent in 560 ms. 143 | 60000 eventbus messages sent in 686 ms. 144 | 80000 eventbus messages sent in 775 ms. 145 | 100000 eventbus messages sent in 919 ms. 146 | 120000 eventbus messages sent in 986 ms. 147 | 140000 eventbus messages sent in 1063 ms. 148 | 160000 eventbus messages sent in 1164 ms. 149 | 180000 eventbus messages sent in 1671 ms. 150 | 200000 eventbus messages sent in 1782 ms. 151 | 220000 eventbus messages sent in 1856 ms. 152 | 240000 eventbus messages sent in 1947 ms. 153 | 260000 eventbus messages sent in 2108 ms. 154 | 280000 eventbus messages sent in 2200 ms. 155 | 300000 eventbus messages sent in 2303 ms. 156 | 320000 eventbus messages sent in 2399 ms. 157 | 340000 eventbus messages sent in 2498 ms. 158 | 360000 eventbus messages sent in 2608 ms. 159 | 380000 eventbus messages sent in 2867 ms. 160 | 400000 eventbus messages sent in 3029 ms. 161 | 420000 eventbus messages sent in 3125 ms. 162 | 440000 eventbus messages sent in 3226 ms. 163 | 460000 eventbus messages sent in 3332 ms. 164 | 480000 eventbus messages sent in 3436 ms. 165 | 500000 eventbus messages sent in 3538 ms. 166 | replyCount: 10000 after 4001 ms 167 | replyCount: 20000 after 4017 ms 168 | replyCount: 30000 after 4030 ms 169 | replyCount: 40000 after 4043 ms 170 | replyCount: 50000 after 4057 ms 171 | replyCount: 60000 after 4070 ms 172 | replyCount: 70000 after 4083 ms 173 | replyCount: 80000 after 4096 ms 174 | replyCount: 90000 after 4109 ms 175 | replyCount: 100000 after 4122 ms 176 | replyCount: 110000 after 4135 ms 177 | replyCount: 120000 after 4148 ms 178 | replyCount: 130000 after 4159 ms 179 | replyCount: 140000 after 4170 ms 180 | replyCount: 150000 after 4180 ms 181 | replyCount: 160000 after 4190 ms 182 | replyCount: 170000 after 4200 ms 183 | replyCount: 180000 after 4211 ms 184 | replyCount: 190000 after 4222 ms 185 | replyCount: 200000 after 4233 ms 186 | replyCount: 210000 after 4243 ms 187 | replyCount: 220000 after 4253 ms 188 | replyCount: 230000 after 4263 ms 189 | replyCount: 240000 after 4273 ms 190 | replyCount: 250000 after 4283 ms 191 | replyCount: 260000 after 4294 ms 192 | replyCount: 270000 after 4305 ms 193 | replyCount: 280000 after 4315 ms 194 | replyCount: 290000 after 4326 ms 195 | replyCount: 300000 after 4337 ms 196 | replyCount: 310000 after 4348 ms 197 | replyCount: 320000 after 4359 ms 198 | replyCount: 330000 after 4371 ms 199 | replyCount: 340000 after 4382 ms 200 | replyCount: 350000 after 4393 ms 201 | replyCount: 360000 after 4405 ms 202 | replyCount: 370000 after 4416 ms 203 | replyCount: 380000 after 4427 ms 204 | replyCount: 390000 after 4438 ms 205 | replyCount: 400000 after 4448 ms 206 | replyCount: 410000 after 4458 ms 207 | replyCount: 420000 after 4468 ms 208 | replyCount: 430000 after 4478 ms 209 | replyCount: 440000 after 4488 ms 210 | replyCount: 450000 after 4498 ms 211 | replyCount: 460000 after 4508 ms 212 | replyCount: 470000 after 4518 ms 213 | replyCount: 480000 after 4528 ms 214 | replyCount: 490000 after 4537 ms 215 | replyCount: 500000 after 4546 ms 216 | all replies received in 4546 ms 217 | ``` 218 | 219 | ------ 220 | 221 | <<<<<< [END] >>>>>> 222 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 4 | # Copyright © 2015-2021 the original authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | # 21 | # Gradle start up script for POSIX generated by Gradle. 22 | # 23 | # Important for running: 24 | # 25 | # (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is 26 | # noncompliant, but you have some other compliant shell such as ksh or 27 | # bash, then to run this script, type that shell name before the whole 28 | # command line, like: 29 | # 30 | # ksh Gradle 31 | # 32 | # Busybox and similar reduced shells will NOT work, because this script 33 | # requires all of these POSIX shell features: 34 | # * functions; 35 | # * expansions «$var», «${var}», «${var:-default}», «${var+SET}», 36 | # «${var#prefix}», «${var%suffix}», and «$( cmd )»; 37 | # * compound commands having a testable exit status, especially «case»; 38 | # * various built-in commands including «command», «set», and «ulimit». 39 | # 40 | # Important for patching: 41 | # 42 | # (2) This script targets any POSIX shell, so it avoids extensions provided 43 | # by Bash, Ksh, etc; in particular arrays are avoided. 44 | # 45 | # The "traditional" practice of packing multiple parameters into a 46 | # space-separated string is a well documented source of bugs and security 47 | # problems, so this is (mostly) avoided, by progressively accumulating 48 | # options in "$@", and eventually passing that to Java. 49 | # 50 | # Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, 51 | # and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; 52 | # see the in-line comments for details. 53 | # 54 | # There are tweaks for specific operating systems such as AIX, CygWin, 55 | # Darwin, MinGW, and NonStop. 56 | # 57 | # (3) This script is generated from the Groovy template 58 | # https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt 59 | # within the Gradle project. 60 | # 61 | # You can find Gradle at https://github.com/gradle/gradle/. 62 | # 63 | ############################################################################## 64 | 65 | # Attempt to set APP_HOME 66 | 67 | # Resolve links: $0 may be a link 68 | app_path=$0 69 | 70 | # Need this for daisy-chained symlinks. 71 | while 72 | APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path 73 | [ -h "$app_path" ] 74 | do 75 | ls=$( ls -ld "$app_path" ) 76 | link=${ls#*' -> '} 77 | case $link in #( 78 | /*) app_path=$link ;; #( 79 | *) app_path=$APP_HOME$link ;; 80 | esac 81 | done 82 | 83 | # This is normally unused 84 | # shellcheck disable=SC2034 85 | APP_BASE_NAME=${0##*/} 86 | APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit 87 | 88 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 89 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 90 | 91 | # Use the maximum available, or set MAX_FD != -1 to use that value. 92 | MAX_FD=maximum 93 | 94 | warn () { 95 | echo "$*" 96 | } >&2 97 | 98 | die () { 99 | echo 100 | echo "$*" 101 | echo 102 | exit 1 103 | } >&2 104 | 105 | # OS specific support (must be 'true' or 'false'). 106 | cygwin=false 107 | msys=false 108 | darwin=false 109 | nonstop=false 110 | case "$( uname )" in #( 111 | CYGWIN* ) cygwin=true ;; #( 112 | Darwin* ) darwin=true ;; #( 113 | MSYS* | MINGW* ) msys=true ;; #( 114 | NONSTOP* ) nonstop=true ;; 115 | esac 116 | 117 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 118 | 119 | 120 | # Determine the Java command to use to start the JVM. 121 | if [ -n "$JAVA_HOME" ] ; then 122 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 123 | # IBM's JDK on AIX uses strange locations for the executables 124 | JAVACMD=$JAVA_HOME/jre/sh/java 125 | else 126 | JAVACMD=$JAVA_HOME/bin/java 127 | fi 128 | if [ ! -x "$JAVACMD" ] ; then 129 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 130 | 131 | Please set the JAVA_HOME variable in your environment to match the 132 | location of your Java installation." 133 | fi 134 | else 135 | JAVACMD=java 136 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 137 | 138 | Please set the JAVA_HOME variable in your environment to match the 139 | location of your Java installation." 140 | fi 141 | 142 | # Increase the maximum file descriptors if we can. 143 | if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then 144 | case $MAX_FD in #( 145 | max*) 146 | # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. 147 | # shellcheck disable=SC3045 148 | MAX_FD=$( ulimit -H -n ) || 149 | warn "Could not query maximum file descriptor limit" 150 | esac 151 | case $MAX_FD in #( 152 | '' | soft) :;; #( 153 | *) 154 | # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. 155 | # shellcheck disable=SC3045 156 | ulimit -n "$MAX_FD" || 157 | warn "Could not set maximum file descriptor limit to $MAX_FD" 158 | esac 159 | fi 160 | 161 | # Collect all arguments for the java command, stacking in reverse order: 162 | # * args from the command line 163 | # * the main class name 164 | # * -classpath 165 | # * -D...appname settings 166 | # * --module-path (only if needed) 167 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. 168 | 169 | # For Cygwin or MSYS, switch paths to Windows format before running java 170 | if "$cygwin" || "$msys" ; then 171 | APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) 172 | CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) 173 | 174 | JAVACMD=$( cygpath --unix "$JAVACMD" ) 175 | 176 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 177 | for arg do 178 | if 179 | case $arg in #( 180 | -*) false ;; # don't mess with options #( 181 | /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath 182 | [ -e "$t" ] ;; #( 183 | *) false ;; 184 | esac 185 | then 186 | arg=$( cygpath --path --ignore --mixed "$arg" ) 187 | fi 188 | # Roll the args list around exactly as many times as the number of 189 | # args, so each arg winds up back in the position where it started, but 190 | # possibly modified. 191 | # 192 | # NB: a `for` loop captures its iteration list before it begins, so 193 | # changing the positional parameters here affects neither the number of 194 | # iterations, nor the values presented in `arg`. 195 | shift # remove old arg 196 | set -- "$@" "$arg" # push replacement arg 197 | done 198 | fi 199 | 200 | # Collect all arguments for the java command; 201 | # * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of 202 | # shell script including quotes and variable substitutions, so put them in 203 | # double quotes to make sure that they get re-expanded; and 204 | # * put everything else in single quotes, so that it's not re-expanded. 205 | 206 | set -- \ 207 | "-Dorg.gradle.appname=$APP_BASE_NAME" \ 208 | -classpath "$CLASSPATH" \ 209 | org.gradle.wrapper.GradleWrapperMain \ 210 | "$@" 211 | 212 | # Stop when "xargs" is not available. 213 | if ! command -v xargs >/dev/null 2>&1 214 | then 215 | die "xargs is not available" 216 | fi 217 | 218 | # Use "xargs" to parse quoted args. 219 | # 220 | # With -n1 it outputs one arg per line, with the quotes and backslashes removed. 221 | # 222 | # In Bash we could simply go: 223 | # 224 | # readarray ARGS < <( xargs -n1 <<<"$var" ) && 225 | # set -- "${ARGS[@]}" "$@" 226 | # 227 | # but POSIX shell has neither arrays nor command substitution, so instead we 228 | # post-process each arg (as a line of input to sed) to backslash-escape any 229 | # character that might be a shell metacharacter, then use eval to reverse 230 | # that process (while maintaining the separation between arguments), and wrap 231 | # the whole thing up as a single "set" statement. 232 | # 233 | # This will of course break if any of these variables contains a newline or 234 | # an unmatched quote. 235 | # 236 | 237 | eval "set -- $( 238 | printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | 239 | xargs -n1 | 240 | sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | 241 | tr '\n' ' ' 242 | )" '"$@"' 243 | 244 | exec "$JAVACMD" "$@" 245 | --------------------------------------------------------------------------------