I want to download vs on my pterodactyl server but when i install it the world crashes is there a way to minimize the treads that are create to like 200 ?
Reply chain from #31
This process is called a context switch.
Apparent Concurrency: This switching happens so quickly (often in milliseconds or less) that it appears all threads are running simultaneously to the user, even on a single-core machine.
Why This Is Done
Creating more threads than cores is a standard technique, particularly when threads frequently encounter blocking operations:
Handling I/O Operations: Threads often pause to wait for slow operations like disk I/O, network access, or user input. During this waiting time, the CPU would be idle. The OS scheduler efficiently uses this idle time by switching to a different, ready-to-run thread.
Responsiveness: In applications like web servers, where each connection might be handled by a separate thread, having many threads ensures that while some are waiting for network data, others can continue processing.
Task Management: Programs are often structured with different threads for distinct tasks (e.g., one for GUI, one for background processing), and these threads may not be continuously CPU-bound.
Performance Considerations
While you can create many threads, it’s not always beneficial for performance:
Overhead: Creating and managing a large number of threads comes with overhead, primarily the cost of context switching.
Performance Degradation: If you have too many CPU-bound threads (threads that constantly need the CPU and don’t wait for I/O), the excessive context switching can cause the system to “thrash” and slow down the overall application’s throughput.
Optimal Number: For CPU-intensive tasks, a common recommendation is to use a number of threads equal to the available hardware concurrency (number of cores/logical processors), which can be retrieved using std:
🧵:hardware_concurrency() in C++.
To manage a large number of potential tasks efficiently, developers often use thread pools, which reuse a fixed number of threads instead of constantly creating and destroying new ones.
This conversation is on Discord · Reply there