GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Java-Interview-Advanced/docs/03/108.md at master · leelovejava/Java-Interview-Advanced

Expand file tree

/

108.md

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
29 lines (9 loc) · 1.21 KB
/

108.md

Copy path

File metadata and controls

29 lines (9 loc) · 1.21 KB
Raw
Copy raw file
Download raw file
Edit and raw actions

108、零拷贝技术到底是什么,他是如何提升IO性能的?

零拷贝原理

linux提供了sendfile,也就是零拷贝技术

在你的代码里面,如果说你基于零拷贝技术来读取磁盘文件,同时把读取到的数据通过Socket发送出去的话,流程如下,Kafka源码,transferFrom和transferTo两个方法,从磁盘上读取文件,把数据通过网络发送出去

这个零拷贝技术,就是先从用户态切换到内核态,在内核态的状态下,把磁盘上的数据拷贝到内核缓冲区,同时从内核缓冲区拷贝一些offset和length到Socket缓冲区;接着从内核态切换到用户态,从内核缓冲区直接把数据拷贝到网络协议引擎里去

同时从Socket缓冲区里拷贝一些offset和length到网络协议引擎里去,但是这个offset和length的量很少,几乎可以忽略

只要2次切换,2次拷贝,就可以了

kafka、tomcat,都是用的零拷贝技术,rocketmq用的是mmap技术,mmap还是要多2次切换和1次拷贝的,在Java代码中如何进行mmap和零拷贝,大家可以去看一看网上的一些资料

用户态和内核态,用户态空间,内核态空间

You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.