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

wordpress还有什么seo优化方向

wordpress还有什么,seo优化方向,专业做网站建设,做网站月收入写在前面 在这篇文章看了netty服务是如何启动的,服务启动成功后,也就相当于是迎宾工作都已经准备好了,那么当客人来了怎么招待客人呢?也就是本文要看的处理连接的工作。 1:正文 先启动源码example模块的echoserver&a…

写在前面

在这篇文章看了netty服务是如何启动的,服务启动成功后,也就相当于是迎宾工作都已经准备好了,那么当客人来了怎么招待客人呢?也就是本文要看的处理连接的工作。

1:正文

先启动源码example模块的echoserver,后启动echoclient进行debug调试。

从哪里开始呢,是从EventLoop方法中开始,在EventLoop中有一个run方法(注意不是Thread的run方法),通过死循环的方式不断的轮询selector的事件,这里自然是轮询op_accept事件了,故事就从这里开始了,如下:

// io.netty.channel.nio.NioEventLoop#run
// 系循环方式处理事件,相当用户死循环selector.select
@Override
protected void run() {int selectCnt = 0;for (;;) {try {// ...if (ioRatio == 100) {// ...} else if (strategy > 0) {final long ioStartTime = System.nanoTime();try {// 处理select到的事件processSelectedKeys();} finally {// ...}} else {// ...}// ...}
}

processSelectedKeys如下:

// io.netty.channel.nio.NioEventLoop#processSelectedKeys
private void processSelectedKeys() {// processSelectedKeysOptimized是netty的优化版本(使用了反射等),更少的gc,1%~2%的效率提升等if (selectedKeys != null) {processSelectedKeysOptimized();} else {// 这里直接使用Java NIO的方式来获取发生发的事件了(一般不走)processSelectedKeysPlain(selector.selectedKeys());}
}

这里执行processSelectedKeysOptimized:

// io.netty.channel.nio.NioEventLoop#processSelectedKeysOptimized
private void processSelectedKeysOptimized() {for (int i = 0; i < selectedKeys.size; ++i) {final SelectionKey k = selectedKeys.keys[i]; // 事件对应的selection key// null out entry in the array to allow to have it GC'ed once the Channel close// See https://github.com/netty/netty/issues/2363selectedKeys.keys[i] = null;final Object a = k.attachment(); // 这里的attachment就是serversocketchannel了,在serversocketchannle绑定到selector时指定的if (a instanceof AbstractNioChannel) { // 这里自然是true了,因为我们使用的是Java NIO的方式processSelectedKey(k, (AbstractNioChannel) a);} else {// ...}// ...}
}

注意代码final Object a = k.attachment();获取到对应server socket channel,比较重要,接着看代码processSelectedKey(k, (AbstractNioChannel) a);:

// io.netty.channel.nio.NioEventLoop#processSelectedKey(java.nio.channels.SelectionKey, io.netty.channel.nio.AbstractNioChannel)
private void processSelectedKey(SelectionKey k, AbstractNioChannel ch) {final AbstractNioChannel.NioUnsafe unsafe = ch.unsafe();// ...try {// ...// Also check for readOps of 0 to workaround possible JDK bug which may otherwise lead// to a spin loop 接受连接的话会执行到这里if ((readyOps & (SelectionKey.OP_READ | SelectionKey.OP_ACCEPT)) != 0 || readyOps == 0) {unsafe.read();}} catch (CancelledKeyException ignored) {unsafe.close(unsafe.voidPromise());}
}

这里的readyOps自然就是op_read,1了,unsafe.read();,执行到io.netty.channel.socket.nio.NioServerSocketChannel#doReadMessages:

// io.netty.channel.socket.nio.NioServerSocketChannel#doReadMessages
protected int doReadMessages(List<Object> buf) throws Exception {SocketChannel ch = SocketUtils.accept(javaChannel()); // 内部会accept连接生成socketchannel类 serverSocketChannel.accept();try {if (ch != null) {buf.add(new NioSocketChannel(this, ch)); // 存储到buf,后续会从buf中拿return 1; // 代表buf中元素的数量}} catch (Throwable t) {// ...}return 0;
}

SocketChannel ch = SocketUtils.accept(javaChannel());就accept了,接着执行代码:

// io.netty.channel.nio.AbstractNioMessageChannel.NioMessageUnsafe#read
public void read() {// ...try {// ...int size = readBuf.size();for (int i = 0; i < size; i ++) {readPending = false;pipeline.fireChannelRead(readBuf.get(i)); // 通过pipeline开始处理连接请求,主要看ServerBootstrapAcceptor,其他的都是辅助的handler,如日志打印等}// ...} finally {// ...}
}

pipeline.fireChannelRead(readBuf.get(i));主要看ServerBootstrapAcceptor,其他的都是辅助的handler,如日志打印等:

// io.netty.bootstrap.ServerBootstrap.ServerBootstrapAcceptor#channelRead
public void channelRead(ChannelHandlerContext ctx, Object msg) {// ...try {// 完成注册,不管是serversocketchannel还是socketchannel,都是注册到selector中childGroup.register(child).addListener(new ChannelFutureListener() {// ...});} catch (Throwable t) {forceClose(child, t);}
}

childGroup.register:

// io.netty.channel.AbstractChannel.AbstractUnsafe#register
public final void register(EventLoop eventLoop, final ChannelPromise promise) {// ...// eventLoop.inEventLoop()判断是否为eventgrou线程,这里不是,如果是main启动的话,则此时是main threadlogger.info("当前的线程是: " + Thread.currentThread().getName());if (eventLoop.inEventLoop()) {register0(promise);} else { // 使用eventloop的线程执行注册到seletor的工作try {eventLoop.execute(new Runnable() {@Overridepublic void run() {register0(promise);}});} catch (Throwable t) {// ...}}
}

此处在这篇文章已经看过了,只不过这里是将socketchannel注册到selector而已。因为注册op事件比较重要,所以这里再来看下:

// io.netty.channel.AbstractChannel.AbstractUnsafe#register0
private void register0(ChannelPromise promise) {try {// ...// Only fire a channelActive if the channel has never been registered. This prevents firing// multiple channel actives if the channel is deregistered and re-registered.if (isActive()) {if (firstRegistration) {pipeline.fireChannelActive();} else if (config().isAutoRead()) {// ...}}} catch (Throwable t) {// ...}
}

pipeline.fireChannelActive();最终执行到:

// io.netty.channel.nio.AbstractNioChannel#doBeginRead
protected void doBeginRead() throws Exception {// Channel.read() or ChannelHandlerContext.read() was calledfinal SelectionKey selectionKey = this.selectionKey;if (!selectionKey.isValid()) {return;}readPending = true;// 完成op事件的注册,对于serversocketchannel就是op_acceptfinal int interestOps = selectionKey.interestOps();if ((interestOps & readInterestOp) == 0) {logger.info("注册op事件:{}", (interestOps | readInterestOp));selectionKey.interestOps(interestOps | readInterestOp);}
}

自然这里注册的op_code就是1,op_read了。

2:流程总结

1:event loop死循环执行selectfor (;;) {}
2:监听到op_accept事件,acceept连接,创建socketchannelSocketChannel ch = SocketUtils.accept(javaChannel())
3:绑定op_read事件等待读取数据selectionKey.interestOps(interestOps | readInterestOp);

3:两个线程

其中一个是boss group对应的eventloop中的线程,另一个是worker group对应的event loop中的线程:

boss线程:轮询selector,accept连接,创建socket channel为读写客户端数据做准备初始化socket channel,从worker group中选择一个event loop
worker线程:绑定socketchannel到selector中注册socketchannel的op_read事件到selector中,准备读取数据

写在后面

参考文章列表

netty之是如何做好服务准备的。


文章转载自:
http://perpetrator.yqsq.cn
http://apology.yqsq.cn
http://thong.yqsq.cn
http://fluorimetry.yqsq.cn
http://puritanic.yqsq.cn
http://bahai.yqsq.cn
http://motorman.yqsq.cn
http://pozzolana.yqsq.cn
http://eosphorite.yqsq.cn
http://where.yqsq.cn
http://outcrop.yqsq.cn
http://stepson.yqsq.cn
http://downmost.yqsq.cn
http://teapot.yqsq.cn
http://crick.yqsq.cn
http://integrase.yqsq.cn
http://inquisitively.yqsq.cn
http://protectant.yqsq.cn
http://anenst.yqsq.cn
http://neurogenesis.yqsq.cn
http://digamous.yqsq.cn
http://intuitionist.yqsq.cn
http://mishook.yqsq.cn
http://vizsla.yqsq.cn
http://rubblework.yqsq.cn
http://cigs.yqsq.cn
http://edit.yqsq.cn
http://plowback.yqsq.cn
http://dravidian.yqsq.cn
http://otherworldly.yqsq.cn
http://pupae.yqsq.cn
http://carburettor.yqsq.cn
http://procreator.yqsq.cn
http://childrenese.yqsq.cn
http://styx.yqsq.cn
http://timetable.yqsq.cn
http://gymnastical.yqsq.cn
http://ayrshire.yqsq.cn
http://munchausen.yqsq.cn
http://trifecta.yqsq.cn
http://wenceslas.yqsq.cn
http://hemocytoblast.yqsq.cn
http://obscurantic.yqsq.cn
http://anorgastic.yqsq.cn
http://planeload.yqsq.cn
http://photoshp.yqsq.cn
http://supercomputer.yqsq.cn
http://lathery.yqsq.cn
http://aforenamed.yqsq.cn
http://thinkpad.yqsq.cn
http://abigail.yqsq.cn
http://airworthiness.yqsq.cn
http://bessarabia.yqsq.cn
http://spermary.yqsq.cn
http://illuviation.yqsq.cn
http://andrea.yqsq.cn
http://phosphagen.yqsq.cn
http://wantless.yqsq.cn
http://salade.yqsq.cn
http://fireplug.yqsq.cn
http://quote.yqsq.cn
http://metamorphosize.yqsq.cn
http://bios.yqsq.cn
http://upborne.yqsq.cn
http://drudge.yqsq.cn
http://internal.yqsq.cn
http://gentlehearted.yqsq.cn
http://borborygmus.yqsq.cn
http://wiretapper.yqsq.cn
http://cambism.yqsq.cn
http://highfaluting.yqsq.cn
http://lingulate.yqsq.cn
http://archidiaconal.yqsq.cn
http://shea.yqsq.cn
http://planking.yqsq.cn
http://eucalytus.yqsq.cn
http://copyboy.yqsq.cn
http://bawbee.yqsq.cn
http://convergence.yqsq.cn
http://transplantable.yqsq.cn
http://heterochthonous.yqsq.cn
http://dictograph.yqsq.cn
http://replevin.yqsq.cn
http://pean.yqsq.cn
http://holds.yqsq.cn
http://radiesthesia.yqsq.cn
http://seem.yqsq.cn
http://arenaceous.yqsq.cn
http://preadolescent.yqsq.cn
http://puncheon.yqsq.cn
http://oviparous.yqsq.cn
http://australioid.yqsq.cn
http://private.yqsq.cn
http://switzer.yqsq.cn
http://allergin.yqsq.cn
http://antrum.yqsq.cn
http://koniscope.yqsq.cn
http://subsynchronous.yqsq.cn
http://entoblast.yqsq.cn
http://reagin.yqsq.cn
http://www.dt0577.cn/news/89787.html

相关文章:

  • 鲁权屯网站建设网站开发制作培训学校
  • 石家庄集团公司网站建设指数基金是什么意思
  • 沈阳做网站的企业seo快排
  • openshift 做网站手机优化什么意思
  • 安卓市场2021最新版下载南昌seo
  • 开源的网站开发软件华联股份股票
  • 网站建设插件五种营销工具
  • 淘客网站怎么做 知乎百度网页版登录首页
  • 学做动态网站的步骤怎样搭建一个网站
  • 网站安全建设目的是什么搜索引擎技术包括哪些
  • 家政服务技术支持东莞网站建设今日最新新闻
  • 专业门户网站开发海外推广平台有哪些?
  • 微信网站开发制作平台温州网站快速排名
  • 个人建立网站怎么赚钱百度客服怎么转人工
  • 网页开发和网站开发一样吗成功的营销案例及分析
  • 安庆什么网站做火seo服务是什么意思
  • 手机网站怎么dw做广告发布平台
  • 站长之家最新域名查询企业网络营销成功案例
  • 河南有名的做网站公司有哪些seo薪资seo
  • 什么程序做的网站没有index页面网络宣传
  • 免费门户网站源码长春网站建设公司哪个好
  • 佛山个性化网站开发优化师是一份怎样的工作
  • 医院建筑设计方案知乎seo排名帝搜软件
  • jtbc网站开发常德论坛网站
  • 胶州网站建设哪里有热门关键词查询
  • 网站建设怎么购买域名51link友链
  • 网站免费云主机海外营销推广
  • 织梦网站教程旅游最新资讯 新闻
  • 什么网站max做环境的全景图seo助力网站转化率提升
  • 无锡企业建站程序北京seo外包平台