Netty(四)NIO-优化与源码

Netty优化与源码

1. 优化

1.1 扩展序列化算法

序列化,反序列化主要用于消息正文的转换。
序列化:将java对象转为要传输对象(byte[]或json,最终都是byte[])
反序列化:将正文还原成java对象。

//java自带的序列化
// 反序列化
byte[] body = new byte[bodyLength];
byteByf.readBytes(body);
ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(body));
Message message = (Message) in.readObject();
message.setSequenceId(sequenceId);
// 序列化
ByteArrayOutputStream out = new ByteArrayOutputStream();
new ObjectOutputStream(out).writeObject(message);
byte[] bytes = out.toByteArray();

为了支持更多序列化算法,抽象一个 Serializer 接口,提供两个实现,将实现加入了枚举类 Serializer.Algorithm 中:

enum SerializerAlgorithm implements Serializer {// Java 实现Java {@Overridepublic <T> T deserialize(Class<T> clazz, byte[] bytes) {try {ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(bytes));Object object = in.readObject();return (T) object;} catch (IOException | ClassNotFoundException e) {throw new RuntimeException("SerializerAlgorithm.Java 反序列化错误", e);}}@Overridepublic <T> byte[] serialize(T object) {try {ByteArrayOutputStream out = new ByteArrayOutputStream();new ObjectOutputStream(out).writeObject(object);return out.toByteArray();} catch (IOException e) {throw new RuntimeException("SerializerAlgorithm.Java 序列化错误", e);}}}, // Json 实现(引入了 Gson 依赖)Json {@Overridepublic <T> T deserialize(Class<T> clazz, byte[] bytes) {return new Gson().fromJson(new String(bytes, StandardCharsets.UTF_8), clazz);}@Overridepublic <T> byte[] serialize(T object) {return new Gson().toJson(object).getBytes(StandardCharsets.UTF_8);}};// 需要从协议的字节中得到是哪种序列化算法public static SerializerAlgorithm getByInt(int type) {SerializerAlgorithm[] array = SerializerAlgorithm.values();if (type < 0 || type > array.length - 1) {throw new IllegalArgumentException("超过 SerializerAlgorithm 范围");}return array[type];}
}

增加配置类和配置文件:

public abstract class Config {static Properties properties;static {try (InputStream in = Config.class.getResourceAsStream("/application.properties")) {properties = new Properties();properties.load(in);} catch (IOException e) {throw new ExceptionInInitializerError(e);}}public static int getServerPort() {String value = properties.getProperty("server.port");if(value == null) {return 8080;} else {return Integer.parseInt(value);}}public static Serializer.Algorithm getSerializerAlgorithm() {String value = properties.getProperty("serializer.algorithm");if(value == null) {return Serializer.Algorithm.Java;} else {return Serializer.Algorithm.valueOf(value);}}
}

配置文件

serializer.algorithm=Json

修改编解码器

/*** 必须和 LengthFieldBasedFrameDecoder 一起使用,确保接到的 ByteBuf 消息是完整的*/
public class MessageCodecSharable extends MessageToMessageCodec<ByteBuf, Message> {@Overridepublic void encode(ChannelHandlerContext ctx, Message msg, List<Object> outList) throws Exception {// 3. 1 字节的序列化方式 jdk 0 , json 1out.writeByte(Config.getSerializerAlgorithm().ordinal());byte[] bytes = Config.getSerializerAlgorithm().serialize(msg);}@Overrideprotected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {byte serializerAlgorithm = in.readByte(); // 0 或 1// 找到反序列化算法Serializer.Algorithm algorithm = Serializer.Algorithm.values()[serializerAlgorithm];// 确定具体消息类型Class<? extends Message> messageClass = Message.getMessageClass(messageType);Message message = algorithm.deserialize(messageClass, bytes);out.add(message);}
}

1.2 参数调优

CONNECT_TIMEOUT_MILLIS
  • 属于SocketChannel参数,用在客户端建立连接时,如超时则抛出timeout异常
  • SO_TIMEOUT主要用在阻塞IO,阻塞IO中accept,read等都是无限等待的
Bootstrap bootstrap = new Bootstrap().group(group).option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 5000).channel(NioServerSocketChannel.class).handler(new LoggingHandler());

