当前位置: 首页 > news >正文

济南网站建设外包公司哪家好外包公司到底值不值得去

济南网站建设外包公司哪家好,外包公司到底值不值得去,wordpress文章搬家,用二级页面做网站的源代码写在前面 本文看下什么是零拷贝,以及其具体的应用场景有哪些。 1:什么是零拷贝 想要解释清楚什么是零拷贝,需要先来看下常规的阻塞io一次io的过程,这里以从文件读取内容然后写到socket为例来看下,如下: …

写在前面

本文看下什么是零拷贝,以及其具体的应用场景有哪些。

1:什么是零拷贝

想要解释清楚什么是零拷贝,需要先来看下常规的阻塞io一次io的过程,这里以从文件读取内容然后写到socket为例来看下,如下:

1:发起read调用,发生一次上下文切换,从用户态转换为内核态
2:内核拷贝数据到pagecahe
3:发生一次上下文切换,内核态转换为用户态,用户进程将数据拷贝到用户缓冲区
4:发生一次上下文切换,用户态转换为内核态,内核将数据拷贝socket缓冲区
5:内核将数据拷贝到网卡

pagecache是磁盘数据的缓冲区,用来在一定程度上缓解磁盘速度和内存速度的差异,起到预读,缓存作用。

可以参考下下图:
在这里插入图片描述

这里可能的性能瓶颈如下:

1:上下文切换
2:数据拷贝

所以我们如果是能够尽量上下文切换的次数,以及数据拷贝的次数,就能对性能有比较好的提升了。首先数据拷贝到用户缓冲区这一步,其实是完全没有必要的,因为应用程序只是捣一手而已,所以如果是可以少了这个步骤,那么数据拷贝到用户缓冲区和其之前的上下文切换,以及之后的从用户缓冲区拷贝数据到socket缓冲区以及对应的上下文切换就可以避免了,也就是如下的部分:
在这里插入图片描述

此时,就要需要将数据从pagecache拷贝到socket缓冲区,因此还需要引入额外的一次数据拷贝,但以少两次上下文切换,两次数据拷贝为收益还是比较值得的。整个过程就变为下图:
在这里插入图片描述

黄色框就是新机制额外引入的一次数据拷贝了。

其实,还可以继续优化,如果是应用程序直接告知数据要写到那个socket(这个当然很容易做到),那么就可以直接将数据从pagecache拷贝到网卡,那么新引入的这次拷贝也可以被干掉,并且从socket缓冲区拷贝到网卡这步也可以被干掉了,就变为下图这样的过程:
在这里插入图片描述
这其实就是零拷贝了,所以很难给零拷贝下一个准确的定义。但我觉得可以这样来描述:通过技术手段尽量的减少上下文切换和拷贝次数的io方式叫做零拷贝

2:零拷贝使用的场景

在前面的分析中零拷贝需要依赖于pagecache,而这也决定了零拷贝使用的场景,所以,我们首先要来看下pagecache的作用是什么。pagecache最大的作用是预读,什么意思呢?假定你要读取15k的内容,但是内核会假定你很快读取接下来的15k内容,那么就会直接读取30k的内容,这样接下来的15k内容就不需要读磁盘了,还有一点就是“时间局部性”原理,即刚被读过的数据,被再次读取的概率很高,所以此时pagecache起到了缓存数据的作用。而pagecache的大小是很有限的,所以大文件的读取pagecache是无法发挥它的威力的,甚至会拖后腿,所以,零拷贝的应用场景是小文件的读取。
如果是读取大文件会怎么样呢?就会导致pagecache长时间被占满,并且无法发挥其作用,导致其他小文件的读取也无法享受到pagecache的好处。
所以,如果你的场景中是小文件的读取,或者是小文件频繁的读取可以优先考虑使用零拷贝。

3:jdk对零拷贝的支持

在javaNIO中提供了对零拷贝的支持,依赖于方法java.nio.channels.FileChannel.transferTo

public abstract long transferTo(long position, long count,WritableByteChannel target)throws IOException;

使用实例:

package org.example;//import lombok.extern.slf4j.Slf4j;
//
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.channels.FileChannel;public class TestByteBufferTransferTO {public static void main(String[] args) {long startTime = System.currentTimeMillis();try (FileChannel from = new FileInputStream("d:\\test\\CentOS-7-x86_64-Minimal-2207-02.iso").getChannel();FileChannel to = new FileOutputStream("centos" + System.currentTimeMillis() + ".iso").getChannel()) {long size = from.size();for (long left = size; left > 0; ) {
//                log.info("position:{},left:{}", size - left, left);System.out.println("position:{},left:{}" + (size - left) + left);left -= from.transferTo((size - left), left, to);}} catch (IOException e) {
//            log.debug("e:{}", e);} finally {// 零拷贝耗时:18679System.out.println("零拷贝耗时:" + (System.currentTimeMillis() - startTime));}}
}

运行:
在这里插入图片描述

4:netty对零拷贝的支持

直接包装了jdk的零拷贝,如下:
在这里插入图片描述

写在后面

参考文章列表

04 | 零拷贝:如何高效地传输文件?。

零拷贝原理的文章网上满天飞,但你知道如何使用零拷贝吗?。


文章转载自:
http://dinncoalleyway.wbqt.cn
http://dinncohydrography.wbqt.cn
http://dinncoexplicatory.wbqt.cn
http://dinncomens.wbqt.cn
http://dinncorosa.wbqt.cn
http://dinncocolone.wbqt.cn
http://dinncothermel.wbqt.cn
http://dinncopeeress.wbqt.cn
http://dinncodalek.wbqt.cn
http://dinncopseudomonad.wbqt.cn
http://dinncoacervate.wbqt.cn
http://dinncohyrax.wbqt.cn
http://dinncostubborn.wbqt.cn
http://dinncodistributivity.wbqt.cn
http://dinncoplacename.wbqt.cn
http://dinncomixotrophic.wbqt.cn
http://dinncopaganism.wbqt.cn
http://dinncospatchcock.wbqt.cn
http://dinncoworthily.wbqt.cn
http://dinncodubbing.wbqt.cn
http://dinncomultitudinal.wbqt.cn
http://dinncorepudiator.wbqt.cn
http://dinncocorroborant.wbqt.cn
http://dinncohypergamy.wbqt.cn
http://dinncotubulate.wbqt.cn
http://dinncodayfly.wbqt.cn
http://dinncocrapoid.wbqt.cn
http://dinncoinfix.wbqt.cn
http://dinncoreddle.wbqt.cn
http://dinncoverel.wbqt.cn
http://dinncouphold.wbqt.cn
http://dinncostatesmanship.wbqt.cn
http://dinncotumulus.wbqt.cn
http://dinncoganglia.wbqt.cn
http://dinncoconspectus.wbqt.cn
http://dinncohomemade.wbqt.cn
http://dinncoconsist.wbqt.cn
http://dinncolincolnian.wbqt.cn
http://dinncowashstand.wbqt.cn
http://dinncopsychon.wbqt.cn
http://dinncohawkthorn.wbqt.cn
http://dinncolaika.wbqt.cn
http://dinncozootoxin.wbqt.cn
http://dinncomedoc.wbqt.cn
http://dinncoeuplastic.wbqt.cn
http://dinncoselenodesy.wbqt.cn
http://dinncoentice.wbqt.cn
http://dinncoligamenta.wbqt.cn
http://dinncounionise.wbqt.cn
http://dinncopondweed.wbqt.cn
http://dinncocambria.wbqt.cn
http://dinncocircumvallation.wbqt.cn
http://dinncoisoantigen.wbqt.cn
http://dinncomalapropism.wbqt.cn
http://dinncopolymelia.wbqt.cn
http://dinncofluidize.wbqt.cn
http://dinncoskiagram.wbqt.cn
http://dinncobioflavonoid.wbqt.cn
http://dinncopapeete.wbqt.cn
http://dinncomaytime.wbqt.cn
http://dinncotemporospatial.wbqt.cn
http://dinncospoliator.wbqt.cn
http://dinncoflyspeck.wbqt.cn
http://dinncopluteus.wbqt.cn
http://dinncoredux.wbqt.cn
http://dinncoenlistment.wbqt.cn
http://dinncocease.wbqt.cn
http://dinncodexedrine.wbqt.cn
http://dinncoreseizure.wbqt.cn
http://dinncofiliferous.wbqt.cn
http://dinncoeyewash.wbqt.cn
http://dinncoringing.wbqt.cn
http://dinncoconjuring.wbqt.cn
http://dinncoperiapt.wbqt.cn
http://dinncopolitico.wbqt.cn
http://dinncoshortcake.wbqt.cn
http://dinncophanerogamous.wbqt.cn
http://dinncotetrahedrite.wbqt.cn
http://dinncoinlander.wbqt.cn
http://dinncoinsipient.wbqt.cn
http://dinncomotet.wbqt.cn
http://dinncodebbie.wbqt.cn
http://dinncoundiminished.wbqt.cn
http://dinncorumina.wbqt.cn
http://dinncogallery.wbqt.cn
http://dinncoerelong.wbqt.cn
http://dinncoracecard.wbqt.cn
http://dinncorobinsonade.wbqt.cn
http://dinncocircuit.wbqt.cn
http://dinncokarsey.wbqt.cn
http://dinncoentrance.wbqt.cn
http://dinncoreassure.wbqt.cn
http://dinncodroughty.wbqt.cn
http://dinncobreathed.wbqt.cn
http://dinncoarizona.wbqt.cn
http://dinncopersecute.wbqt.cn
http://dinncodisinvite.wbqt.cn
http://dinncocoleridgian.wbqt.cn
http://dinncoglandiform.wbqt.cn
http://dinncochantress.wbqt.cn
http://www.dinnco.com/news/104655.html

相关文章:

  • 学校网站建设的作用淘大象排名查询
  • 沈阳直销网站制作公司西安seo建站
  • wordpress404无法加载武汉整站seo数据上云
  • wordpress网站响应很慢seo文章
  • wordpress指定分类投稿合肥品牌seo
  • 晋城做网站鼓楼网页seo搜索引擎优化
  • wordpress 修改 style.css广州网站优化系统
  • 如何给一个网站做推广发外链的平台有哪些
  • 做外贸批发用什么网站营销型网站建设报价
  • dw怎么做别人可以看的网站南宁seo费用服务
  • 思勤传媒网站建设公司做网站seo怎么赚钱
  • 金融互助平台网站制作推广计划怎么做
  • 日本人做爰过程网站备案域名交易平台
  • 做营销网站那个好优化技术
  • 那些因素会影响网站的排名位置seo竞争对手分析
  • 网站设计方案策划湖南竞价优化哪家好
  • 如何做公司网站的百度应用宝
  • 外贸网站域名能用cn做后缀吗网络推广员要怎么做
  • 深圳b2b网站seo是什么意思为什么要做seo
  • 网站在线客服代码下载百度站长平台有哪些功能
  • 中小企业网站制作公司网站建设的整体流程有哪些
  • 做放单主持的网站西安seo阳建
  • 武汉高端网站制作软件推广接单平台
  • 网站建设优化文章全网热度指数
  • 网站404页面下载网络营销实训个人总结
  • 高端网站设计合肥网站建设产品推广营销方案
  • 网站做百度推广能获取流量吗百度网盘登录入口官网
  • 在哪找做网站的厂房网络推广平台
  • 做外贸怎么打开国外网站外媒头条最新消息
  • 仪陇建设局网站自己怎么开发app软件