Java Multi-core CPU multithreading running efficiency analysis __java

Source: Internet
Author: User
Tags cpu usage

The more efficient Java threads have always been, and then know the efficiency of execution and CPU core number, today we tried the multi-core CPU under multithreading calculation:

This machine i5 four cores, opens 1, 4, 10, 20, 40, 100, 400 threads to do 100W times respectively, the result is as follows:

All tasks completed, total time consuming: 38368ms,threadsize:1,section:1000000
All Tasks completed, total time consuming: 17293ms,threadsize:4,section:250000
All tasks completed, total time consuming: 15107ms,threadsize:10,section:100000
All Tasks completed, total time consuming: 15019ms,threadsize:20,section:50000
All tasks completed, total time consuming: 16115ms,threadsize:40,section:25000
All Tasks completed, total time consuming: 22014ms,threadsize:100,section:10000
All tasks completed, total time consuming: 40431ms,threadsize:400,section:2500

Threadsize is the number of concurrent threads, and the section is the MD5 of each thread.

The number of threads is most efficient between 10-20


CPU Usage:

Single Thread:


4 Threads:


10 Threads:


20 Threads:


40 Threads:


100 Threads:


400 Threads:


As shown in the figure:

1. Single threaded processes can also lead to a rise in the usage of multiple CPUs, supposedly because a single thread is crowding out the CPU resources of other processes on the system, causing these system processes to increase overhead on other CPUs.

2. In 10-20 threads, the CPU's rise is smooth and stable, and hundreds of threads, CPU usage fluctuations are relatively large, may be the frequent task scheduling caused.


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.