question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Refactor usage of concurrency with reactor

See original GitHub issue

Terasology does not use or promote a consistent feature set or technologies for handling concurrency.

In some situations the number of threads are over-provisioned, and in some cases its under-provisioned. Some workloads might benefit from more threads but selectively changing the number of threads by hand will lead to over-provisioning on some systems and under-provisioning on another system.

Poor utilization of threads will end up with situations where the kernel is switching between different tasks. If every thread is a CPU bound task then the processor will spend a lot of time context switching between the different tasks.

We propose dropping ThreadManagerSubsystem and use the functionality provided by Project Reactor.

Currently, TaskMaster is used to push tasks to an off thread where the use case of TaskMaster is probably not needed and the spawned thread is mostly unused.

Current situation

  • Chunk-Unloader (allocate 4 threads)

    • int list to queue event for BeforeDeactivateBlocks
    • very light load so threads are mostly idle
    • at any moment a single thread will become active
  • Chunk-Updater (allocates 8 threads)

    • generates chunk mesh and queue them back on the main thread
  • LOD Chunk Generation

  • only triggered for handling different levels of lod

  • ThreadManagerSubsystem (allocates 16 threads) only used for a couple situations and the fixed number of threads does not properly utilize the number of cores. and hardly used so all these threads are idle.

    • loadingGame
    • create new world
    • saving screenshot
  • TaskMaster

    • Behaviors (1 thread)
    • FlexiablePathFinding (4 threads)
    • Pathfinding (1 thread)

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:14 (14 by maintainers)

github_iconTop GitHub Comments

1reaction
keturncommented, Jul 27, 2021

Reactor explicitly has built-in integration with micrometer, which makes for a good default answer to which of the metrics implementations in #4637 we should use.

1reaction
pollendcommented, Jul 19, 2021

some main problems with RXJava. There is a table of mappings that define a flowable, Observable, Single, Maybe, and Completable and mappings from one to the other. 0…N defined for Floablw and Observable but only flowable has backpressure. Single is one element only but Maybe is 0 or 1. Completable is 0 element or error. there are different methods to map one type to another. the inconsistent API is difficult to follow. The mappings make this pretty confusing where reactor has Flux and Mono. Flux is 0…N and mono is just a single object. I like this a lot better then the former.

While working with Flowable I managed to get into a situation where objects getting pushed to my Flowable were not getting handled by the subscriber where this pattern seems to be more reliable with reactor. I was looking at this benchmark comparing the two and found the reactor implementation is quite a bit faster: https://github.com/MovingBlocks/Terasology/pull/4786

https://github.com/akarnokd/akarnokd-misc/issues/7

Read more comments on GitHub >

github_iconTop Results From Across the Web

Refactoring from imperative to reactive implementation
Ideally Spring Boot should automatically configure Reactor Netty as default server if we are using Webflux. Since it was not getting configured ...
Read more >
Concurrency in Spring WebFlux - Baeldung
This indicates that Reactor Kafka manages its own thread pool, with a few worker threads that participate in Kafka message processing ...
Read more >
Refactoring to Reactive - Anatomy of a JDBC migration - InfoQ
Build a more resilient application, allowing our server to sustain a greater number of concurrent users than the actual number of available ...
Read more >
Java Reactive Programming - Effective Usage in a Real World ...
We used the reactive KafkaReceiver from the reactor.kafka package and ... by a runOn(scheduler) to introduce concurrent processing here.
Read more >
Refactoring Sequential Java Code for Concurrency via ...
AtomicInteger in java.util.concurrent. Lock-free programming on single integer variable. Update operations execute atomically. Uses efficient machine-level ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found