基于mina架构的JTT808协议两种解码方式性能比较
来源:互联网 发布:美工30岁后能转型 编辑:程序博客网 时间:2024/06/06 15:11
方案一继承CumulativeProtocolDecoder,实现doDecode方法进行解码;
方案二继承ProtocolDecoder ,实现decode方法进行解码;
在一台普通pc机(默认配置的Eclipse中直接运行测试程序)上测试客户端2k并发,方案一35分钟勉强达到达到150W数量,方案二只用了32分钟就已经达到150W数量。
方案一:
public class JTT808CodecDecoder extends CumulativeProtocolDecoder {<pre name="code" class="java"> ……(此处省略N行代码)protected boolean doDecode(IoSession session, IoBuffer in, ProtocolDecoderOutput out)throws Exception { boolean matched=false; int start=in.position(); int limit=in.limit(); while (in.hasRemaining()) { byte b=in.get(); if(!matched){ if(b==JTT808Message.FLAG){ matched=true; start=in.position()-1; } continue; } if(b!=JTT808Message.FLAG) continue; int pos = in.position(); try{ if(in.hasRemaining()){ b=in.get(); in.position(start); in.limit(pos); if(b==JTT808Message.FLAG){ decode(in,out); }else{ illegalMessage(in); } }else{ in.position(start); in.limit(pos); decode(in,out); } }catch(Exception e){ illegalMessage(in); logger.error(e.getMessage(),e); }finally{ in.limit(limit); in.position(pos); } return true; } if(matched){ in.limit(limit); in.position(start); return false; } return true; } private void decode(IoBuffer buf,ProtocolDecoderOutput out){ int size=buf.limit()-buf.position(); byte[] bytes = new byte[size]; buf.get(bytes,0, bytes.length);
<span style="white-space:pre"></span>……(此处省略N行代码)
<span style="white-space:pre"></span>……(此处省略N行代码)
public class JTT808CodecDecoder implements ProtocolDecoder { ……(此处省略N行代码)//此解码方式性能更高public void decode(IoSession session, IoBuffer in, ProtocolDecoderOutput out)throws Exception { Context ctx = getContext(session); boolean mark=false; if(ctx.getBuf().position()>0){ if(ctx.getBuf().get(0)==JTT808Message.FLAG){ mark=true; }else{ ctx.getBuf().clear(); } } while (in.hasRemaining()) { byte b=in.get(); ctx.getBuf().put(b); if(b!=JTT808Message.FLAG) continue; if(mark){ if(in.hasRemaining()){ b=in.get(); if(b==JTT808Message.FLAG){ decode(ctx.getBuf(),out); }else{ logger.error("illegal message:"+bytesToHexString(ctx.getBuf().array())); out.write("-1"); } ctx.getBuf().clear(); ctx.getBuf().put(b); mark=true; }else{ decode(ctx.getBuf(),out); ctx.getBuf().clear(); } }else{ mark=true; } } }private void decode(IoBuffer buf,ProtocolDecoderOutput out){int size=buf.position();buf.flip();byte[] bytes = new byte[size];buf.get(bytes); ……(此处省略N行代码) }
……(此处省略N行代码)}
0 0
- 基于mina架构的JTT808协议两种解码方式性能比较
- mina两种协议获取方式(TCP/UDP)
- HashMap 遍历的两种方式及性能比较
- 几种基于HTTP协议的RPC性能比较
- 基于两种方式的cs架构开发技术
- 基于mina的应用架构
- MINA 协议解码过滤器
- 转:几种基于HTTP协议的RPC性能比较,以及ICE接口性能测试比较
- gps两种解码的方式
- reuqest 两种请求方式的解码
- 基于MINA的网络应用程序架构
- 计算斐波那契数列的两种常用方式的性能比较
- Tomcat的四种基于HTTP协议的Connector性能比较
- Tomcat 6 支持 NIO -- Tomcat的四种基于HTTP协议的Connector性能比较
- Tomcat 6 支持 NIO -- Tomcat的四种基于HTTP协议的Connector性能比较
- Tomcat的四种基于HTTP协议的Connector性能比较
- Tomcat 6 支持 NIO -- Tomcat的四种基于HTTP协议的Connector性能比较
- Tomcat的四种基于HTTP协议的Connector性能比较
- makefile变量使用
- C# 禁止windows程序重复运行的两种基本方法
- 第二章线性表的总结
- android4.3以后的截屏笔记
- ubuntu修复启动项
- 基于mina架构的JTT808协议两种解码方式性能比较
- Strace命令使用
- Android网络阅读器_jsoup解析应用
- USACO 1.3 Barn Repair (动态规划再写次)
- IDispatch接口 - GetIDsOfNames和Invoke
- 日语学习之沪江N4基础 20141126 -3
- 数据库设计范式实例解析
- 【GitHub上的ios经典库库、学习资料】iOS frameworks, libraries, tutorials, xcode plugins and components.
- 快速排序