Netty核心源码分析(二),Netty的Server端接收请求过程源码分析

news2024/9/24 12:21:56

文章目录

  • 系列文章目录
  • 一、连接请求接受过程源码分析
    • 1、事件的值
    • 2、processSelectedKeys获取事件
      • (1)doReadMessages方法
      • (2)pipeline的fireChannelRead方法
      • (3)ServerBootstrapAcceptor的channelRead方法
    • 3、workerGroup的register过程
    • 4、beginRead方法
    • 5、Netty接受请求过程源码小结

系列文章目录

Netty核心源码分析(一),Netty的Server端启动过程源码分析
Netty核心源码分析(二),Netty的Server端接收请求过程源码分析

一、连接请求接受过程源码分析

当Netty服务器启动之后,执行到NioEventLoop的run方法,这是一个死循环,不断地循环判断有没有事件发生:

// io.netty.channel.nio.NioEventLoop#run
@Override
protected void run() {
    for (;;) {
        try {
            switch (selectStrategy.calculateStrategy(selectNowSupplier, hasTasks())) {
                case SelectStrategy.CONTINUE:
                    continue;
                case SelectStrategy.SELECT:
                    select(wakenUp.getAndSet(false));

                    // 'wakenUp.compareAndSet(false, true)' is always evaluated
                    // before calling 'selector.wakeup()' to reduce the wake-up
                    // overhead. (Selector.wakeup() is an expensive operation.)
                    //
                    // However, there is a race condition in this approach.
                    // The race condition is triggered when 'wakenUp' is set to
                    // true too early.
                    //
                    // 'wakenUp' is set to true too early if:
                    // 1) Selector is waken up between 'wakenUp.set(false)' and
                    //    'selector.select(...)'. (BAD)
                    // 2) Selector is waken up between 'selector.select(...)' and
                    //    'if (wakenUp.get()) { ... }'. (OK)
                    //
                    // In the first case, 'wakenUp' is set to true and the
                    // following 'selector.select(...)' will wake up immediately.
                    // Until 'wakenUp' is set to false again in the next round,
                    // 'wakenUp.compareAndSet(false, true)' will fail, and therefore
                    // any attempt to wake up the Selector will fail, too, causing
                    // the following 'selector.select(...)' call to block
                    // unnecessarily.
                    //
                    // To fix this problem, we wake up the selector again if wakenUp
                    // is true immediately after selector.select(...).
                    // It is inefficient in that it wakes up the selector for both
                    // the first case (BAD - wake-up required) and the second case
                    // (OK - no wake-up required).

                    if (wakenUp.get()) {
                        selector.wakeup();
                    }
                    // fall through
                default:
            }

            cancelledKeys = 0;
            needsToSelectAgain = false;
            final int ioRatio = this.ioRatio;
            if (ioRatio == 100) {
                try {
                    processSelectedKeys();
                } finally {
                    // Ensure we always run tasks.
                    runAllTasks();
                }
            } else {
                final long ioStartTime = System.nanoTime();
                try {
                	// 关键方法
                    processSelectedKeys();
                } finally {
                    // Ensure we always run tasks.
                    final long ioTime = System.nanoTime() - ioStartTime;
                    runAllTasks(ioTime * (100 - ioRatio) / ioRatio);
                }
            }
        } catch (Throwable t) {
            handleLoopException(t);
        }
        // Always handle shutdown even if the loop processing threw an exception.
        try {
            if (isShuttingDown()) {
                closeAll();
                if (confirmShutdown()) {
                    return;
                }
            }
        } catch (Throwable t) {
            handleLoopException(t);
        }
    }
}

1、事件的值

读、写、连接、accept事件,都是在SelectionKey中定义的,利用的是偏移量进行计算

// 1
public static final int OP_READ = 1 << 0;
// 4
public static final int OP_WRITE = 1 << 2;
// 8
public static final int OP_CONNECT = 1 << 3;
// 16
public static final int OP_ACCEPT = 1 << 4;

2、processSelectedKeys获取事件

