Thanks for the detailed response. We hope OpenJDK will commit to supporting custom schedulers at some point. For "self deadlock" cases, the API could provide some guidelines on what users should not do inside custom schedulers.
Our colleague David Gay also provided more details on the multi-tenancy use case:
Firestore is a cloud-based database, implemented with a multi-tenant (i.e., a single job serves many customers) architecture. Multi-tenancy allows us to serve small-scale customers very cheaply, but brings isolation challenges: : traffic to a single Firestore database can potentially affect the performance and availability of other databases by consuming all or most of the resources in one or more components. Thus providing isolation between customers sending traffic to the same task in a job is critical.
Specifically for Java: Firestore backends are implemented in Java, currently using a custom asynchronous programming framework which basically:
- provides all the usual Java control structures (try-catch, loops, etc)
- "automatic" suspension at (manually identified) blocking points
- scheduling of 'slices' of these asynchronous computations via a fair scheduler (we're using a stride scheduler)
Replacing our custom asynchronous programming framework with virtual threads is obviously highly desirable - much more readable and efficient code (and I can stop getting confused by continuations), but the fair scheduling of slices is an absolute requirement. We did experiments comparing the performance impact of an antagonistic workload from customer A on an 'innocent' workload from customer B:
- without fair scheduling, B sees two orders of magnitude worse latency (p50 and p99)
- with fair scheduling, B sees essentially no p50 latency impact and tolerable p99 impact
The 'without fair scheduling' measurements are effectively measuring how the linux kernel schedules our threads - I would expect broadly similar results from the default virtual thread scheduler as neither has any information on which customer owns which traffic to appropriately prioritise scheduling.
The above is partly summarised from
https://research.google/pubs/firestore-the-nosql-serverless-database-for-the-application-developer/ - specifically see:
- section IV.C for the overview of our isolation approach
- section V.C and Figure 11 for the isolation benchmark