成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

影響Java NIO框架性能的因數

開發 后端
最近打算用kilim做一個rpc框架, kilim有自己的nio框架而在業界有強勁的netty和mina。

最近打算用kilim做一個rpc框架, kilim有自己的nio框架 而在業界有強勁的netty和mina。

所以問了一下kilim的作者,他的回答說 因為底層用的都是java nio的api,所以留給nio框架最主要的問題是這2點:

(i) 為了處理很多socket連接和優化吞吐量,會導致了大量的線程切換。

Amount of thread switching done to handle n numbers of sockets and optimizing for throughput.

(ii) 有很多次的selector的中斷和調用,喚醒seletor是很費資源的操作。

所以能做的優化有以下幾點:

1、對read writer process操作分別作輕量級的scheduler,基于actor。

2、有個trick,就是read或者write操作時候,但沒有讀滿或者寫完的情況下,并不是立即返回并再次注冊channel到selector,而是再嘗試若干次(3次),再返回并注冊到selector。在mina中也有同樣的處理。不同之處在于kilim會yield的當前task,而mina為了避免線程切換,只是做了簡單的while循環。但目的都是減少線程切換和避免多次注冊 selector。

mina 處理代碼

  1. for (int i = WRITE_SPIN_COUNT; i > 0; i --)  
  2. {  
  3. localWrittenBytes = ch.write(buf.buf());  
  4. if (localWrittenBytes != 0 || !buf.hasRemaining())  
  5. {  
  6. break;  
  7. }  

kilim nio的處理

  1. while (remaining > 0)  
  2. {  
  3. if (n == 0)  
  4. {  
  5. yieldCount++;  
  6. if (yieldCount < YIELD_COUNT)  
  7. {  
  8. Task.yield(); // don't go back to selector yet.  
  9. else  
  10. {  
  11. pauseUntilWritable();  
  12. yieldCount = 0;  
  13. }  
  14. }  
  15. n = ch.write(buf);  
  16. remaining -= n;  

除了上面說的2個因素以外,還有有哪些因素會影響nio的性能?

原文如下:

I have not tested netty, but here's my experience. All NIO frameworks, Kilim included, are comparable because they use the same underlying NIO API. The difference in performance _may_ stem from the following two sources:

(i) Amount of thread switching done to handle n numbers of sockets and optimizing for throughput.

(ii) Number of times the selector is interrupted and invoked. Waking up the selector is an expensive operation.

The first one is entirely up to the user of the Kilim NIO library. A typical server request consists of one or more reads to accumulate the frame, processing the packet, and one or more writes to write a packet to the socket. One can split up this work between multiple schedulers if you wish. By default, all reading and writing is done outside of the selector's thread. Which brings me to the next point.

I have optimized the access to the selector, by avoiding using it as much as possible. If a socket read or write is unable to transfer any bytes, then the task simply yields. Other runnable tasks get a chance to run. When the task is subsequently resumed, it retries the operation. This goes on for a fixed number of times (3), and if it still fails, it sends a message to the selector thread to wake it up whenever the socket is ready. See the comments on kilim.nio.EndPoint.

Please keep us posted about your netty experiments.

原文地址:http://wangscu.iteye.com/blog/664688

【編輯推薦】

  1. java.nio.Buffer的一些基礎知識的備忘
  2. Java與Cobol對決:Cobol軟件質量最過硬
  3. 甲骨文Java專利遭拒 起訴Android侵權受挫
  4. Java企業應用問題代碼最多
  5. 微軟警告稱Java乃入侵目標之首
責任編輯:林師授 來源: wang_scu的博客
相關推薦

2011-12-15 09:55:47

javanio

2015-06-19 12:17:49

JAVA性能影響

2014-02-11 14:36:14

UPS

2011-03-11 09:51:47

Java NIO

2023-07-12 08:24:19

Java NIO通道

2015-06-26 09:27:14

Java調用性能

2011-12-15 13:28:57

2022-11-17 08:00:18

JavaScript錯誤性能

2019-05-17 09:05:54

MySQL查詢性能數據庫

2022-12-15 08:00:38

JavaScript錯誤性能

2011-12-23 11:33:25

JavaGrizzly

2009-11-30 09:40:23

Java 7 NIO2HTTP Server

2013-07-25 14:56:37

JavaEE 性能

2011-08-31 10:54:25

Java性能

2013-06-21 14:36:02

JavaEEx性能

2013-06-28 09:45:58

vSphere虛擬機

2012-05-07 08:18:42

程序日志性能

2021-06-28 17:21:49

MySQL性能Java

2011-12-07 16:12:29

JavaNIO

2011-04-15 10:26:38

JavaMVC
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 欧美在线一区视频 | www在线视频 | 999精品网 | 91手机精品视频 | 国产真实精品久久二三区 | 午夜精品久久久久久久 | 国产综合久久 | 国产欧美精品在线观看 | 日韩亚洲视频在线 | 日本精品一区二区三区视频 | 免费一级欧美在线观看视频 | 在线免费观看一区二区 | 成人一区二区视频 | 97免费在线观看视频 | 欧美日韩国产一区二区三区 | 日韩成人在线播放 | 欧洲在线视频 | 黄片毛片在线观看 | 亚洲福利网 | 自拍偷拍第一页 | 成人在线免费 | 一区二区三区国产好的精 | 婷婷激情五月网 | 黄色成人免费看 | 日日爱av | 日韩在线免费视频 | 精品久久久久久久久久久久 | 欧美成人激情 | 成人黄色电影在线观看 | 欧美色综合一区二区三区 | 99精品免费视频 | 久草视频在 | 本道综合精品 | 在线免费观看黄a | 亚洲国产成人精品久久久国产成人一区 | 超级乱淫av片免费播放 | 欧美一区二区三区视频在线播放 | 365夜爽爽欧美性午夜免费视频 | 一级黄色淫片 | 成人激情视频免费观看 | 国产毛片久久久 |