// io.netty.channel.nio.NioEventLoop#processSelectedKeys
private void processSelectedKeys() {
    if (selectedKeys != null) {
        processSelectedKeysOptimized();
    } else {
        processSelectedKeysPlain(selector.selectedKeys());
    }
}

// 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();
    if (!k.isValid()) {
        final EventLoop eventLoop;
        try {
            eventLoop = ch.eventLoop();
        } catch (Throwable ignored) {
            // If the channel implementation throws an exception because there is no event loop, we ignore this
            // because we are only trying to determine if ch is registered to this event loop and thus has authority
            // to close ch.
            return;
        }
        // Only close ch if ch is still registered to this EventLoop. ch could have deregistered from the event loop
        // and thus the SelectionKey could be cancelled as part of the deregistration process, but the channel is
        // still healthy and should not be closed.
        // See https://github.com/netty/netty/issues/5125
        if (eventLoop != this || eventLoop == null) {
            return;
        }
        // close the channel if the key is not valid anymore
        unsafe.close(unsafe.voidPromise());
        return;
    }

    try {
        int readyOps = k.readyOps();
        // We first need to call finishConnect() before try to trigger a read(...) or write(...) as otherwise
        // the NIO JDK channel implementation may throw a NotYetConnectedException.
        if ((readyOps & SelectionKey.OP_CONNECT) != 0) {
            // remove OP_CONNECT as otherwise Selector.select(..) will always return without blocking
            // See https://github.com/netty/netty/issues/924
            int ops = k.interestOps();
            ops &= ~SelectionKey.OP_CONNECT;
            k.interestOps(ops);

            unsafe.finishConnect();
        }

        // Process OP_WRITE first as we may be able to write some queued buffers and so free memory.
        if ((readyOps & SelectionKey.OP_WRITE) != 0) {
            // Call forceFlush which will also take care of clear the OP_WRITE once there is nothing left to write
            ch.unsafe().forceFlush();
        }

        // Also check for readOps of 0 to workaround possible JDK bug which may otherwise lead
        // to a spin loop
        // 判断事件,selectKeys最终执行的方法
        if ((readyOps & (SelectionKey.OP_READ | SelectionKey.OP_ACCEPT)) != 0 || readyOps == 0) {
            unsafe.read();
        }
    } catch (CancelledKeyException ignored) {
        unsafe.close(unsafe.voidPromise());
    }
}

当我们有客户端连接时,此时我们可以看到readyOps 的值是16,对应着ACCEPT事件也是16,此时会执行unsafe.read()方法。
在这里插入图片描述
NioMessageUnsafe是AbstractNioMessageChannel的一个内部类:

// io.netty.channel.nio.AbstractNioMessageChannel.NioMessageUnsafe
private final class NioMessageUnsafe extends AbstractNioUnsafe {

    private final List<Object> readBuf = new ArrayList<Object>();

    @Override
    public void read() {
    	// 检查该eventLoop是否是当前线程
        assert eventLoop().inEventLoop();
        final ChannelConfig config = config(); // 拿到config
        final ChannelPipeline pipeline = pipeline(); // 拿到pipeline
        final RecvByteBufAllocator.Handle allocHandle = unsafe().recvBufAllocHandle();
        allocHandle.reset(config);

        boolean closed = false;
        Throwable exception = null;
        try {
            try {
                do {
                	// readBuf是一个list,此处循环执行该方法
                	// doReadMessages是读取boss线程中的NioServerSocketChannel接收到的请求,并把这些请求放进readBuf
                    int localRead = doReadMessages(readBuf);
                    if (localRead == 0) {
                        break;
                    }
                    if (localRead < 0) {
                        closed = true;
                        break;
                    }

                    allocHandle.incMessagesRead(localRead);
                } while (allocHandle.continueReading());
            } catch (Throwable t) {
                exception = t;
            }

            int size = readBuf.size();
            for (int i = 0; i < size; i ++) {
                readPending = false;
                // 循环调用handler中的ChannelRead方法
                pipeline.fireChannelRead(readBuf.get(i));
            }
            readBuf.clear();
            allocHandle.readComplete();
            pipeline.fireChannelReadComplete();

            if (exception != null) {
                closed = closeOnReadError(exception);

                pipeline.fireExceptionCaught(exception);
            }

            if (closed) {
                inputShutdown = true;
                if (isOpen()) {
                    close(voidPromise());
                }
            }
        } finally {
            // Check if there is a readPending which was not processed yet.
            // This could be for two reasons:
            // * The user called Channel.read() or ChannelHandlerContext.read() in channelRead(...) method
            // * The user called Channel.read() or ChannelHandlerContext.read() in channelReadComplete(...) method
            //
            // See https://github.com/netty/netty/issues/2254
            if (!readPending && !config.isAutoRead()) {
                removeReadOp();
            }
        }
    }
}

