Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support virtual threads #2311

Merged
merged 4 commits into from
Dec 20, 2024
Merged

Conversation

boaks
Copy link
Contributor

@boaks boaks commented Dec 13, 2024

Signed-off-by: Achim Kraus <[email protected]>
Add connection to established connections before resume it.

Signed-off-by: Achim Kraus <[email protected]>
@boaks boaks force-pushed the support_virtual_threads branch 3 times, most recently from 761cf2b to c3603be Compare December 17, 2024 11:22
@Nick-The-Uncharted
Copy link

Remember to do socket.setSoTimeout(xxx) org.eclipse.californium.scandium.DTLSConnector#init, or java.net.DatagramSocket#receive may park forever.

@boaks
Copy link
Contributor Author

boaks commented Dec 17, 2024

or java.net.DatagramSocket#receive may park forever.

Not clear, what you mean. In my experience, there is no need for that. The thread will either wait for a message or an "interrupt" on shutdown.

For which use-case do you consider a socket timeout to be useful?

@Nick-The-Uncharted
Copy link

Nick-The-Uncharted commented Dec 17, 2024

Remember to do socket.setSoTimeout(xxx) org.eclipse.californium.scandium.DTLSConnector#init, or java.net.DatagramSocket#receive may park forever.

Calling java.net.DatagramSocket#receive in virtual thread would lead to virtualthread unparker scheduled after about Long.MAX_VALUE, which leading to negative time returned by java.util.concurrent.ScheduledThreadPoolExecutor#triggerTime(long)

It may become the head of workQueue (depends on whether it overflows again when compareTo). If that happens, the unparker thread could park forever because getDelay is overflowed again to a very big number so everytime the head is peeked from queue, it will still have a positive delay and won't be executed(see java.util.concurrent.DelayQueue#poll()).

See this jdk issue

@Nick-The-Uncharted
Copy link

I tried virtual thread at Augest and succesfully started 60000 (limited by avaiable port of linux) with 7s communication period for 24-hours stress test.

I write down what I do at this issue, please see if that helps.

@boaks
Copy link
Contributor Author

boaks commented Dec 17, 2024

Not sure, at least java.util.concurrent.ScheduledThreadPoolExecutor#triggerTime(long) isn't used directly.
The intended support is limited to dtls + udp receiver threads and udp sender threads. These thread are only used
to read the data from the socket and do a very early decoding in order to be able to do further processing. These threads are not put in "ThreadPools", at least not with the code of Californium.

The ThreadPool dtls uses for the main work-load can be passed in. So such a ThreadPool don't need to use virtual threads.

Is there a hidden mechanism, which uses a ScheduledThreadPoolExecutor for virtual threads without explicitly doing so?

@Nick-The-Uncharted
Copy link

Not sure, at least java.util.concurrent.ScheduledThreadPoolExecutor#triggerTime(long) isn't used directly.

It's used by virtual thread unparker (java.lang.VirtualThread#UNPARKER) implictly.

@boaks
Copy link
Contributor Author

boaks commented Dec 17, 2024

OK. Then it requires a "large timeout" smaller than Long.MAX_VALUE? Which one did you use?

@Nick-The-Uncharted
Copy link

Nick-The-Uncharted commented Dec 17, 2024 via email

@boaks
Copy link
Contributor Author

boaks commented Dec 18, 2024

I added the socket timeout.
In my tests I wasn't able to reproduce/verify the defect and this workaround as fix (I run 21.0.5 maybe that has already fixed it).
There is one test SecureTest which fails running on jenkins, when virtual threads are used. But succeeds on the same machine running mvn from cli. Using the socket timeout doesn't change that.

@Nick-The-Uncharted
Copy link

I added the socket timeout. In my tests I wasn't able to reproduce/verify the defect and this workaround as fix (I run 21.0.5 maybe that has already fixed it).

It only happens when I start tens of thoudsands of client in very fast pace, and they all have short communication period (7s).

Reproducing that maybe hard but at least setting a timeout won't have any bad effect.

@boaks boaks force-pushed the support_virtual_threads branch from 17b3199 to ca3acd5 Compare December 19, 2024 11:30
@boaks boaks merged commit f796b94 into eclipse-californium:main Dec 20, 2024
1 check passed
@boaks boaks deleted the support_virtual_threads branch January 1, 2025 11:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants