Vert.x PoC for Project Loom Support

Related tags

JSON vertx codegen loom
Overview

Vert.x Loom Wrapper Codegen

This project contains a proof of concept implementation for a codegen wrapper API that provides virtual async-await support to Vert.x

Upstream changes for this PoC were made to vert-rx and are needed to compile the project.

This PoC is based on the Async/Await support by August Nagro.

Example

import io.vertx.core.Future;
import io.vertx.core.http.HttpMethod;
import io.vertx.core.json.JsonArray;
import io.vertx.core.json.JsonObject;
import io.vertx.lang.loom.Async;
import io.vertx.loom.core.Vertx;
import io.vertx.loom.ext.web.Router;

Vertx vertx = Vertx.vertx();
Router router = Router.router(vertx);
// The handler method will automatically be invoked in a dedicated virtual thread when using the wrapper API within the `io.vertx.loom` packages.
router.route("/test").handler(rc -> {
  // The await method can be used to wait until the async operation has completed
  List<Long> userIds = Async.await(loadUserIds());
  JsonObject response = new JsonObject();
  response.put("userIds", new JsonArray(userIds));
  rc.end(response.encodePrettily());
});

private Future<List<Long>> loadUserIds() {
  // Invoking async will run the code in new virtual thread and return a future
  return Async.async(() -> {
    Thread.sleep(100);
    return Async.await(loadIdsFromDb());
  });
}

private Future<List<Long>> loadIdsFromDb() {
  return Async.async(() -> {
    Thread.sleep(100);
    return Arrays.asList(1L, 2L, 3L, 42L);
  });
}

Benefits

Stacktraces

The traces which can be uses to followup on the execution sequence. Normally with async operations the information about the origin of the operation is often obfuscated or no longer accessible.

Nov 02, 2021 6:30:06 PM io.vertx.test.core.AsyncTestBase
INFO: Starting test: UsecaseTest#testServer
Exception in thread "vert.x-virtual-thread-0" java.lang.RuntimeException: java.lang.RuntimeException: java.lang.RuntimeException: Error
	at io.vertx.lang.loom.Coroutine.await(Coroutine.java:48)
	at io.vertx.lang.loom.Async.await(Async.java:60)
	at io.vertx.core.it.UsecaseTest.lambda$0(UsecaseTest.java:25)
	at io.vertx.loom.ext.web.Route$1.lambda$0(Route.java:174)
	at io.vertx.lang.loom.Async.lambda$1(Async.java:76)
	at java.base/java.lang.VirtualThread.run(VirtualThread.java:299)
	at java.base/java.lang.VirtualThread$VThreadContinuation.lambda$new$0(VirtualThread.java:176)
	at java.base/java.lang.Continuation.enter0(Continuation.java:372)
	at java.base/java.lang.Continuation.enter(Continuation.java:365)
Caused by: java.lang.RuntimeException: java.lang.RuntimeException: Error
	at io.vertx.lang.loom.Coroutine.await(Coroutine.java:48)
	at io.vertx.lang.loom.Async.await(Async.java:60)
	at io.vertx.core.it.UsecaseTest.lambda$5(UsecaseTest.java:48)
	at io.vertx.lang.loom.Async.lambda$0(Async.java:42)
	... 4 more
Caused by: java.lang.RuntimeException: Error
	at io.vertx.core.it.UsecaseTest.lambda$6(UsecaseTest.java:57)
	... 5 more

Virtual Threads

The PoC makes use of JDK 18 Project Loom and thus allows the use of virtual threads. The callback handlers in various Vert.x classes will be automatically be wrapped and executed in a virtual thread. This allows for great parallelism. Potential calls to blocking APIs will no longer block the allocated thread in the JVM (carrier thread). Instead the JVM will automatically switch over to another virtual thread and continue executing code there. In the example above Thread.sleep is used to simulate this behaviour.

Open Tasks

  • Investigate thread local impact and potential callback issues with body-handler of the http client
  • Implement ways to limit virtual thread pool size
  • Check impact of very high virtual thread count on performance and memory
  • Check how metrics on the virtual pool scheduler can be gathered and exposed
You might also like...

Experiments on how to add Loom support for Netty

Netty Loom Experiment This repository contains Project Loom and Netty related test code. Contents / Goals I created these examples since I was curious

Oct 14, 2022

A short and practical intro into project loom

A short and practical intro into project loom

project-loom Project loom is all about making concurrency easier (for developers) on the JVM. It is in experimental phase. Download the early access b

Dec 15, 2021

Echo client-server components to evaluate Project Loom virtual threads.