(1)doReadMessages方法

// io.netty.channel.socket.nio.NioServerSocketChannel#doReadMessages
@Override
protected int doReadMessages(List<Object> buf) throws Exception {
	// 实际上调用NIO的的accept方法,获取SocketChannel
    SocketChannel ch = SocketUtils.accept(javaChannel());

    try {
        if (ch != null) {
        	// 将NIO的SocketChannel包装成NioSocketChannel
            buf.add(new NioSocketChannel(this, ch));
            return 1;
        }
    } catch (Throwable t) {
        logger.warn("Failed to create a new channel from an accepted socket.", t);

        try {
            ch.close();
        } catch (Throwable t2) {
            logger.warn("Failed to close a socket.", t2);
        }
    }

    return 0;
}

我们发现,doReadMessages实际上是调用了NIO的SocketChannel的accept方法,获取到NIO的SocketChannel。
然后使用Netty的NioSocketChannel对NIO的SocketChannel进行了包装,最后添加到buf容器中。

(2)pipeline的fireChannelRead方法

doReadMessages方法获取到NioSocketChannel之后,fireChannelRead将这些NioSocketChannel作为参数传入。

// io.netty.channel.DefaultChannelPipeline#fireChannelRead
@Override
public final ChannelPipeline fireChannelRead(Object msg) {
    AbstractChannelHandlerContext.invokeChannelRead(head, msg);
    return this;
}
// io.netty.channel.AbstractChannelHandlerContext#invokeChannelRead(io.netty.channel.AbstractChannelHandlerContext, java.lang.Object)
static void invokeChannelRead(final AbstractChannelHandlerContext next, Object msg) {
    final Object m = next.pipeline.touch(ObjectUtil.checkNotNull(msg, "msg"), next);
    EventExecutor executor = next.executor();
    if (executor.inEventLoop()) {
        next.invokeChannelRead(m);
    } else {
        executor.execute(new Runnable() {
            @Override
            public void run() {
                next.invokeChannelRead(m);
            }
        });
    }
}

// io.netty.channel.AbstractChannelHandlerContext#invokeChannelRead(java.lang.Object)
private void invokeChannelRead(Object msg) {
    if (invokeHandler()) {
        try {
            ((ChannelInboundHandler) handler()).channelRead(this, msg);
        } catch (Throwable t) {
            notifyHandlerException(t);
        }
    } else {
        fireChannelRead(msg);
    }
}

我们发现,会调用channelHandler的channelRead方法,

@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
    ctx.fireChannelRead(msg);
}
@Override
public ChannelHandlerContext fireChannelRead(final Object msg) {
    invokeChannelRead(findContextInbound(), msg);
    return this;
}
static void invokeChannelRead(final AbstractChannelHandlerContext next, Object msg) {
    final Object m = next.pipeline.touch(ObjectUtil.checkNotNull(msg, "msg"), next);
    EventExecutor executor = next.executor();
    if (executor.inEventLoop()) {
        next.invokeChannelRead(m);
    } else {
        executor.execute(new Runnable() {
            @Override
            public void run() {
                next.invokeChannelRead(m);
            }
        });
    }
}

我们发现,调用channelRead方法时,会调用ctx.fireChannelRead(msg); 将请求传递给pipeline中的下一个Handler,而在pipeline中,Handler是链式存储的。

