funky-eyes commented on code in PR #7870:
URL: https://github.com/apache/incubator-seata/pull/7870#discussion_r2629687257
##########
namingserver/src/main/resources/application.yml:
##########
@@ -18,6 +18,9 @@
server:
Review Comment:
We need to enable virtual threads.
##########
namingserver/src/main/java/org/apache/seata/namingserver/filter/ConsoleRemotingFilter.java:
##########
@@ -57,15 +54,15 @@ public class ConsoleRemotingFilter implements Filter {
private final NamingManager namingManager;
- private final AsyncRestTemplate asyncRestTemplate;
+ private final RestTemplate restTemplate;
Review Comment:
Since we've switched to RestTemplate, we need to enable virtual threads to
prevent blocking the thread pool when forwarding HTTP requests.
##########
namingserver/src/main/java/org/apache/seata/namingserver/filter/ConsoleRemotingFilter.java:
##########
@@ -113,34 +110,27 @@ public void doFilter(ServletRequest servletRequest,
ServletResponse servletRespo
// Create the HttpEntity with headers and body
HttpEntity<byte[]> httpEntity = new
HttpEntity<>(request.getCachedBody(), headers);
+ HttpMethod httpMethod;
+ try {
+ httpMethod =
HttpMethod.valueOf(request.getMethod());
+ } catch (IllegalArgumentException ex) {
+ logger.error("Unsupported HTTP method: {}",
request.getMethod(), ex);
+
response.setStatus(HttpServletResponse.SC_METHOD_NOT_ALLOWED);
+ return;
+ }
// Forward the request
AsyncContext asyncContext =
servletRequest.startAsync();
asyncContext.setTimeout(5000L);
- ListenableFuture<ResponseEntity<byte[]>>
responseEntityFuture = asyncRestTemplate.exchange(
- URI.create(targetUrl),
-
Objects.requireNonNull(HttpMethod.resolve(request.getMethod())),
- httpEntity,
- byte[].class);
- responseEntityFuture.addCallback(new
ListenableFutureCallback<ResponseEntity<byte[]>>() {
- @Override
- public void onFailure(Throwable ex) {
- try {
- logger.error(ex.getMessage(), ex);
-
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
- } finally {
- asyncContext.complete();
- }
- }
-
- @Override
- public void onSuccess(ResponseEntity<byte[]>
responseEntity) {
- // Copy response headers and status code
+ Thread.startVirtualThread(() -> {
Review Comment:
I believe there's no need to switch from Tomcat's default business thread
pool (with a maximum of 200 threads) to virtual threads. Instead, we can
directly configure Tomcat to use a virtual thread pool as its executor for
handling business threads.
Moreover, in this scenario, we can simply wait synchronously for the
response from the downstream server and then return it to the client—no
asynchronous processing is required. Adopting a synchronous request model with
virtual threads is perfectly sufficient and straightforward.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]