Java Thread CPU Affinity tool __java

Source: Internet
Author: User
Thread Affinity Why thread CPU affinity is required

Applications are executed in a multi-threaded manner, most of which can be reasonably scheduled. In some cases, however, an important thread is paused, and the time slice is assigned to an irrelevant thread. When a thread is paused for hibernation each time and is awakened, the cache line (CPU L1/L2 cache) needs to be reloaded. When a thread's working time is short and needs to be awakened frequently, it means that the entire process is slow and may be 2-5 times slower than a single thread.

Some of the threads applied may need to be performed all the time and not hibernate because of CPU scheduling, which requires the thread to be executed on a single CPU.

Https://github.com/OpenHFT/Java-Thread-Affinity implements the bind thread to the CPU, for example: Thread x must use a physical CPU, Threads y and Z use different logical CPUs of the same physical CPU (CPU Hyper-Threading technology). This code identifies the individual CPU and binds the thread to the appropriate CPU based on the rules provided by the developer. This tool is able to identify a separate CPU, based on the principle of optimal effect, to allocate threads to the CPU according to the rules provided. Even without the core of independence can do the best. principle

This tool reads/proc/cpuinfo/to determine the layout of the CPU. If this file is not found, one slot per CPU is considered.
By default, independent CPUs are queried only on unused CPUs. For example, with a total of 16 CPUs, 8 are not normally used (as determined by the thread affinity set at startup), then Java-thread-affinity will use these CPUs. Attention

If multiple processes use this library, you need to specify the CPU for a process, otherwise the processes will share the CPU. Adding-daffinity.reserved={cpu-mark-in-hex} at the command line allows you to specify which CPU the process uses to resolve the problem. PS

This article mentions the time loss of context switching: The reason for the http://ifeve.com/java-context-switch/ thread switch 1, after the current time slice of the task is run out, the system CPU normally dispatches the next task. 2, the current task encountered IO blocking, the scheduler will suspend this task, continue the next task 3, multiple tasks preemption lock resources, the current task did not grab, the scheduler hangs, continue the next task 4, user code suspend the current task, give up the CPU time 5, interrupted. Hardware interrupts: Peripherals send electrical signals to the processor, asynchronous, IRQ (interrupt request), soft interrupts: Exception conditions or special instruction sets, soft interrupts can be used to implement system call.

Context switching involves: saving and loading registers and memory maps, updating various tables and lists etc.

A context switch can mean aregister the context switch, the atask context switch, the astack frame switch, athread context switch, or A process context switch. (representation: Between processes, between threads, between stack frames)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.