Java Threading CPU Affinity tool

Source: Internet
Author: User
Thread affinity why requires CPU affinity of threads

The application is executed in multi-threaded way, most of the time the thread can be reasonably dispatched. In some cases, however, an important thread is paused, and the time slice is assigned to a thread that is not important. When a thread pauses to hibernate and then wakes up, it needs to reload "cache line" (CPU L1/L2 cache). When a thread's working time is short and needs to be woken up frequently, it means that the entire process is slow and can be 2-5 times slower than a single-threaded scenario.

Some threads of the application may need to be executed all the time, not hibernate due to CPU scheduling, which requires the thread to be executed on one CPU at a time.

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

Principle

This tool reads/proc/cpuinfo/to determine the layout of the CPU. If you do not have this file then think of one slot per CPU.
By default, independent CPUs are queried only on unused CPUs. For example, a total of 16 CPUs, 8 of which are usually not used (as determined by the thread affinity set at boot time), then java-thread-affinity will use these CPUs.

Attention

If more than one process uses this library, you need to specify the CPU for a process, otherwise these processes will share the CPU. Add-daffinity.reserved={cpu-mark-in-hex} at the command line to specify which CPU the process uses to resolve the problem.

Ps

This article mentions the time loss of context switching: http://ifeve.com/java-context-switch/

Java Threading CPU Affinity tool

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.