首页 文章 精选 留言 我的

精选列表

搜索[AI性能],共10000篇文章
优秀的个人博客,低调大师

Gos Log V3.0.1 版本发布,高性能大日志检索中台

Gos Log V3.0.1 版本发布,V3.0.1支持功能如下 支持客户端logc启动即注册 支持服务端logs定时检测客户端在线状态 支持关键字不唯一时,也能全部检索 优化删除逻辑 版本地址 https://gitee.com/dianjiu/gos-log/releases/V3.0.1 https://github.com/dianjiu/gos-log/releases/V3.0.1 仓库地址 gos-log https://gitee.com/dianjiu/gos-log(opens new window) https://github.com/dianjiu/gos-log(opens new window) gos-log-vue https://gitee.com/dianjiu/gos-log-vue(opens new window) https://github.com/dianjiu/gos-log-vue 打包 #gos-log # 打包服务端 cd gos-log/logs bee pack -be GOOS=linux # 打包客户端 cd gos-log/logc bee pack -be GOOS=linux # 准备数据库 见gos-log项目下的sql文件夹 # 将打包后的文件上传到服务器指定目录 #gos-log-vue # 打包构建 yarn run build # 把dist目录下的文件上传到服务器的指定目录 #启动 #gos-log-logs # 解压缩 tar -zxf logs.tar.gz -C ./ # 授权 chmod -x logs # 修改数据库配置、临时目录 sudo vim conf/app.conf # 启动 nohup ./logs >> logs.log & #gos-log-logc # 解压缩 tar -zxf logc.tar.gz -C ./ # 授权 chmod -x logc # 修改临时目录 sudo vim conf/app.conf # 启动 nohup ./logc >> logc.log & #gos-log-vue # nginx部署如下nginx.conf server { listen 2022; server_name localhost; location / { root /web/gos-log/vue; index index.html index.htm; try_files $uri $uri/ /index.html; } location /api { rewrite ^/api/(.*)$ /$1 break; proxy_pass http://127.0.0.1:2021; } }

优秀的个人博客,低调大师

高性能IO框架Netty:手把手教你解决 “粘包/半包” 问题!