Echo client-server components to evaluate Project Loom virtual threads.

Overview Project Loom is the OpenJDK initiative to introduce user-mode threads in Java. The purpose of this repository is to compare Project Loom virt

Nov 1, 2022

The first Java Actor System supporting fibers from Project Loom

Fibry Fibry is an experimental Actor System built to be simple and flexible. Hopefully, it will also be fun to use. Fibry is the first Java Actor Syst

Dec 26, 2022

Experimenting with Project Loom

Project Loom Lab Experiments with Project Loom's features based on these JEP(draft)s: Structured Concurrency Virtual Threads Experiments For these exp

Dec 23, 2022

Vert.x is a tool-kit for building reactive applications on the JVM

Vert.x Core This is the repository for Vert.x core. Vert.x core contains fairly low-level functionality, including support for HTTP, TCP, file system

Jan 8, 2023

Vert.x jOOQ DSL

jOOQ.x - Vertx jOOQ DSL jooqx leverages the power of typesafe SQL from jOOQ DSL and running on SQL connection in a reactive and non-blocking of SQL dr

Nov 16, 2022

A reactive dataflow engine, a data stream processing framework using Vert.x

๐Ÿ NeonBee Core NeonBee is an open source reactive dataflow engine, a data stream processing framework using Vert.x. Description NeonBee abstracts mos

Jan 4, 2023

Consume an async api (with callback) from sync endpoint using vert.x

Consume an async api (with callback) from sync endpoint using vert.x

vertx-async-to-sync Problem statement Suppose we have two services - A and B. In a trivial and everyday scenario, client makes request to A. A then do

Oct 19, 2022

Simple and lightweight sip server to create voice robots, based on vert.x

Overview Lightweight SIP application built on vert.x. It's intended to be used as addon for full-featured PBX to implement programmable voice scenario

May 15, 2022

Async Await but for Vert.x

hang-around Async Await but for Vert.x One of the main pain points of asynchronous programming is that code flow can be hard to read. With the upcomin

Jul 30, 2022

Vert.x virtual threads incubator

Vert.x Virtual Threads Incubator Incubator for virtual threads based prototypes. Prerequisites Vert.x 4.3.2 Java 19 using preview feature OpenJDK 19 E

Dec 27, 2022

The application is a PoC that helps in identifying modern bankers, potentially malicious and remote controlling applications abusing Android AccessibilityService.

Motivation Project aims to help in: identifying keyloggers and events hijacking malicious applications such as Anubis/TeaBot, identifying a "fake bank

Dec 9, 2022

POC showing how to divide endpoint(s) among different Open-API screens