附源码部分 io.netty.channel.nio.AbstractNioChannel.AbstractNioUnsafe#connect

@Override
public final void connect(final SocketAddress remoteAddress, final SocketAddress localAddress, final ChannelPromise promise) {// ...// Schedule connect timeout.int connectTimeoutMillis = config().getConnectTimeoutMillis();if (connectTimeoutMillis > 0) {connectTimeoutFuture = eventLoop().schedule(new Runnable() {@Overridepublic void run() {                ChannelPromise connectPromise = AbstractNioChannel.this.connectPromise;ConnectTimeoutException cause =new ConnectTimeoutException("connection timed out: " + remoteAddress); // 断点2if (connectPromise != null && connectPromise.tryFailure(cause)) {close(voidPromise());}}}, connectTimeoutMillis, TimeUnit.MILLISECONDS);}// ...
}
SO_BACKLOG
  • 属于ServerSocketChannel参数
    三次握手过程
    sync queue - 半连接队列
    • 大小通过 /proc/sys/net/ipv4/tcp_max_syn_backlog 指定,在 syncookies 启用的情况下,逻辑上没有最大值限制,这个设置便被忽略
      accept queue - 全连接队列
    • 其大小通过 /proc/sys/net/core/somaxconn 指定,在使用 listen 函数时,内核会根据传入的 backlog 参数与系统参数,取二者的较小值
    • 如果 accpet queue 队列满了,server 将发送一个拒绝连接的错误信息到 client
      netty中可通过option(ChannelOption.SO_BACKLOG,值)来设置大小
public class DefaultServerSocketChannelConfig extends DefaultChannelConfigimplements ServerSocketChannelConfig {private volatile int backlog = NetUtil.SOMAXCONN;// ...默认大小
}
ulimit -n
  • 限制一个进程打开最大文件描述符的数目,属于操作系统参数
TCP_NODELAY
  • nagle算法的延迟,一般设为true不延迟,数据赞属于 SocketChannal 参数
SO_SNDBUF & SO_RECVBUF

滑动接口的参数,现在的操作系统会根据实际情况自动调整。

  • SO_SNDBUF 属于 SocketChannal 参数
  • SO_RCVBUF 既可用于 SocketChannal 参数,也可以用于 ServerSocketChannal 参数(建议设置到 ServerSocketChannal 上)
ALLOCATOR

ByteBuf分配器,属于 SocketChannal 参数,用来分配 ByteBuf, ctx.alloc()。源码详解P128

RCVBUF_ALLOCATOR
  • 属于 SocketChannal 参数,控制 netty 接收缓冲区大小。源码详解:P129
  • 负责入站数据的分配,决定入站缓冲区的大小(并可动态调整),统一采用 direct 直接内存,具体池化还是非池化由 allocator 决定

1.3 RPC 框架

通过反射获取配置

public class ServicesFactory {static Properties properties;static Map<Class<?>, Object> map = new ConcurrentHashMap<>();static {try {InputStream in = Config.class.getResourceAsStream("/application.properties");properties = new Properties();properties.load(in);Set<String> names = properties.stringPropertyNames();for (String name : names) {if (name.endsWith("Services")) {Class<?> interfaceClass = Class.forName(name);Class<?> instanceClass = Class.forName(properties.getProperty(name));map.put(interfaceClass, instanceClass.newInstance());}}} catch (IOException | ClassNotFoundException | InstantiationException | IllegalAccessException e) {throw new ExceptionInInitializerError(e);}}public static <T> T getService(Class<T> interfaceClass) {return (T) map.get(interfaceClass);}
}

RPC消息处理器

@ChannelHandler.Sharable
public class RpcRequestMessageHandler extends SimpleChannelInboundHandler<RpcRequestMessage> {@Overrideprotected void channelRead0(ChannelHandlerContext ctx, RpcRequestMessage message) {RpcResponseMessage response = new RpcResponseMessage();try {HelloService service = (HelloService) ServicesFactory.getService(Class.forName(message.getInterfaceName()));Method method = service.getClass().getMethod(message.getMethodName(), message.getParameterTypes());Object invoke = method.invoke(service, message.getParameterValue());response.setReturnValue(invoke);} catch (Exception e) {e.printStackTrace();response.setExceptionValue(e);}ctx.writeAndFlush(response);}//本地调试public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException {RpcRequestMessage message = new RpcRequestMessage(1,"com.aric.server.service.HelloService","sayHello",String.class,new Class[]{String.class},new Object[]{"aric"});HelloService service = (HelloService) ServicesFactory.getService(Class.forName(message.getInterfaceName()));Method method = service.getClass().getMethod(message.getMethodName(), message.getParameterTypes());Object invoke = method.invoke(service, message.getParameterValue());System.out.println(invoke);}
}

客户端优化,抽取使用代理对象发送消息

/*** 使用代理对象替换,主线程发送* NioEventLoop线程接收结果,需要线程间通信,使用promise对象接收结果* @author* @created by xuyu on 2023/9/23-23:10*/
@Slf4j
public class RpcClientManager {public static void main(String[] args) {//后期创建代理类优化发送结构getChannel().writeAndFlush(new RpcRequestMessage(1,"com.aric.server.service.HelloService","sayHello",String.class,new Class[]{String.class},new Object[]{"test"}));//使用代理发送HelloService service = getProxyService(HelloService.class);service.sayHello("test");}//创建代理类public static <T> T getProxyService(Class<T> serviceClass) {ClassLoader loader = serviceClass.getClassLoader();  //当前类加载器Class[] interfaces = new Class[]{serviceClass};//代理类要实现的接口//jdk自带的代理Object o = Proxy.newProxyInstance(loader, interfaces, (proxy, method, arg) -> {//proxy代理对象,method:代理方法,arg:代理参数//1.将方法调用转换为消息对象RpcRequestMessage message = new RpcRequestMessage(SequenceIdGenerator.nextId(),serviceClass.getName(),method.getName(),method.getReturnType(),method.getParameterTypes(),arg);//2.将消息对象发送出去getChannel().writeAndFlush(message);//3.TODO:待优化异步等待返回结果return null;});return (T)o;}private static Channel channel = null;private static final Object LOCK = new Object();//单例构造获取唯一channel对象public static Channel getChannel() {if (channel != null) {return channel;}synchronized (LOCK) {if (channel != null) {return channel;}initChannel();return channel;}}//初始化channel方法private static void initChannel() {NioEventLoopGroup group = new NioEventLoopGroup();LoggingHandler LOGGING_HANDLER = new LoggingHandler(LogLevel.DEBUG);MessageCodecSharable MESSAGE_CODEC = new MessageCodecSharable();RpcResponseMessageHandler RPC_HANDLER = new RpcResponseMessageHandler();Bootstrap bootstrap = new Bootstrap();bootstrap.channel(NioSocketChannel.class);bootstrap.group(group);bootstrap.handler(new ChannelInitializer<SocketChannel>() {@Overrideprotected void initChannel(SocketChannel ch) throws Exception {ch.pipeline().addLast(new ProtocolFrameDecoder());ch.pipeline().addLast(LOGGING_HANDLER);ch.pipeline().addLast(MESSAGE_CODEC);ch.pipeline().addLast(RPC_HANDLER);}});try {channel = bootstrap.connect("localhost", 8080).sync().channel();//改为异步channel.closeFuture().addListener(future -> {group.shutdownGracefully();});} catch (InterruptedException e) {log.debug("client error", e);}}
}

优化:线程间通信:异步获取返回结果
通过promise异步等待信息返回

//创建代理类public static <T> T getProxyService(Class<T> serviceClass) {ClassLoader loader = serviceClass.getClassLoader();  //当前类加载器Class[] interfaces = new Class[]{serviceClass};//代理类要实现的接口//jdk自带的代理Object o = Proxy.newProxyInstance(loader, interfaces, (proxy, method, arg) -> {//proxy代理对象,method:代理方法,arg:代理参数//1.将方法调用转换为消息对象int sequenceId = SequenceIdGenerator.nextId();RpcRequestMessage message = new RpcRequestMessage(sequenceId,serviceClass.getName(),method.getName(),method.getReturnType(),method.getParameterTypes(),arg);//2.将消息对象发送出去getChannel().writeAndFlush(message);//3.返回//准备好空的promise对象来接收结果,参数为指定promise对象异步接收结果的线程DefaultPromise<Object> promise = new DefaultPromise<>(getChannel().eventLoop());RpcResponseMessageHandler.PROMISE.put(sequenceId, promise);
//            promise.addListener(future -> {
//                //创建线程处理任务
//            });//原线程等待promise的结果promise.await();if (promise.isSuccess()) {return promise.getNow();} else {throw new RuntimeException(promise.cause());}});return (T) o;}
/*** rpc响应消息处理器*/
@Slf4j
@ChannelHandler.Sharable
public class RpcResponseMessageHandler extends SimpleChannelInboundHandler<RpcResponseMessage> {//序号-promise<结果类型>,多个线程访问,用于异步接收rpc调用的返回结果public static final Map<Integer, Promise<Object>> PROMISE = new ConcurrentHashMap<>();@Overrideprotected void channelRead0(ChannelHandlerContext ctx, RpcResponseMessage msg) throws Exception {//拿到空的promisePromise<Object> promise = PROMISE.remove(msg.getSequenceId());  //返回并移除if (promise != null) {Object returnValue = msg.getReturnValue();Exception exceptionValue = msg.getExceptionValue();if (exceptionValue != null) {promise.setFailure(exceptionValue);} else {promise.setSuccess(returnValue);}}System.out.println(msg);}

代码:https://gitee.com/xuyu294636185/netty-demo.git

2. 源码

2.1 netty启动剖析