而ServerBootstrapAcceptor是pipeline的最后一个Handler,它的channelRead方法是在ServerBootStrap父类中实现的,我们继续看ServerBootstrapAcceptor的channelRead方法。

注意!此处的Handler,并不是child的Handler!而是bossGroup中定义的Handler!
woekerGroup定义的Handler在children中!

(3)ServerBootstrapAcceptor的channelRead方法

// io.netty.bootstrap.ServerBootstrap.ServerBootstrapAcceptor#channelRead
@Override
@SuppressWarnings("unchecked")
public void channelRead(ChannelHandlerContext ctx, Object msg) {
    final Channel child = (Channel) msg;

    child.pipeline().addLast(childHandler);

    setChannelOptions(child, childOptions, logger);

    for (Entry<AttributeKey<?>, Object> e: childAttrs) {
        child.attr((AttributeKey<Object>) e.getKey()).set(e.getValue());
    }

    try { // 将客户端连接注册到worker线程池
    	// 此处的childGroup,就是我们的workergroup,child就是NioSocketChannel
        childGroup.register(child).addListener(new ChannelFutureListener() {
            @Override
            public void operationComplete(ChannelFuture future) throws Exception {
                if (!future.isSuccess()) {
                    forceClose(child, future.cause());
                }
            }
        });
    } catch (Throwable t) {
        forceClose(child, t);
    }
}

最终调用workGroup(childGroup)的register方法,将NioSocketChannel注册到workerGroup(childGroup)中去。

注意!workGroup是我们命名的,Netty称为childGroup

3、workerGroup的register过程

上面分析到,bossGroup拿到NioSocketChannel之后,会调用workerGroup(childGroup)的register方法进行注册:

// io.netty.channel.MultithreadEventLoopGroup#register(io.netty.channel.Channel)
@Override
public ChannelFuture register(Channel channel) {
    return next().register(channel);
}

next方法会轮询拿到workerGroup的下一个线程(workerGroup一般会创建多个线程,默认为cpu核心数*2),调用register方法将NioSocketChannel传入。

// io.netty.util.concurrent.DefaultEventExecutorChooserFactory.GenericEventExecutorChooser#next
@Override
public EventExecutor next() {
	// 取下一个执行器
    return executors[Math.abs(idx.getAndIncrement() % executors.length)];
}

我们继续看register方法:

// io.netty.channel.SingleThreadEventLoop#register(io.netty.channel.Channel)
@Override
public ChannelFuture register(Channel channel) {
	// 对Channel进一步包装
    return register(new DefaultChannelPromise(channel, this));
}
// io.netty.channel.SingleThreadEventLoop#register(io.netty.channel.ChannelPromise)
@Override
public ChannelFuture register(final ChannelPromise promise) {
    ObjectUtil.checkNotNull(promise, "promise");
    // 真正的register的方法
    promise.channel().unsafe().register(this, promise);
    return promise;
}
// io.netty.channel.AbstractChannel.AbstractUnsafe#register
@Override
public final void register(EventLoop eventLoop, final ChannelPromise promise) {
    if (eventLoop == null) {
        throw new NullPointerException("eventLoop");
    }
    if (isRegistered()) {
        promise.setFailure(new IllegalStateException("registered to an event loop already"));
        return;
    }
    if (!isCompatible(eventLoop)) {
        promise.setFailure(
                new IllegalStateException("incompatible event loop type: " + eventLoop.getClass().getName()));
        return;
    }

    AbstractChannel.this.eventLoop = eventLoop;

    if (eventLoop.inEventLoop()) {
        register0(promise);
    } else {
        try {
            eventLoop.execute(new Runnable() {
                @Override
                public void run() {
                	// 进入到这里
                    register0(promise);
                }
            });
        } catch (Throwable t) {
            logger.warn(
                    "Force-closing a channel whose registration task was not accepted by an event loop: {}",
                    AbstractChannel.this, t);
            closeForcibly();
            closeFuture.setClosed();
            safeSetFailure(promise, t);
        }
    }
}

register0方法中,执行了doRegister方法注册,并且判断Channel中有没有可能存在的任务,进行执行。