Multiple Open-API groups: Spring boot POC showing how to divide endpoint(s) among different Open-API screens Demo Link (Select definition from top rig

Dec 15, 2022

Log4J CVE-2021-44228 Minecraft PoC

CVE-2021-44228 in Minecraft Java 16 Paper server build #397 Minecraft 1.17.1 Exploitation In Java 16 only deserialization attacks work by default usin

Feb 15, 2022

LightAdmin - [PoC] Pluggable CRUD UI library for Java web applications

 LightAdmin - [PoC] Pluggable CRUD UI library for Java web applications

LightAdmin - [PoC] Pluggable CRUD UI library for Java web applications The primary goal of this PoC project is to speed up application development by

Dec 16, 2022

spring-cloud-function SpEL RCE, Vultarget & Poc

spring-cloud-function SpEL RCE, Vultarget & Poc

spring-cloud-function SpEL RCE Vultarget You can build it for youself. here is the source of the Vuln App Or you can use the release which built by cc

Nov 30, 2022

PoC for CVE-2021-31805 (Apache Struts2)

CVE-2021-31805 PoC for CVE-2021-31805 (Apache Struts2) CVE-2021-31805ใฎ่งฃ่ชฌ่จ˜ไบ‹ใงไฝฟ็”จใ—ใŸใ‚ขใƒ—ใƒชใ‚ฑใƒผใ‚ทใƒงใƒณใงใ™ใ€‚ ใ‚ปใƒƒใƒˆใ‚ขใƒƒใƒ— $ docker-compose build $ docker-compose up -d ๅ‹•ไฝœ็ขบ่ช

May 21, 2022

Slueth(Zipkin) ๋ฅผ ํ†ตํ•œ SQS Message Tracing POC(Proof of concept) ์ž…๋‹ˆ๋‹ค.

Slueth(Zipkin) ๋ฅผ ํ†ตํ•œ SQS Message Tracing POC(Proof of concept) ์ž…๋‹ˆ๋‹ค.

Sleuth AWS SQS POC ํ•ด๋‹น ํ”„๋กœ์ ํŠธ๋Š” Slueth(Zipkin) ๋ฅผ ํ†ตํ•œ ๋ฉ”์‹œ์ง€ ์ถ”์  POC(Proof of concept) ์ž…๋‹ˆ๋‹ค. Rest API ๋ฅผ ํ†ตํ•ด POST ์š”์ฒญ์„ ๋ฐ›์œผ๋ฉด, ๋ฉ”์‹œ์ง€๋ฅผ ๋ฐœํ–‰/์†Œ๋น„ ํ•ฉ๋‹ˆ๋‹ค. ์ด ๊ณผ์ •์—์„œ ์œ ์ง€๋˜๋Š” TraceId ๋ฅผ ํ™•์ธ

Nov 29, 2022
Comments
  • Virtual Thread Pool Configuration

    Virtual Thread Pool Configuration

    Add a mechanism to configure the thread pool size that is used by Async#async.

    Also investigate whether a custom scheduler can be used to gather metric data.

    opened by Jotschi 0
  • AbstractVerticle#stop / AbstractVerticle#start not executed via async

    AbstractVerticle#stop / AbstractVerticle#start not executed via async

    The AbstractVerticle#stop / AbstractVerticle#start methods are currently not being wrapped via Async#async.

    The DeploymentManager invokes the methods using the context of the verticle (via runOnContext).

    The context is provided via vertx.createWorkerContext / vertx.createEventLoopContext.

    Options:

    • Patch createWorkerContext / createEventLoopContext methods in Vert.x (e.g. by providing a custom thread factory.)
    • Patch DeploymentManager to wrap the start / stop calls with Async.async
    • Leave the behaviour unchanged. Thus it would be required for a user to manually use Async.async within the start method implementation of the custom verticle.
    • Patch ContextImpl#runOnContext to use Async.async.
    • Add startAsync / stopAsync abstract methods to io.vertx.loom.core.AbstractVerticle and invoke those from regular start / stop.
    opened by Jotschi 0
Owner
Johannes Schรผth
Johannes Schรผth
Set of support modules for Java 8 datatypes (Optionals, date/time) and features (parameter names)

Overview This is a multi-module umbrella project for Jackson modules needed to support Java 8 features, especially with Jackson 2.x that only requires

FasterXML, LLC 372 Dec 23, 2022
Extension module to properly support datatypes of javax.money

Jackson Datatype Money Jackson Datatype Money is a Jackson module to support JSON serialization and deserialization of JavaMoney data types. It fills

Zalando SE 217 Jan 2, 2023
It generates a circular Image from users display names with animation support

DisplayNameView generates an avatar from users name. Setup allprojects { repositories { ... maven { url 'https://jitpack.io' }

Emre 4 Sep 24, 2021
A flexible JSON/YAML linter for creating automated style guides, with baked in support for OpenAPI v2 & v3.

Astrum A flexible JSON/YAML linter for creating automated style guides, with baked in support for OpenAPI v2 & v3. OpenAPI is now a widely-adopted met

Apiwiz 11 May 24, 2022
Main Portal page for the Jackson project

Jackson Project Home @github This is the home page of the Jackson Project. What is New? Oct 1, 2020: Jackson participates in Hacktoberfest2020 and we

FasterXML, LLC 7.9k Jan 2, 2023
Eclipse Yasson project

Eclipse Yasson Yasson is a Java framework which provides a standard binding layer between Java classes and JSON documents. This is similar to what JAX

Eclipse EE4J 183 Aug 31, 2022
Java EE project https://zarisa-boutique.herokuapp.com/

CSC584-Enterprise-Programming This repository contains the Enterprise Programming end-of-semester project. It's a basic Java EE project with CRUD (Cre

Farhana Ahmad 2 Oct 11, 2021
Uber-project for (some) standard Jackson textual format backends: csv, properties, yaml (xml to be added in future)

Overview This is a multi-module umbrella project for Jackson standard text-format dataformat backends. Dataformat backends are used to support format

FasterXML, LLC 351 Dec 22, 2022
Async-Await support for Vertx using Project Loom

Vertx-Async-Await Async-Await support for Vertx using Project Loom. import static com.augustnagro.vertx.loom.AsyncAwait.async; import static com.augus

August Nagro 28 Oct 10, 2022
Async-Await support for Vertx using Project Loom

Vertx-Async-Await Async-Await support for Vertx using Project Loom. import static com.augustnagro.vertx.loom.AsyncAwait.async; import static com.augus

August Nagro 21 Jun 9, 2022