        //1. netty中使用EventLoopGroup(Nio boss线程),来封装线程和selectorSelector selector = Selector.open();//创建NioServerSocketChannel,同时初始化它关联的handler,以及为原生ssc存储configNioServerSocketChannel attachment = new NioServerSocketChannel();ServerSocketChannel ssc = ServerSocketChannel.open();ssc.configureBlocking(false);//2.启动nio boss线程执行//建立selector和channel的注册,sscKey是事件的句柄,是将来事件发生后,通过它可以知道事件和哪个channel的事件SelectionKey sscKey = ssc.register(selector, 0, attachment);ssc.bind(new InetSocketAddress(8080));//表示sscKey只关注accept事件sscKey.interestOps(SelectionKey.OP_ACCEPT);
启动流程

启动流程

EventLoop

EventLoop重要组成:selector,线程,任务队列
EventLoop既会处理io事件,也会处理普通任务和定时任务

  1. selector何时创建?
    在构造方法创建时通过SelectorProvider.openSelector();
  2. eventloop为什么会有两个selector成员?
    为了在遍历selectedKey时提高性能。
    一个是原始的unwrappedselector(底层是hashset实现),一个是包装后的selector(底层是数组实现)
  3. eventLoop的nio线程在何时启动?
    在首次调用exectue方法时executor中将当前线程赋给nio线程,并通过state状态控制位只会启动一次
  4. 提交普通任务会不会结束select阻塞?