// io.netty.channel.AbstractChannel.AbstractUnsafe#register0
private void register0(ChannelPromise promise) {
    try {
        // check if the channel is still open as it could be closed in the mean time when the register
        // call was outside of the eventLoop
        if (!promise.setUncancellable() || !ensureOpen(promise)) {
            return;
        }
        boolean firstRegistration = neverRegistered;
        // 执行注册
        doRegister();
        neverRegistered = false;
        registered = true;

        // Ensure we call handlerAdded(...) before we actually notify the promise. This is needed as the
        // user may already fire events through the pipeline in the ChannelFutureListener.
        pipeline.invokeHandlerAddedIfNeeded();

        safeSetSuccess(promise);
        pipeline.fireChannelRegistered();
        // 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) {
            	// 第一次注册执行ChannelActive方法
                pipeline.fireChannelActive();
            } else if (config().isAutoRead()) {
                // This channel was registered before and autoRead() is set. This means we need to begin read
                // again so that we process inbound data.
                //
                // See https://github.com/netty/netty/issues/4805
                // 开始读取
                beginRead();
            }
        }
    } catch (Throwable t) {
        // Close the channel directly to avoid FD leak.
        closeForcibly();
        closeFuture.setClosed();
        safeSetFailure(promise, t);
    }
}
// io.netty.channel.nio.AbstractNioChannel#doRegister
@Override
protected void doRegister() throws Exception {
    boolean selected = false;
    for (;;) {
        try {
            selectionKey = javaChannel().register(eventLoop().unwrappedSelector(), 0, this);
            return;
        } catch (CancelledKeyException e) {
            if (!selected) {
                // Force the Selector to select now as the "canceled" SelectionKey may still be
                // cached and not removed because no Select.select(..) operation was called yet.
                eventLoop().selectNow();
                selected = true;
            } else {
                // We forced a select operation on the selector before but the SelectionKey is still cached
                // for whatever reason. JDK bug ?
                throw e;
            }
        }
    }
}

4、beginRead方法

// io.netty.channel.AbstractChannel.AbstractUnsafe#beginRead
@Override
public final void beginRead() {
    assertEventLoop();

    if (!isActive()) {
        return;
    }

    try {
        doBeginRead();
    } catch (final Exception e) {
        invokeLater(new Runnable() {
            @Override
            public void run() {
                pipeline.fireExceptionCaught(e);
            }
        });
        close(voidPromise());
    }
}

// io.netty.channel.nio.AbstractNioChannel#doBeginRead
@Override
protected void doBeginRead() throws Exception {
    // Channel.read() or ChannelHandlerContext.read() was called
    final SelectionKey selectionKey = this.selectionKey;
    if (!selectionKey.isValid()) {
        return;
    }

    readPending = true;

    final int interestOps = selectionKey.interestOps();
    if ((interestOps & readInterestOp) == 0) {
        selectionKey.interestOps(interestOps | readInterestOp);
    }
}

到这,Server端接收到Client端发送来的连接请求,并将请求注册到了workerGroup中,workerGroup开始接收数据了。
在这里插入图片描述

5、Netty接受请求过程源码小结

总体流程:接受连接---->创建一个新的 NioSocketChannel---------->注册到一个 worker EventLoop-------->注册 selecot Read 事件。

1)服务器轮询 Accept 事件,获取事件后调用 unsafe 的 read 方法,这个 unsafe 是 ServerSocket 的内部类。
2)doReadMessages 用于创建 NioSocketChannel 对象,该对象包装 JDK 的 Nio Channel 客户端。该方法会像创建 ServerSocketChanel 类似创建相关的 pipeline , unsafe,config。
3)随后执行 pipeline.fireChannelRead 方法,在ServerBootstrapAcceptor的channelRead方法中,调用workerGroup(childGroup)的register方法进行注册。
4)注册成功后,开始监听Read事件。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/452408.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

关于数据挖掘和数据集成?

