java吞吐,Java线程池吞吐量

I am observing a very strange problem in a java client server application. I am sending following Runnable objects to the server at 80 requests per second. The thread pool keeps pool size equal to the request rate i.e. approximately 80 threads in the pool. My laptop is intel Core i5-3230M dual core(Windows show me 4 processor). Strange thing is that the Throughput(jos completed per second) is also 80. I could not understand this. How 4 processors and 80 threads are completing 80 jobs of 100 milliseconds in one second ? That is:

Processors=4

Request rate=80

Thread pool size=80

Each job service time=100milliseconds.

Throughput=80 How?

I was expecting throughput=40 because each processor should approximately complete 10 jobs in 1 second so 4 processors should give throughput=40 but it is 80 ? Laptop specification link says

Also, the cores can handle up to four simultaneous threads, which

improves the performance and resource-utilization of the CPU.

Does this means 8 threads can run at the same time b 2 cores?

public class CpuBoundJob implements Runnable {

public void run() {

long startTime = System.nanoTime();

while ((System.nanoTime() - startTime) < (100)*1000000L) {}

}

}

解决方案

You have written tasks which run for a fixed amount of time, not a fix amount of work. This means they should always complete at a fixed rate regardless of the number of CPUs you have. You could just have them sleep for 100 ms.

How 4 processors and 80 threads are completing 80 jobs of 100 milliseconds in one second ?

Your computer is running far more threads than you have processes all the time. The OS uses scheduling to stop and start running thread (faster than you can see) to give the illusion they all running at once but they are not and cannot (never could if you think about it)

Also, the cores can handle up to four simultaneous threads, which improves the performance and resource-utilization of the CPU.

Its means it's two cores have hyper threading allowing the processor to running up to four threads without context switching (as mentioned above)

Does this means 8 threads can run at the same time b 2 cores?

The i5 mentioned has 2 cores it supports 4 threads as it states.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Java吞吐量上不去可能有多种原因,下面我列举了一些常见的原因和解决方法: 1. 硬件资源不足:如果你的服务器硬件配置较低,可能无法支持高吞吐量的需求。可以考虑升级硬件或者增加服务器数量来提高吞吐量。 2. 线程竞争:Java中的线程竞争可能导致吞吐量下降。可以通过优化线程池的大小、调整线程优先级、减少锁的使用等方式来减少线程竞争,提高吞吐量。 3. 内存管理:如果Java应用程序的内存使用不合理,可能会导致频繁的垃圾回收,从而影响吞吐量。可以通过调整堆内存大小、优化对象的创建和销毁、使用对象池等方式来改善内存管理,提高吞吐量。 4. 数据库访问:如果Java应用程序频繁地进行数据库访问,可能会成为性能瓶颈。可以通过优化数据库查询语句、增加缓存机制、使用批量操作等方式来提高数据库访问性能,从而提高吞吐量。 5. 网络通信:如果Java应用程序涉及网络通信,网络延迟和带宽限制可能会影响吞吐量。可以通过优化网络通信协议、增加并发连接数、使用异步IO等方式来提高网络通信性能,从而提高吞吐量。 6. 代码优化:对Java应用程序的代码进行优化也是提高吞吐量的一种方式。可以通过使用高效的算法和数据结构、减少不必要的计算、避免频繁的IO操作等方式来优化代码,提高吞吐量。 以上是一些常见的原因和解决方法,具体的解决方案需要根据具体情况进行分析和调整。如果你能提供更多关于你的应用程序和环境的信息,我可以给出更具体的建议。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值