Skip to content

Commit 9d23daa

Browse files
authored
Merge pull request #31715 from geoand/websocket-perf
Disable Vert.x websockets when websocket extensions are not present
2 parents 76fa7e1 + e615518 commit 9d23daa

File tree

7 files changed

+38
-5
lines changed

7 files changed

+38
-5
lines changed

.github/native-tests.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@
9292
},
9393
{
9494
"category": "HTTP",
95-
"timeout": 90,
96-
"test-modules": "elytron-resteasy, resteasy-jackson, elytron-resteasy-reactive, resteasy-mutiny, resteasy-reactive-kotlin/standard, vertx, vertx-http, vertx-web, vertx-web-jackson, vertx-graphql, virtual-http, rest-client, rest-client-reactive, rest-client-reactive-stork, rest-client-reactive-multipart",
95+
"timeout": 95,
96+
"test-modules": "elytron-resteasy, resteasy-jackson, elytron-resteasy-reactive, resteasy-mutiny, resteasy-reactive-kotlin/standard, vertx, vertx-http, vertx-web, vertx-web-jackson, vertx-graphql, virtual-http, rest-client, rest-client-reactive, rest-client-reactive-stork, rest-client-reactive-multipart, websockets",
9797
"os-name": "ubuntu-latest"
9898
},
9999
{

core/deployment/src/main/java/io/quarkus/deployment/Capability.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ public interface Capability {
128128
String VERTX = QUARKUS_PREFIX + ".vertx";
129129
String VERTX_CORE = VERTX + ".core";
130130
String VERTX_HTTP = VERTX + ".http";
131+
String VERTX_WEBSOCKETS = VERTX + ".websockets";
131132

132133
String APICURIO_REGISTRY = QUARKUS_PREFIX + ".apicurio.registry";
133134
String APICURIO_REGISTRY_AVRO = APICURIO_REGISTRY + ".avro";

extensions/vertx-http/deployment/src/main/java/io/quarkus/vertx/http/deployment/VertxHttpProcessor.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
import io.quarkus.bootstrap.classloading.ClassPathElement;
2424
import io.quarkus.bootstrap.classloading.QuarkusClassLoader;
2525
import io.quarkus.builder.BuildException;
26+
import io.quarkus.deployment.Capabilities;
27+
import io.quarkus.deployment.Capability;
2628
import io.quarkus.deployment.annotations.BuildProducer;
2729
import io.quarkus.deployment.annotations.BuildStep;
2830
import io.quarkus.deployment.annotations.ExecutionTime;
@@ -348,6 +350,7 @@ void openSocket(ApplicationStartBuildItem start,
348350
Optional<RequireVirtualHttpBuildItem> requireVirtual,
349351
EventLoopCountBuildItem eventLoopCount,
350352
List<WebsocketSubProtocolsBuildItem> websocketSubProtocols,
353+
Capabilities capabilities,
351354
VertxHttpRecorder recorder) throws IOException {
352355
boolean startVirtual = requireVirtual.isPresent() || httpBuildTimeConfig.virtual;
353356
if (startVirtual) {
@@ -361,7 +364,7 @@ void openSocket(ApplicationStartBuildItem start,
361364
eventLoopCount.getEventLoopCount(),
362365
websocketSubProtocols.stream().map(bi -> bi.getWebsocketSubProtocols())
363366
.collect(Collectors.toList()),
364-
launchMode.isAuxiliaryApplication());
367+
launchMode.isAuxiliaryApplication(), !capabilities.isPresent(Capability.VERTX_WEBSOCKETS));
365368
}
366369

367370
@BuildStep

extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/VertxHttpRecorder.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ public class VertxHttpRecorder {
128128

129129
public static final String MAX_REQUEST_SIZE_KEY = "io.quarkus.max-request-size";
130130

131+
private static final String DISABLE_WEBSOCKETS_PROP_NAME = "vertx.disableWebsockets";
132+
131133
/**
132134
* Order mark for route with priority over the default route (add an offset from this mark)
133135
**/
@@ -163,7 +165,6 @@ public class VertxHttpRecorder {
163165

164166
/** JVM system property that disables URI validation, don't use this in production. */
165167
private static final String DISABLE_URI_VALIDATION_PROP_NAME = "vertx.disableURIValidation";
166-
167168
/**
168169
* Disables HTTP headers validation, so we can save some processing and save some allocations.
169170
*/
@@ -297,9 +298,14 @@ public RuntimeValue<io.vertx.mutiny.ext.web.Router> createMutinyRouter(final Run
297298
public void startServer(Supplier<Vertx> vertx, ShutdownContext shutdown,
298299
LaunchMode launchMode,
299300
boolean startVirtual, boolean startSocket, Supplier<Integer> ioThreads, List<String> websocketSubProtocols,
300-
boolean auxiliaryApplication)
301+
boolean auxiliaryApplication, boolean disableWebSockets)
301302
throws IOException {
302303

304+
// disable websockets if we have determined at build time that we should and the user has not overridden the relevant Vert.x property
305+
if (disableWebSockets && !System.getProperties().containsKey(DISABLE_WEBSOCKETS_PROP_NAME)) {
306+
System.setProperty(DISABLE_WEBSOCKETS_PROP_NAME, "true");
307+
}
308+
303309
if (startVirtual) {
304310
initializeVirtual(vertx.get());
305311
shutdown.addShutdownTask(() -> {

extensions/websockets/server/runtime/pom.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@
6060
<excludedArtifact>org.jboss.spec.javax.websocket:jboss-websocket-api_1.1_spec</excludedArtifact>
6161
<excludedArtifact>javax.websocket:javax.websocket-api</excludedArtifact>
6262
</excludedArtifacts>
63+
<capabilities>
64+
<provides>io.quarkus.vertx.websockets</provides>
65+
</capabilities>
6366
</configuration>
6467
</plugin>
6568
<plugin>

integration-tests/opentelemetry/pom.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,15 @@
132132
</execution>
133133
</executions>
134134
</plugin>
135+
<plugin>
136+
<groupId>org.apache.maven.plugins</groupId>
137+
<artifactId>maven-surefire-plugin</artifactId>
138+
<configuration>
139+
<systemPropertyVariables>
140+
<vertx.disableWebsockets>false</vertx.disableWebsockets>
141+
</systemPropertyVariables>
142+
</configuration>
143+
</plugin>
135144
</plugins>
136145
</build>
137146

@@ -155,6 +164,9 @@
155164
<artifactId>maven-surefire-plugin</artifactId>
156165
<configuration>
157166
<skipTests>${native.surefire.skip}</skipTests>
167+
<systemPropertyVariables>
168+
<vertx.disableWebsockets>false</vertx.disableWebsockets>
169+
</systemPropertyVariables>
158170
</configuration>
159171
</plugin>
160172

@@ -168,6 +180,7 @@
168180
</goals>
169181
<configuration>
170182
<systemPropertyVariables>
183+
<vertx.disableWebsockets>false</vertx.disableWebsockets>
171184
<native.image.path>
172185
${project.build.directory}/${project.build.finalName}-runner
173186
</native.image.path>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package io.quarkus.websockets;
2+
3+
import io.quarkus.test.junit.QuarkusIntegrationTest;
4+
5+
@QuarkusIntegrationTest
6+
public class ChatIT extends ChatTest {
7+
}

0 commit comments

Comments
 (0)