按照数据的生命周期&#xff0c;我们通常将大数据技术分为数据集成、数据存储、批流处理、数据查询与分析、数据调度与编排、数据开发、BI 7 个部分。 可以看到数据集成在数据生命周期最前面的位置&#xff0c;它负责将多个来自不同数据源的数据聚合存放在一个数据存储中&…

分布式任务调度框架Power-Job

分布式任务调度框架的由来及对比 在大型业务业务系统中&#xff0c;不可避免会出现一些需要定时执行需求的场景&#xff0c;例如定时同步数据&#xff0c;定时清洗数据&#xff0c;定时生成报表&#xff0c;大量机器一同执行某个任务&#xff0c;甚至有些需要分布式处理的任务…

中继器+js组件化GIS地图

虽然可以使用JavaScript注入的方式将GIS地图嵌入Axure&#xff0c;但每次使用地图都需要重复嵌入并修改代码&#xff0c;不太方便。那么&#xff0c;能不能实现组件化呢&#xff1f;我们可以使用中继器&#xff08;repeater&#xff09;将常用的地图参数提取出来&#xff0c;通…

力扣题库刷题笔记406-根据身高重建队列

1、题目如下&#xff1a; 2、个人Python代码实现 这里需要单独备注一下截图中第21行代码&#xff1a; 上图可以看到&#xff0c;已经对[5, 2]等元素进行了遍历循环&#xff0c;且[5, 2]左侧确实只存在[7, 0][6, 1]两个元素身高高于他&#xff0c;但是继续[5,0]循环完成后&#…

@Async异步线程:Spring 自带的异步解决方案

前言 在项目应用中&#xff0c;使用MQ异步调用来实现系统性能优化&#xff0c;完成服务间数据同步是常用的技术手段。如果是在同一台服务器内部&#xff0c;不涉及到分布式系统&#xff0c;单纯的想实现部分业务的异步执行&#xff0c;这里介绍一个更简单的异步方法调用。 对于…

FreeRTOS - 计数信号量

一.任务功能 1、修改按键功能&#xff0c;模拟停车位出入功能 2、当按键按下 获取车位 3、当按键抬起 释放车位 二.API接口 函数原型SemaphoreHandle_t xSemaphoreCreateCounting( ①UBaseType_t uxMaxCount,②UBaseType_t uxInitialCount );功能概述创建计数信号量&#xff0c…

详解空气质量API 使用

引言 空气污染是当今世界面临的一大环境问题&#xff0c;而空气质量监测数据是制定环境政策和公众健康计划的重要依据。通过提供空气质量查询 API&#xff0c;开发人员可以方便地获取中国境内多个城市的空气质量数据&#xff0c;从而更好地监测和管理空气质量。 本文将介绍的…

Redis入门学习笔记【一】

目录 一、redis是什么 二、Redis数据结构 2.1 Redis 的五种基本数据类型 2.1.1String&#xff08;字符串&#xff09; 2.1.2字符串列表&#xff08;lists&#xff09; 2.1.3字符串集合&#xff08;sets&#xff09; 2.1.5哈希&#xff08;hashes&#xff09; 2.2 Red…

设计模式详解-软件设计(五十六)

原创 真题详解(UML图)-软件设计&#xff08;五十五)https://blog.csdn.net/ke1ying/article/details/130311994 创建型、结构型、行为型 抽象工厂&#xff08;Abstruct Factory&#xff09; 提供一个创建系列相关或相互依赖的接口&#xff0c;无须指定他们具体的类。 适用于&…

07-Node.js—包管理工具

目录 1、概念介绍1.1 包是什么1.2 包管理工具1.3 常用的包管理工具 2、npm2.1 npm 的安装2.2 npm 基本使用2.2.1 初始化2.2.2 搜索包2.2.3 下载安装包2.2.4 require 导入 npm 包基本流程 2.3 生产环境与开发环境2.4 生产依赖与开发依赖2.5 全局安装2.5.1 修改 windows 执行策略…

CorelDRAW 2023版本更新内容及安装详细教程

这里是CorelDRAW 2023版本更新内容及安装详细教程: CorelDRAW 2023是最新更新版本,在界面和功能上做了较大提升与优化: 1. 简洁界面:采用全新设计界面,简约而不简单。菜单和工具栏进行了整合与重组,更加直观。拥有自动标记和提示,易于上手使用。 2. 全新工作空间:提供“轻量…

