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

影響Java NIO框架性能的因數(shù)

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

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

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

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

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

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

所以能做的優(yōu)化有以下幾點:

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

2、有個trick,就是read或者write操作時候,但沒有讀滿或者寫完的情況下,并不是立即返回并再次注冊channel到selector,而是再嘗試若干次(3次),再返回并注冊到selector。在mina中也有同樣的處理。不同之處在于kilim會yield的當前task,而mina為了避免線程切換,只是做了簡單的while循環(huán)。但目的都是減少線程切換和避免多次注冊 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的一些基礎(chǔ)知識的備忘
  2. Java與Cobol對決:Cobol軟件質(zhì)量最過硬
  3. 甲骨文Java專利遭拒 起訴Android侵權(quán)受挫
  4. Java企業(yè)應(yīng)用問題代碼最多
  5. 微軟警告稱Java乃入侵目標之首
責任編輯:林師授 來源: wang_scu的博客
相關(guān)推薦

2011-12-15 09:55:47

javanio

2015-06-19 12:17:49

JAVA性能影響

2014-02-11 14:36:14

UPS

2023-07-12 08:24:19

Java NIO通道

2011-03-11 09:51:47

Java NIO

2015-06-26 09:27:14

Java調(diào)用性能

2011-12-15 13:28:57

2019-05-17 09:05:54

MySQL查詢性能數(shù)據(jù)庫

2022-12-15 08:00:38

JavaScript錯誤性能

2011-12-23 11:33:25

JavaGrizzly

2022-11-17 08:00:18

JavaScript錯誤性能

2009-11-30 09:40:23

Java 7 NIO2HTTP Server

2011-08-31 10:54:25

Java性能

2013-06-21 14:36:02

JavaEEx性能

2013-07-25 14:56:37

JavaEE 性能

2012-05-07 08:18:42

程序日志性能

2021-06-28 17:21:49

MySQL性能Java

2011-12-07 16:12:29

JavaNIO

2013-06-28 09:45:58

vSphere虛擬機

2011-04-15 10:26:38

JavaMVC
點贊
收藏

51CTO技術(shù)棧公眾號

主站蜘蛛池模板: 男人影音 | 中文字幕人成乱码在线观看 | 久久久久久久久久久久久9999 | 欧美精品乱码99久久影院 | h片在线免费观看 | 国产二区三区 | 午夜影院在线视频 | 美女高潮网站 | 免费黄色成人 | 蜜桃视频在线观看免费视频网站www | 国产日韩精品一区二区三区 | 国产高清在线精品一区二区三区 | 天天爱天天操 | 九九免费视频 | 伦理二区 | 自拍偷拍亚洲欧美 | 成人a在线观看 | 成人免费视频在线观看 | 一级全黄视频 | 黄色片免费在线观看 | 黄色免费av| 中文字幕在线看 | 自拍偷拍第一页 | 我我色综合 | 国产一区二区三区四区在线观看 | 黄色片视频网站 | 在线免费观看日本视频 | 激情六月天 | 国产精品久久久久一区二区三区 | 91在线视频观看免费 | 日韩在线一区二区三区 | 亚洲一区二区三区高清 | 欧美福利在线 | 久久成人国产精品 | 久久精品福利 | 中文字幕在线免费 | 久久一级大片 | 国产精品美女www爽爽爽 | 91精品国模一区二区三区 | 亚洲成年影院 | 免费一区二区 |