博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
jetty9优化的两处地方
阅读量:5789 次
发布时间:2019-06-18

本文共 3104 字,大约阅读时间需要 10 分钟。

jetty 9两个优化:

https://webtide.intalio.com/2013/01/jetty-9-goes-fast-with-mechanical-sympathy/?utm_source=tuicool

1. False Sharing in Queues

原先使用了 ,这个queue有头尾两个指针,生产和消费是独立的,但是会产生这样一个问题;“However because of the layout in memory of the class, it turned out that the head and tail pointers and locks were all within a single CPU cache row。This is bad because when different threads running on different cores are trying to independently work on the head and tail, it turns out that they are both hitting the same area of memory and are thus repeatedly invalidating each others caches in a pattern called ”

解决方法:

“The solution is to be aware of the memory layout of the class when considering what threads will be accessing which fields and to space them out so that you can avoid this of cache rows. ”

从代码上看(http://git.eclipse.org/c/jetty/org.eclipse.jetty.project.git/tree/jetty-util/src/main/java/org/eclipse/jetty/util/BlockingArrayQueue.java):

public class BlockingArrayQueue
extends AbstractList
implements BlockingQueue
{ /** * The head offset in the {@link #_indexes} array, displaced by 15 slots to avoid false sharing with the array length (stored before the first element of * the array itself). */ private static final int HEAD_OFFSET = MemoryUtils.getIntegersPerCacheLine() - 1; /** * The tail offset in the {@link #_indexes} array, displaced by 16 slots from the head to avoid false sharing with it. */ private static final int TAIL_OFFSET = HEAD_OFFSET + MemoryUtils.getIntegersPerCacheLine(); /** * Default initial capacity, 128. */ public static final int DEFAULT_CAPACITY = 128; /** * Default growth factor, 64. */ public static final int DEFAULT_GROWTH = 64; private final int _maxCapacity; private final int _growCapacity; /** * Array that holds the head and tail indexes, separated by a cache line to avoid false sharing */ private final int[] _indexes = new int[TAIL_OFFSET + 1]; private final Lock _tailLock = new ReentrantLock(); private final AtomicInteger _size = new AtomicInteger(); private final Lock _headLock = new ReentrantLock(); private final Condition _notEmpty = _headLock.newCondition(); private Object[] _elements;...}

 

2. Time and Space Efficient Trie

  解析HTTP Header的时候,我们常常需要将在ByteBuffer的数据(ByteBuffer不在jvm内存中)转换成String类,通常还放到一个hashmap中,这样会产生大量的开销(创建对象耗时,内存消耗)。jetty9为了不将ByteBuffer的数据进行转换,不采用hashmap,而使用trie这种数据结构。

  jetty代码提交者们使用了不同类型的trie进行尝试。1)首先使用了,但是缺乏空间局部性,性能较差;2)之后使用 ,但是 内存开销过大,当有成千上万请求时可能会造成GC问题;3)最终使用了 (http://grepcode.com/file/repo1.maven.org/maven2/org.eclipse.jetty/jetty-util/9.1.0.v20131115/org/eclipse/jetty/util/ArrayTernaryTrie.java), 节省空间,且查找速度不低于hashmap。

 

3. 性能评测

  “Thus for a small increase in static heap usage (0.5MB in the static Tries), jetty-9 out performs jetty-8 by 30% faster (33.5s vs 48.6s) and 50% less YG garbage (1409MB vs 2914MB) which trigger less than half the YG collections.”

 

ternary-search-tree参考文献:

http://igoro.com/archive/efficient-auto-complete-with-a-ternary-search-tree/

转载地址:http://ywhyx.baihongyu.com/

你可能感兴趣的文章
C#常见错误解决方法
查看>>
安装cnpm (npm淘宝镜像)
查看>>
Java 面向对象(基础) 知识点总结I
查看>>
读书笔记《自控力》
查看>>
基于神念TGAM的脑波小车(1)
查看>>
ceph集群搭建Jewel版本
查看>>
HttpClient 解释
查看>>
111111
查看>>
在Button上面显示图片,去掉Button的默认样式
查看>>
区域生长算法
查看>>
(转)json+flexgrid+jbox组合运用页面刷新<jsp>
查看>>
hive学习2(Navicat连接hive)
查看>>
getResourceAsStream的3种路径配置
查看>>
switch语句小练习
查看>>
组合逻辑电路
查看>>
POP-一个点击带有放大还原的动画效果
查看>>
个人阅读作业2
查看>>
UE4材质是什么样的机制
查看>>
使用QTP录制自带Flight小实例
查看>>
JProfiler学习笔记
查看>>