    int selectedKeys = selector.select(timeoutMillis);
    protected void wakeup(boolean inEventLoop) {
    if(!inEventLoop && wakeUp.compareAndSet(false,true)) {
    selector.wakeup();
    }
    }
  5. wakeup方法理解
    inEventLoop:用于判断当前wakeup线程是否和nio线程是否相同,不同才能进入。
    wakeUp:原子Boolean变量,如果有多个线程来提交任务,为了避免wakeup被频繁调用。只有一个成功。
  6. 每次循环时,什么时候会进入SelectStrategy.SELECT分支?
    public void run(){
    for(;😉 {
    switch(selectStrategy.calculateStrategy(selectNowSupplier, hasTask())) {
    case SelectStrategy.CONTINUE:
    continue;
    case SelectStrategy.BUSY_WAIT:
    case SelectStrategy.SELECT:
    select(wakeUp.getAndSet(false));
    if(wakeUp.get()) {…}
    default:
    }
    }
    }
    public int calculateStrategy(IntSupplier supplier,boolean hasTasks) {
    return hasTasks ? suppplier.get() : SelectStrategy.SELECT;
    }
    没有任务时,才会进入SELECT。
    当有任务时,会调用SelectNow方法,顺便拿到io事件。
  7. 何时会select阻塞,阻塞多久?
    long currentTimeNanos = System.nanoTime();
    long selectDeadLineNanos = currentTimeNanos + delayNanos(cuurrentTimeNanos);
    for(;😉{
    long timeoutMillis = (selectDeadLineNanos - currentTimeNanos + 500000L) / 1000000L;
    int selectedKeys = selector.select(timeoutMillis);
    }
    没有定时任务的情况
    selectDeadLineNanos:截至时间 = 当前时间 + 1s
    timeoutMillis:超时时间 = 1s + 0.5ms
  8. nio空轮询bug在哪体现,如何解决?
    for(;😉{
    long timeoutMillis = (selectDeadLineNanos - currentTimeNanos + 500000L) / 1000000L;
    int selectedKeys = selector.select(timeoutMillis);
    }
    在select中没有阻塞,一直在死循环
    解决:引入selectCnt,每循环一次++,当超过设置的阈值(默认512),selectRebuildSelector(selectCnt)重新创建一个selector,替换旧的。
  9. ioRatio控制什么,设置为100有何作用?
    if(ioRatio == 100) {
    processSelectedKeys(); //处理所有ioio事件
    runAllTasks();
    } else {
    long ioStartTime = System.nanoTime();
    processSelectedKeys();
    long ioTime = System.nanoTime() - ioStartTime;
    runAllTasks(ioTime * (100 - ioRatio) / ioRatio); //避免普通事件执行时间太长
    }
    ioRatio控制处理io事件所占用的事件比例50%,ioTime代表执行io事件处理耗时。
  10. selectedKeys优化,在哪区分不同事件类型。
    selectedKeys由hashset集合替换为数组实现。
    private void processSelectedKeys() [
    if(selectedKeys != null) {
    processSelectedKeysOptimized(); //优化后的
    } else {
    processSelectedKeysPlain(selector.selectedKeys()); //原始的
    }
    }
    private void processSelectedKeysOptimized() {
    for(int i = 0;i < selectedKeys.size; ++i) {
    SelectionKey k = selectedKeys.keys[i];
    selectedKeys.keys[i] = null;
    Objected a = k.attachment();
    if(a instanceof AbstractNioChannel) {
    processSelectedKey(k, (AbstractNioChannel) a); //处理具体的事件类型
    }
    }
    }
accept流程
  1. selector.select()阻塞直到事件发生
  2. 遍历处理selectedKeys
  3. 拿到一个key,判断事件类型是否为accpet
  4. 创建socketChannel,设置非阻塞
  5. 将socketChannel注册到selector
  6. 关注selectionKey的read事件。
read流程
  1. selector.select()阻塞直到事件发生
  2. 遍历处理selectedKeys
  3. 拿到一个key,判断事件类型是否为read
  4. 读取操作

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

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

相关文章

SpringBoot自带模板引擎Thymeleaf使用详解①

目录 前言 一、SpringBoot静态资源相关目录 二、变量输出 2.1 在templates目录下创建视图index.html 2.2 创建对应的Controller 2.3 在视图展示model中的值 三、操作字符串和时间 3.1 操作字符串 3.2 操作时间 前言 Thymeleaf是一款用于渲染XML/HTML5内容的模板引擎&am…

[unity]保存文件的路径设置

序 比如&#xff0c;序列化了一个数组&#xff0c;保存到磁盘上。 原来的路径是"D://test.bin"&#xff0c;能跑&#xff0c;但是有点问题&#xff1a;序列化出来的文件和原项目离的太远&#xff0c;不好管理。 要是能保存到unity工程的文件夹里就好了。这个路径该…

学习记忆——方法篇——整除特点

理解记忆法 对于数的整除特征大家都比较熟悉&#xff1a;比如4看后两位&#xff08;因为100是4的倍数&#xff09;&#xff0c;8看后三位&#xff08;因为1000是8的倍数&#xff09;&#xff0c;5末尾是0或5&#xff0c;3与9看各位数字和等等&#xff0c;今天重点研究一下3,9,…

毕设-原创医疗预约挂号平台分享

医疗预约挂号平台 不是尚医通项目&#xff0c;先看项目质量&#xff08;有源码论文&#xff09; 项目链接&#xff1a;医疗预约挂号平台git地址 演示视频&#xff1a;医疗预约挂号平台 功能结构图 登录注册模块&#xff1a;该模块具体分为登录和注册两个功能&#xff0c;这些…

小样本学习——匹配网络

目录 匹配网络 &#xff08;1&#xff09;简单介绍&#xff1a; &#xff08;2&#xff09;专业术语 &#xff08;3&#xff09;主要思想 &#xff08;4&#xff09;训练过程 问题 回答 MANN 匹配网络 &#xff08;1&#xff09;简单介绍&#xff1a; Matching netwo…

创新家庭办公室:打造完美工作空间的秘诀

一个精心策划的家庭办公室有很多好处&#xff0c;何不把临时工作区升级改造为你的专属工作区呢&#xff0c;还能为这些至关重要的区域注入新的活力。 创造多用途的起居室&#xff1a;我们大多数人都不曾拥有一个可以完全根据工作需求设计的独立家庭办公室——所以有时候要找到…

【锁的区别】C++线程库和POSIX线程库锁的区别

C线程库和POSIX线程库锁的区别 C线程库代码段的互斥&#xff1a;mutex、recursive_mutex、timed_mutex、recursive_timed_mutex互斥量mutex&#xff1a;直接进行lock()或者unlock()递归互斥锁recursive_mutex&#xff1a;可以多次加锁&#xff0c;意味着加几次锁就需要解几次锁…

【C++】:类和对象(2)

朋友们、伙计们&#xff0c;我们又见面了&#xff0c;本期来给大家解读一下有关Linux的基础知识点&#xff0c;如果看完之后对你有一定的启发&#xff0c;那么请留下你的三连&#xff0c;祝大家心想事成&#xff01; C 语 言 专 栏&#xff1a;C语言&#xff1a;从入门到精通 数…

netcore Polly.Core

一、安装包 <PackageReference Include"Polly.Core" Version"8.0.0" /> 二、编写重试 ResiliencePipeline pipeline new ResiliencePipelineBuilder().AddRetry(new RetryStrategyOptions{MaxRetryAttempts 2,Delay TimeSpan.FromSeconds(3),O…

王杰国庆作业day6

服务器 #include <stdio.h> #include <string.h> #include <stdlib.h> #include <my_head.h> #define PORT 2324 //端口号 #define IP "192.168.10.107" //本机IP int main(int argc, const char *argv[]) {sqlite3* d…

【JavaEE】JUC(Java.util.concurrent)常见类

文章目录 前言ReentrantLock原子类线程池信号量CountDownLatch相关面试题 前言 经过前面文章的学习我们大致了解了如何实现多线程编程和解决多线程编程中遇到的线程不安全问题&#xff0c;java.util.concurrent 是我们多线程编程的一个常用包&#xff0c;那么今天我将为大家分…

vue、vuex状态管理、vuex的核心概念state状态

每一个 Vuex 应用的核心就是 store&#xff08;仓库&#xff09;。“store”基本上就是一个容器&#xff0c;它包含着你的应用中大部分的状态 (state)。Vuex 和单纯的全局对象有以下两点不同&#xff1a; Vuex 的状态存储是响应式的。当 Vue 组件从 store 中读取状态的时候&…

【TensorFlow Hub】:有 100 个预训练模型等你用

要访问TensorFlow Hub&#xff0c;请单击此处 — https://www.tensorflow.org/hub 一、说明 TensorFlow Hub是一个库&#xff0c;用于在TensorFlow中发布&#xff0c;发现和使用可重用模型。它提供了一种使用预训练模型执行各种任务&#xff08;如图像分类、文本分析等&#xf…

计算机专业毕业设计项目推荐11-博客项目(Go+Vue+Mysql)

博客项目&#xff08;GoVueMysql&#xff09; **介绍****系统总体开发情况-功能模块****各部分模块实现** 介绍 本系列(后期可能博主会统一为专栏)博文献给即将毕业的计算机专业同学们,因为博主自身本科和硕士也是科班出生,所以也比较了解计算机专业的毕业设计流程以及模式&am…

[黑马程序员TypeScript笔记]------一篇就够了

目录&#xff1a; TypeScript 介绍 TypeScript 是什么&#xff1f;TypeScript 为什么要为 JS 添加类型支持&#xff1f;TypeScript 相比 JS 的优势TypeScript 初体验 安装编译 TS 的工具包 编译并运行 TS 代码 简化运行 TS 的步骤 TypeScript 常用类型 概述类型注解常用基础…

基于微信小程序的付费自习室

博主介绍&#xff1a;✌程序员徐师兄、7年大厂程序员经历。全网粉丝30W、csdn博客专家、掘金/华为云/阿里云/InfoQ等平台优质作者、专注于Java技术领域和毕业项目实战✌ 文章目录 1 简介2 技术栈3 需求分析3.1用户需求分析3.1.1 学生用户3.1.3 管理员用户 4 数据库设计4.4.1 E…

Linux友人帐之账号用户管理

一、账号管理 1.1简介 Linux系统是一个多用户多任务的分时操作系统&#xff0c;任何一个要使用系统资源的用户&#xff0c;都必须首先向系统管理员申请一个账号&#xff0c;然后以这个账号的身份进入系统。 用户的账号一方面可以帮助系统管理员对使用系统的用户进行跟踪&#…

lv7 嵌入式开发-网络编程开发 12 IP协议与ethernet协议

目录 1 IP协议作用和意义 2 IP数据报首部格式 3 IP数据报分片 4 以太网协议作用和意义&#xff08;链路层&#xff09; 5 练习 1 IP协议作用和意义 IP网的意义 当互联网上的主机进行通信时&#xff0c;就好像在一个网络上通信一样&#xff0c;看不见互连的各具体的网络异…

mysql面试题10:MySQL中有哪几种锁?表级锁、行级锁、页面锁区别和联系?

该文章专注于面试,面试只要回答关键点即可,不需要对框架有非常深入的回答,如果你想应付面试,是足够了,抓住关键点 面试官:Mysql中有哪几种锁? 在MySQL中,主要有以下几种类型的锁: 共享锁(Shared Lock):也称为读锁。多个事务可以同时持有共享锁,可以读取但不能修…

浏览器渲染原理

1 浏览器是如何渲染页面的&#xff1f; 浏览器的渲染 render 将 html 字符串 --> 像素信息 function render(html) {// ...return pixels; }网络&#xff1a;拿 HTML&#xff08;JS和CSS也在HTML中&#xff09;&#xff1b; 渲染&#xff1a;渲染&#xff1b; 当浏览器的 …