jetty9优化的两处地方
http://www.cnblogs.com/LBSer/p/3637387.html
jetty 9两个优化:
https://webtide.intalio.com/2013/01/jetty-9-goes-fast-with-mechanical-sympathy/?utm_source=tuicool
1. False Sharing in Queues
原先使用了 BlockingArrayQueue,这个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 false sharing”
解决方法:
“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 thisfalse sharing 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<E> extends AbstractList<E> implements BlockingQueue<E>
{
/**
* 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() - ;
/**
* 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 = ;
/**
* Default growth factor, 64.
*/
public static final int DEFAULT_GROWTH = ; 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 + ];
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)首先使用了TreeTrie,但是TreeTrie缺乏空间局部性,性能较差;2)之后使用ArrayTrie ,但是ArrayTrie 内存开销过大,当有成千上万请求时可能会造成GC问题;3)最终使用了 ArrayTernaryTrie(http://grepcode.com/file/repo1.maven.org/maven2/org.eclipse.jetty/jetty-util/9.1.0.v20131115/org/eclipse/jetty/util/ArrayTernaryTrie.java), ArrayTernaryTrie节省空间,且查找速度不低于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/
jetty9优化的两处地方的更多相关文章
- MySQL优化聊两句
原文地址:http://www.cnblogs.com/verrion/p/mysql_optimised.html MySQL优化聊两句 MySQL不多介绍,今天聊两句该如何优化以及从哪些方面入手, ...
- 手动更改WIN远程桌面端口,要改两个地方的注册表哟
看到我的服务器有老多人在用桌面连接,虽然进不去,但他们不停地试,浪费掉不少服务器资源,我看到网上有不少关于修改3389的介绍.修改3389的工具,一些工具一点用都没有,纯属扯淡.修改后照样是3389. ...
- 挺苹果的声音,iPhone 5s的两处进步
苹果iPhone 5s发布后的两处重大进步让我很关注,但看了网上众多网友的点评,又深深的被中国当前手机发烧友圈的这种屌丝文化所震撼,这不是一条正确的道路,这将把中国的手机产业引向歧途,所以我不得不说几 ...
- [代码审计]phpshe开源商城后台两处任意文件删除至getshell
0x00 背景 这套系统审了很久了,审计的版本是1.6,前台审不出个所以然来.前台的限制做的很死. 入库的数据都是经过mysql_real_escape_string,htmlspecialchars ...
- 有两个地方,用到了javabean对象和属性字符串值之间的转换
1.有两个地方,用到了javabean对象和属性字符串值之间的转换 2.一个是接入层spring mvc,将json字符串参数转换为javaBean.通过@RequestBody javaBean方式 ...
- 使用 CUDA 进行计算优化的两种思路
前言 本文讨论如何使用 CUDA 对代码进行并行优化,并给出不同并行思路对均值滤波的实现. 并行优化的两种思路 思路1: global 函数 在 global 函数中创建出多个块多个线程对矩阵每个元素 ...
- Makefile 中会在多处地方看到 FORCE
转载:http://blog.csdn.net/wzw88486969/article/details/11739737 在内核的 Makefile 中会在多处地方看到 FORCE ,比如: # vm ...
- 第七篇:使用 CUDA 进行计算优化的两种思路
前言 本文讨论如何使用 CUDA 对代码进行并行优化,并给出不同并行思路对均值滤波的实现. 并行优化的两种思路 思路1: global 函数 在 global 函数中创建出多个块多个线程对矩阵每个元素 ...
- 人不能同时在两个地方做猪(Scrum Team)
在一个神奇的国度里生活着许多动物, 其中有猪, 鸡, 和鹦鹉. 它们每天搞头脑风暴, 琢磨如何创业, 最后鹦鹉提议它们合伙开一个早餐店: 具体分工如下: 猪: 提供猪肉, 做熏猪肉 (bacon) 鸡 ...
随机推荐
- 论文笔记(3)-Extracting and Composing Robust Features with Denoising Autoencoders
这篇文章是Bengio研究的在传统的autoencoder基础上增加了噪声参数,也就是说在输入X的时候,并不直接用X的数据,而是按照一定的概率来清空输入为0.paper中的名词为corrupted.这 ...
- HttpClient4.X发送Get请求的url参数拼接
HttpClient4.X发送Get请求的参数拼接 使用httpClient发送get请求时,请求参数可以以?key=val&key1=val1的拼接到url后面. 但是请求参数较多时,这种方 ...
- window2012如何查看进程中PID所对应的IIS应用程序池
1.打开任务管理器,找到任意IIS进程,右击选择打开文件位置,获取到文件路径,例如:C:\Windows\System32\inetsrv 2.使用管理员打开cmd命令行工具,然后切换到刚才获取到文件 ...
- 反射获取属性DisplayName特性名字以及属性值
/// <summary> /// 反射获取所有DisplayName标记值 /// </summary> /// <typeparam name="T&quo ...
- mysql之使用centos7实现主从复制(读写分离)的实现过程
什么是主从复制? 主从复制,是用来建立一个和主数据库完全一样的数据库环境,称为从数据库:主数据库一般是准实时的业务数据库. 主从复制的作用(好处)! 1.做数据的热备,作为后备数据库,主数据库服务器故 ...
- web请求的状态码
摘录于 https://www.cnblogs.com/lovychen/p/6256343.html 1xx消息 这一类型的状态码,代表请求已被接受,需要继续处理.这类响应是临时响应,只包含状态行 ...
- jqury的ajax
前端代码: <%@ page language="java" contentType="text/html; charset=UTF-8" pageEnc ...
- Text and Binary modes
http://perlmaven.com/what-is-a-text-file https://cygwin.com/cygwin-ug-net/using-textbinary.html Text ...
- beyondCompare试用期到期解决办法
找到beyond Compare 4文件夹下面的BCUnrar.dll,将其删掉或者重命名,再重新打开接着使用! 我这是转的,到期之后试试.
- 微信小程序与vueJs的异同
简而言之,所有的框架都是建立在原生javascript基础之上的,所以对于有一定js基础的同学来说,各种框架都是比较容易入手的,但不同的框架之间又有一定的差别,有时候切换使用时就会掉入坑了. 一.微信 ...