tipsy/loomylin — dự án mã nguồn mở — đang có 43 sao GitHub.
Tóm tắt dựng từ metadata GitHub của chính dự án — chưa có bài review TopGit. Trang sẽ tự động cập nhật khi bài review đầy đủ được xuất bản.
VÌ SAO CHƯA CÓ REVIEW
TopGit viết bài đầy đủ cho repo có nhiều sao nhất và được yêu cầu nhiều nhất. Trang này là snapshot trong thời gian chờ — xem README gốc ở tab READ ME.
Loomylin is a tech demo for Project Loom,
which brings lightweight user-mode threads (fibers/green-threads) to the JVM.
In the JDK, they refer to these threads as
Virtual Threads.
Not all operations are "Virtual Thread Friendly", you can find a list in the
OpenJDK Wiki.
There's also a nice Getting started guide in the Wiki,
but this is not required reading to understand this project.
The idea behind this project is to gain knowledge of the practical value of running Loom "in the wild",
by trying to use it with a traditional blocking HttpServlet server (in our case Jetty).
The project implements a ThreadPool
with virtual threads, passes this ThreadPool to a Jetty Server,
and passes this Jetty Server to a Javalin instance (for easy project setup).
The project has three servers:
A server with a QueuedThreadPool, 4 threads (the number of physical cores on my machine), running on port 7000
A server with a QueuedThreadPool, 32 threads, running on port 7001
A server with a custom LoomThreadPool, running on port 7002
The project contains instructions both for running with Docker
and without (using Maven Wrapper, so please, pick your poison.
The project contains two equivalent implementations, one Java and one Kotlin.
Running with Docker
The fastest way to run the project (provided you have Docker installed), is to:
After this you'll have all three servers running, and can proceed to load testing.
Running without Docker
First, you'll need to grab the latest version of OpenJDK.
The easiest way to do this is to install SDKMAN. This will also make it
easy to switch back to a stable JDK later, if you need to.
To list all the available JDKs, you do:
sdk list java
Locate an SDK with Loom (ex: 19-open), and do:
sdk install java 19-open
That's it. Now you can either run the project via Maven Wrapper by doing:
Or open the project in your favorite IDE. If you get Error: Cannot determine path to 'tools.jar' library for 16 (path/to/jdk-16) when running from IDEA, you should update to the latest version.
The main function in src/main/kotlin/loomylin/Loomylin.kt will start all three servers.
Load testing with hey
Disclaimer: I have very little experience with load testing, so take these results with a pinch of salt. Feedback to improve this section would be much appreciated!
You can load test using whatever you want, this section just outlines a quick and easy approach
with the library hey. If you want something from NPM,
autocannon seems like a pretty good alternative.
The hey tool runs requests per worker sequentially, so if each worker has 20 requests to run,
and each request takes 100ms, that worker should be done in 2s.
To warm everything up, all tests are run thrice in a for-loop.
Only the third result is included below.
Computational endpoint
This endpoint runs Math.random() 25000 times, then returns "Hello, World".
This number was chosen because it made the tests bearable to run.
When doing pure computation, having number of threads equal to the number of
physical cores should be the most efficient. Using 32 threads is almost three times as slow,
most likely because the overhead introduced by thread switching (and hyper-threading).
I expected the Loom server to be similar in performance to 4 threads, but it's almost twice as slow.
You can see that the request time is super consistent at 272ms, but there are a few
outliers in the results that ruin everything (12 requests took 2.6s to finish). These outliers
might be slow because of garbage collection, but I haven't had the time to look into that yet.
Waiting endpoint (blocking)
This endpoint is where Loom should shine. It does a simple Thread.sleep(100), before
settings the result to "Hello, World".
The 4 thread server is basically useless in this scenario. In theory it should spend
1000 * 100/min(4, 50)=25s, but it gets severely clogged and stuck switching between threads,
spending almost a full minute on servicing the 1000 requests.
The 32 thread server should spend 1000 * 100/min(32, 50)=3.1s, but
since there are more clients than threads, some thread switching and waiting does occur,
and it ends up spending 3.8s.
The infinite thread server (Loom) should spend 1000 * 100/min(infinity, 50)=2s,
and in this case the number of clients is the limiting factor (50). For once reality
is close to theory, and the server finishes in 2.1s.
These are the type of scenarios where Loom should be very useful.
If your server is spending a lot of time waiting for blocking calls, plugging in Loom to
replace a QueuedThreadPool would give you instants results, without any further need
for configuration.
BONUS: Waiting endpoint (async)
For fun, there's also an async endpoint attached to the servers. It doesn't matter which
server you test this against, as async requests are lifted out of the Jetty's request ThreadPool.
When running our async test we should get results more or less identical to the Loom test:
And we do! The downside here is of course that you have to write your code using async concepts,
so instead of a simple Thread.sleep() you have to create an executor, wrap your result in a
CompletableFuture and schedule the completion of this future on your executor.
Conclusion
Setting up Project Loom is surprisingly easy, but load testing is surprisingly hard.
Loom seems like it could give huge performance gains for virtually no effort, but it's important
to know when it's appropriate to use it. Remember that not all APIs are "Loom friendly",
so consult the OpenJDK Wiki
before getting your hopes up.
If you have any suggestions for improvements or want to expand the test cases and/or load testing sections,
please submit an issue or PR, I would greatly appreciate it.
Trang TopGit này là một snapshot — tab "Readme" hiển thị nguyên văn README của repo (đã bỏ link, giữ ảnh). Repo GitHub ở github.com/tipsy/loomylin là nguồn chính thức.
tipsy/loomylin có bao nhiêu sao?
tipsy/loomylin có 43 sao GitHub — tải lại trang để xem số mới nhất, hoặc xem trực tiếp github.com/tipsy/loomylin. TopGit phản chiếu số sao của GitHub nhưng không cam kết đến từng phút.
tipsy/loomylin có tag gì không?
Bản đồng bộ chưa ghi nhận topic GitHub nào cho tipsy/loomylin. GitHub topics hiển thị ở thanh bên phải trang repo — đó là nơi đáng kiểm tra nhất.
tipsy/loomylin có website riêng không?
TopGit chưa ghi nhận URL trang chủ cho tipsy/loomylin. Phần README ở tab phía trên thường có link demo, hoặc xem mô tả GitHub của repo.
tipsy/loomylin còn đang phát triển không?
Commit gần nhất trên tipsy/loomylin là 4.1 năm trước (theo timestamp GitHub). Repo có 4 fork — một chỉ báo về mức độ quan tâm của cộng đồng.
tipsy/loomylin dùng license gì?
tipsy/loomylin phát hành theo license Apache-2.0. Nên mở file LICENSE trên GitHub để xác nhận — license metadata đôi khi lệch với thực tế dự án.
tipsy/loomylin viết bằng ngôn ngữ gì?
tipsy/loomylin chủ yếu viết bằng Java. Trường "language" của GitHub dựa trên phần lớn byte ở nhánh mặc định.
Đọc đầy đủ README ở tab phía trên.
Muốn nghe thêm một ý kiến về loomylin?
Hỏi một AI đọc được trang này — một cú bấm là có ngay nhận định về loomylin.