2 --> 前言:demo演示 首先,我们来看个demo 1、EchoServer public class EchoServer { private final int port; public EchoServer(int port) { this.port = port; } public static void main(String[] args) throws InterruptedException { EchoServer echoServer = new EchoServer(9999); System.out.println("服务器即将启动"); echoServer.start(); System.out.println("服务器关闭"); } public void start() throws InterruptedException { final EchoServerHandler serverHandler = new EchoServerHandler(); EventLoopGroup group = new NioEventLoopGroup();/*线程组*/ try { ServerBootstrap b = new ServerBootstrap();/*服务端启动必须*/ b.group(group)/*将线程组传入*/ .channel(NioServerSocketChannel.class)/*指定使用NIO进行网络传输*/ .localAddress(new InetSocketAddress(port))/*指定服务器监听端口*/ /*服务端每接收到一个连接请求,就会新启一个socket通信,也就是channel, 所以下面这段代码的作用就是为这个子channel增加handle*/ .childHandler(new ChannelInitializer<SocketChannel>() { protected void initChannel(SocketChannel ch) throws Exception { ch.pipeline().addLast(serverHandler);/*添加到该子channel的pipeline的尾部*/ } }); ChannelFuture f = b.bind().sync();/*异步绑定到服务器,sync()会阻塞直到完成*/ System.out.println("服务器启动完成,等待客户端的连接和数据....."); f.channel().closeFuture().sync();/*阻塞直到服务器的channel关闭*/ } finally { group.shutdownGracefully().sync();/*优雅关闭线程组*/ } } } 2、EchoServerHandler @ChannelHandler.Sharable public class EchoServerHandler extends ChannelInboundHandlerAdapter { private AtomicInteger counter = new AtomicInteger(0); /*** 服务端读取到网络数据后的处理*/ @Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { ByteBuf in = (ByteBuf) msg; String request = in.toString(CharsetUtil.UTF_8); System.out.println("Server Accept[" + request + "] and the counter is:" + counter.incrementAndGet()); String resp = "Hello," + request + ". Welcome to Netty World!" + System.getProperty("line.separator"); ctx.writeAndFlush(Unpooled.copiedBuffer(resp.getBytes())); } /*** 发生异常后的处理*/ @Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { cause.printStackTrace(); ctx.close(); } } 使用netty实现了个服务端,当接收到客户端的消息是,打印出来请求的内容,并统计接收请求的次数。 3、EchoClient public class EchoClient { private final int port; private final String host; public EchoClient(int port, String host) { this.port = port; this.host = host; } public void start() throws InterruptedException { EventLoopGroup group = new NioEventLoopGroup();/*线程组*/ try { final Bootstrap b = new Bootstrap(); /*客户端启动必须*/ b.group(group)/*将线程组传入*/ .channel(NioSocketChannel.class)/*指定使用NIO进行网络传输*/ .remoteAddress(new InetSocketAddress(host, port))/*配置要连接服务器的ip地址和端口*/ .handler(new ChannelInitializer<SocketChannel>() { protected void initChannel(SocketChannel ch) throws Exception { ch.pipeline().addLast(new EchoClientHandler()); } }); ChannelFuture f = b.connect().sync(); f.channel().closeFuture().sync(); } finally { group.shutdownGracefully().sync(); } } public static void main(String[] args) throws InterruptedException { new EchoClient(9999, "127.0.0.1").start(); } } 4、EchoClientHandler import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.SimpleChannelInboundHandler; import io.netty.util.CharsetUtil; import java.util.concurrent.atomic.AtomicInteger; public class EchoClientHandler extends SimpleChannelInboundHandler<ByteBuf> { private AtomicInteger counter = new AtomicInteger(0); /*** 客户端读取到网络数据后的处理*/ protected void channelRead0(ChannelHandlerContext ctx, ByteBuf msg) throws Exception { System.out.println("client Accept[" + msg.toString(CharsetUtil.UTF_8) + "] and the counter is:" + counter.incrementAndGet()); } /*** 客户端被通知channel活跃后,做事*/ @Override public void channelActive(ChannelHandlerContext ctx) throws Exception { ByteBuf msg = null; String request = "test1,test2,test3,test4" + System.getProperty("line.separator"); for (int i = 0; i < 100; i++) { msg = Unpooled.buffer(request.length()); msg.writeBytes(request.getBytes()); ctx.writeAndFlush(msg); } } /*** 发生异常后的处理*/ @Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { cause.printStackTrace(); ctx.close(); } } 使用netty实现了个客户端,链接建立完成之后向服务端发送消息。循环100次。并且打印服务端返回的消息。并统计返回次数。 执行结果 服务端输出 客户端打印 结果发现,我们客户单发送了100次数据,但实际上只接收了30次。而且每次消息发送的是test1,test2,test3,test4,test5,但实际接受的却有很多相链接起来的。这是为什么呢?为什么不是100次test1,test2,test3,test4,test5呢?这就是TCP传输的粘包/半包问题。 一、什么是TCP粘包半包? 假设客户端分别发送了两个数据包D1和D2给服务端,由于服务端一次读取到的字节数是不确定的,故可能存在以下4种情况。 服务端分两次读取到了两个独立的数据包,分别是D1和D2,没有粘包和拆包; 服务端一次接收到了两个数据包,D1和D2粘合在一起,被称为TCP粘包; 服务端分两次读取到了两个数据包,第一次读取到了完整的D1包和D2包的部分内容,第二次读取到了D2包的剩余内容,这被称为TCP拆包; 服务端分两次读取到了两个数据包,第一次读取到了D1包的部分内容D1_1,第二次读取到了D1包的剩余内容D1_2和D2包的整包。 如果此时服务端TCP接收滑窗非常小,而数据包D1和D2比较大,很有可能会发生第五种可能,即服务端分多次才能将D1和D2包接收完全,期间发生多次拆包。 二、TCP粘包/半包发生的原因 由于TCP协议本身的机制(面向连接的可靠地协议-三次握手机制)客户端与服务器会维持一个连接(Channel),数据在连接不断开的情况下,可以持续不断地将多个数据包发往服务器,但是如果发送的网络数据包太小,那么他本身会启用Nagle算法(可配置是否启用)对较小的数据包进行合并(基于此,TCP的网络延迟要UDP的高些)然后再发送(超时或者包大小足够)。那么这样的话,服务器在接收到消息(数据流)的时候就无法区分哪些数据包是客户端自己分开发送的,这样产生了粘包;服务器在接收到数据库后,放到缓冲区中,如果消息没有被及时从缓存区取走,下次在取数据的时候可能就会出现一次取出多个数据包的情况,造成粘包现象 UDP:本身作为无连接的不可靠的传输协议(适合频繁发送较小的数据包),他不会对数据包进行合并发送(也就没有Nagle算法之说了),他直接是一端发送什么数据,直接就发出去了,既然他不会对数据合并,每一个数据包都是完整的(数据+UDP头+IP头等等发一次数据封装一次)也就没有粘包一说了。 分包产生的原因就简单的多:可能是IP分片传输导致的,也可能是传输过程中丢失部分包导致出现的半包,还有可能就是一个包可能被分成了两次传输,在取数据的时候,先取到了一部分(还可能与接收的缓冲区大小有关系),总之就是一个数据包被分成了多次接收。 更具体的原因有三个,分别如下。 应用程序写入数据的字节大小大于套接字发送缓冲区的大小 进行MSS大小的TCP分段。MSS是最大报文段长度的缩写。MSS是TCP报文段中的数据字段的最大长度。数据字段加上TCP首部才等于整个的TCP报文段。所以MSS并不是TCP报文段的最大长度,而是:MSS=TCP报文段长度-TCP首部长 以太网的payload大于MTU进行IP分片。MTU指:一种通信协议的某一层上面所能通过的最大数据包大小。如果IP层有一个数据包要传,而且数据的长度比链路层的MTU大,那么IP层就会进行分片,把数据包分成托干片,让每一片都不超过MTU。注意,IP分片可以发生在原始发送端主机上,也可以发生在中间路由器上。 三、解决粘包半包问题 由于底层的TCP无法理解上层的业务数据,所以在底层是无法保证数据包不被拆分和重组的,这个问题只能通过上层的应用协议栈设计来解决,根据业界的主流协议的解决方案,可以归纳如下。 1、在包尾增加分割符 在包尾增加分割符,比如回车换行符进行分割,例如FTP协议; demo如下: LineBaseEchoServer public class LineBaseEchoServer { public static final int PORT = 9998; public static void main(String[] args) throws InterruptedException { LineBaseEchoServer lineBaseEchoServer = new LineBaseEchoServer(); System.out.println("服务器即将启动"); lineBaseEchoServer.start(); } public void start() throws InterruptedException { final LineBaseServerHandler serverHandler = new LineBaseServerHandler(); EventLoopGroup group = new NioEventLoopGroup();/*线程组*/ try { ServerBootstrap b = new ServerBootstrap();/*服务端启动必须*/ b.group(group)/*将线程组传入*/ .channel(NioServerSocketChannel.class)/*指定使用NIO进行网络传输*/ .localAddress(new InetSocketAddress(PORT))/*指定服务器监听端口*/ /*服务端每接收到一个连接请求,就会新启一个socket通信,也就是channel, 所以下面这段代码的作用就是为这个子channel增加handle*/ .childHandler(new ChannelInitializerImp()); ChannelFuture f = b.bind().sync();/*异步绑定到服务器,sync()会阻塞直到完成*/ System.out.println("服务器启动完成,等待客户端的连接和数据....."); f.channel().closeFuture().sync();/*阻塞直到服务器的channel关闭*/ } finally { group.shutdownGracefully().sync();/*优雅关闭线程组*/ } } private static class ChannelInitializerImp extends ChannelInitializer<Channel> { @Override protected void initChannel(Channel ch) throws Exception { //添加换行解码器 ch.pipeline().addLast(new LineBasedFrameDecoder(1024)); ch.pipeline().addLast(new LineBaseServerHandler()); } } } LineBaseEchoServer public class LineBaseEchoServer { public static final int PORT = 9998; public static void main(String[] args) throws InterruptedException { LineBaseEchoServer lineBaseEchoServer = new LineBaseEchoServer(); System.out.println("服务器即将启动"); lineBaseEchoServer.start(); } public void start() throws InterruptedException { final LineBaseServerHandler serverHandler = new LineBaseServerHandler(); EventLoopGroup group = new NioEventLoopGroup();/*线程组*/ try { ServerBootstrap b = new ServerBootstrap();/*服务端启动必须*/ b.group(group)/*将线程组传入*/ .channel(NioServerSocketChannel.class)/*指定使用NIO进行网络传输*/ .localAddress(new InetSocketAddress(PORT))/*指定服务器监听端口*/ /*服务端每接收到一个连接请求,就会新启一个socket通信,也就是channel, 所以下面这段代码的作用就是为这个子channel增加handle*/ .childHandler(new ChannelInitializerImp()); ChannelFuture f = b.bind().sync();/*异步绑定到服务器,sync()会阻塞直到完成*/ System.out.println("服务器启动完成,等待客户端的连接和数据....."); f.channel().closeFuture().sync();/*阻塞直到服务器的channel关闭*/ } finally { group.shutdownGracefully().sync();/*优雅关闭线程组*/ } } private static class ChannelInitializerImp extends ChannelInitializer<Channel> { @Override protected void initChannel(Channel ch) throws Exception { //添加换行解码器 ch.pipeline().addLast(new LineBasedFrameDecoder(1024)); ch.pipeline().addLast(new LineBaseServerHandler()); } } } LineBaseEchoClient public class LineBaseEchoClient { private final String host; public LineBaseEchoClient(String host) { this.host = host; } public void start() throws InterruptedException { EventLoopGroup group = new NioEventLoopGroup();/*线程组*/ try { final Bootstrap b = new Bootstrap(); b.group(group)/*将线程组传入*/ .channel(NioSocketChannel.class)/*指定使用NIO进行网络传输*/ .remoteAddress(new InetSocketAddress(host, LineBaseEchoServer.PORT))/*配置要连接服务器的ip地址和端口*/ .handler(new ChannelInitializerImp()); ChannelFuture f = b.connect().sync(); System.out.println("已连接到服务器....."); f.channel().closeFuture().sync(); } finally { group.shutdownGracefully().sync(); } } private static class ChannelInitializerImp extends ChannelInitializer<Channel> { @Override protected void initChannel(Channel ch) throws Exception { //回车符做了分割 ch.pipeline().addLast(new LineBasedFrameDecoder(1024)); ch.pipeline().addLast(new LineBaseClientHandler()); } } public static void main(String[] args) throws InterruptedException { new LineBaseEchoClient("127.0.0.1").start(); } } LineBaseClientHandler public class LineBaseClientHandler extends SimpleChannelInboundHandler<ByteBuf> { private AtomicInteger counter = new AtomicInteger(0); /*** 客户端读取到网络数据后的处理*/ protected void channelRead0(ChannelHandlerContext ctx, ByteBuf msg) throws Exception { System.out.println("client Accept[" + msg.toString(CharsetUtil.UTF_8) + "] and the counter is:" + counter.incrementAndGet()); ctx.close(); } /*** 客户端被通知channel活跃后,做事*/ @Override public void channelActive(ChannelHandlerContext ctx) throws Exception { ByteBuf msg = null; String request = "test1,test2,test3,test4,test5" + System.getProperty("line.separator"); for (int i = 0; i < 10; i++) { Thread.sleep(500); System.out.println(System.currentTimeMillis() + ":即将发送数据:" + request); msg = Unpooled.buffer(request.length()); msg.writeBytes(request.getBytes()); ctx.writeAndFlush(msg); } } /*** 发生异常后的处理*/ @Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { cause.printStackTrace(); ctx.close(); } } 执行效果 2、消息定长 例如每个报文的大小为固定长度200字节,如果不够,空位补空格; 服务端只需将服务端的ChannelInitializerImp 解码器new LineBasedFrameDecoder(1024)替换为new FixedLengthFrameDecoder( FixedLengthEchoClient.REQUEST.length())即可。 private static class ChannelInitializerImp extends ChannelInitializer<Channel> { @Override protected void initChannel(Channel ch) throws Exception { //添加定长报文长度解码器,长度问请求的长度 ch.pipeline().addLast( new FixedLengthFrameDecoder( FixedLengthEchoClient.REQUEST.length())); ch.pipeline().addLast(new FixedLengthServerHandler()); } } 3、将消息分为消息头和消息体 消息头中包含表示消息总长度(或者消息体长度)的字段,通常设计思路为消息头的第一个字段使用int32来表示消息的总长度。类似与第二条,只是我们按照头部的content-length长度进行定长解码。

优秀的个人博客,低调大师

cdy-mars V0.4 发布,高性能实时数据库

cdy-mars V0.4 已经发布,此版本更新内容包括: 1.优化网络网络传输,减少动态内存分配,减少GC时间。 2.Web API 接口功能丰富,增加在线帮助文档。 3.Bug修复。 Mars 数据库又名火星实时物联数据库,Mars 数据库整个分成开发、运行2个部分,两者之间相互独立。数据库的开发用于管理数据库支持的变量、安全信息、接口信息等;数据库的运行负责数据的采集、存储、对外提供实时、历史数据服务。 详情查看:https://gitee.com/chongdaoyang/mars/releases/V0.4

优秀的个人博客,低调大师

Gos Log V21.05.20 版本发布,高性能大日志检索中台

V21.05.20 版本更新内内容 ✅ 1、 上线Gos Log 官网https://goslog.dianjiu.org.cn ✅ 2、 优化并行查询速度,查询全部服务器理论耗时于单台服务相当 ✅ 3、 每次查询响应后自动清理临时文件,优化磁盘空间 ✅ 4、优化向下截取行可输入,解决默认1000行有时不够用的问题 版本地址 https://gitee.com/dianjiu/gos-log/releases/V21.05.20 https://github.com/dianjiu/gos-log/releases/V21.05.20 仓库地址 gos-log https://gitee.com/dianjiu/gos-log(opens new window) https://github.com/dianjiu/gos-log(opens new window) gos-log-vue https://gitee.com/dianjiu/gos-log-vue(opens new window) https://github.com/dianjiu/gos-log-vue 打包 #gos-log # 打包服务端 cd gos-log/logs bee pack -be GOOS=linux # 打包客户端 cd gos-log/logc bee pack -be GOOS=linux # 准备数据库 见gos-log项目下的sql文件夹 # 将打包后的文件上传到服务器指定目录 #gos-log-vue # 打包构建 yarn run build # 把dist目录下的文件上传到服务器的指定目录 #启动 #gos-log-logs # 解压缩 tar -zxf logs.tar.gz -C ./ # 授权 chmod -x logs # 修改数据库配置、临时目录 sudo vim conf/app.conf # 启动 nohup ./logs >> logs.log & #gos-log-logc # 解压缩 tar -zxf logc.tar.gz -C ./ # 授权 chmod -x logc # 修改临时目录 sudo vim conf/app.conf # 启动 nohup ./logc >> logc.log & #gos-log-vue # nginx部署如下nginx.conf server { listen 2022; server_name localhost; location / { root /web/gos-log/vue; index index.html index.htm; try_files $uri $uri/ /index.html; } location /api { rewrite ^/api/(.*)$ /$1 break; proxy_pass http://127.0.0.1:2021; } }

资源下载

更多资源
Mario

Mario

马里奥是站在游戏界顶峰的超人气多面角色。马里奥靠吃蘑菇成长,特征是大鼻子、头戴帽子、身穿背带裤,还留着胡子。与他的双胞胎兄弟路易基一起,长年担任任天堂的招牌角色。

腾讯云软件源

腾讯云软件源

为解决软件依赖安装时官方源访问速度慢的问题,腾讯云为一些软件搭建了缓存服务。您可以通过使用腾讯云软件源站来提升依赖包的安装速度。为了方便用户自由搭建服务架构,目前腾讯云软件源站支持公网访问和内网访问。

Nacos

Nacos

Nacos /nɑ:kəʊs/ 是 Dynamic Naming and Configuration Service 的首字母简称,一个易于构建 AI Agent 应用的动态服务发现、配置管理和AI智能体管理平台。Nacos 致力于帮助您发现、配置和管理微服务及AI智能体应用。Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据、流量管理。Nacos 帮助您更敏捷和容易地构建、交付和管理微服务平台。

Spring

Spring

Spring框架(Spring Framework)是由Rod Johnson于2002年提出的开源Java企业级应用框架,旨在通过使用JavaBean替代传统EJB实现方式降低企业级编程开发的复杂性。该框架基于简单性、可测试性和松耦合性设计理念,提供核心容器、应用上下文、数据访问集成等模块,支持整合Hibernate、Struts等第三方框架,其适用范围不仅限于服务器端开发,绝大多数Java应用均可从中受益。

用户登录
用户注册
修改密码
忘记密码