Qt — Graphics/View框架

文章目录 前言一、Qt图形系统介绍二、Graphics/View框架 前言 Qt的Graphics/View框架被用来存放、显示二维图形元素&#xff0c;处理那些对图形元素进行操作的交互命令。 一、Qt图形系统介绍 Qt 应用程序的图形界面包含各种控件&#xff0c;比如窗口、按钮、滚动条等。所有这…

三谈ChatGPT(ChatGPT可以解决问题的90%)

这是我第三次谈ChatGPT&#xff0c;前两篇主要谈了ChatGPT的概念&#xff0c;之所以火的原因和对人们的影响&#xff0c;以及ChatGPT可能存在的安全风险和将面临的监管问题。这一篇主要讲讲ChatGPT的场景和处理问题的逻辑。 这一次我特意使用了ChatGPT中文网页版体验了一番。并…

3个月,从功能测试进阶到自动化测试涨薪10k,我悟了....

因为我最近在分享自动化测试技术&#xff0c;经常被问到&#xff1a; 功能测试想转自动化&#xff0c;请问应该怎么入手&#xff1f;有没有好的资源推荐&#xff1f; 那么&#xff0c;接下来我就结合自己的经历聊一聊我是如何在工作中做自动化测试的。&#xff08;学习路线和…

EIGRP配置 路由过滤和汇总,以及默认路由

1.4.1 实验目的 通过对 EIGRP 路由过滤&#xff0c;汇总以及默认路由配置的实验的练习&#xff0c;从而掌握 EIGRP 路由过 滤的方法&#xff0c;EIGRP 路由汇总的方法和作用&#xff0c;以及如何为 EIGRP 配置默认路由。 1.4.2 实验拓扑 1.4.3 实验步骤 配置 R1&#xff0c…

【深度学习】计算分类模型的分类指标,计算accuracy_top-1、accuracy_top-5、precision、recall和f1_score

计算accuracy_top-1、accuracy_top-5、precision、recall和f1_score&#xff1a; &#xff08;1&#xff09;accuracy_top-1 np.sum(np.argmax(preds, axis1) np.argmax(actual, axis1)) / actual.shape[0] accuracy_top-1指标是假设预测数据中&#xff0c;最大值的index就是…

自动控制原理模拟卷8

自动控制原理模拟题八 Question1 求解以下电网络和机械系统的传递函数,并证明下图的电网络和机械系统有相同的数学模型。 解: 【图 ( a ) ({\rm a}) (a)系统传递函数】 根据复数阻抗的方法可得电网络的传递函数为:

为啥运维人员更喜欢 NeoVim 而不是 Vim?这8个原因或许是答案,命令对比一目了然!

在 Linux 系统中&#xff0c;编辑器是开发和系统管理的必备工具。而在众多编辑器中&#xff0c;Vim 作为一款经典的文本编辑器&#xff0c;一直备受欢迎。然而&#xff0c;随着时间的推移&#xff0c;NeoVim 的出现逐渐成为了 Linux 运维人员的首选。那么&#xff0c;为什么 Li…

Opencv+Python笔记(七)边缘检测原理

注意:梯度计算总是由右边减去左边 目录 一、边缘检测原理二、Sobel算子&#xff08;基于搜索&#xff09;三、Laplacian算子&#xff08;基于零穿越&#xff09;四、Candy边缘检测算法1.消除噪声2. 计算图像的亮度梯度值3.减除虚假边缘&#xff08;非极大值抑制NMS&#xff09…

OSCP-Sirol(docker容器到宿主机)

目录 扫描 WEB 提权 扫描 sudo nmap 192.168.64.54 -p- -sS -sVPORT STATE SERVICE VERSION 22/tcp open ssh OpenSSH 7.4p1 Debian 10+deb9u7 (protocol 2.0) 53/tcp closed domain 80/tcp open http Apache httpd 2.4.25 ((Debian)) 3306…