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优化的两处地方的更多相关文章

  1. MySQL优化聊两句

    原文地址:http://www.cnblogs.com/verrion/p/mysql_optimised.html MySQL优化聊两句 MySQL不多介绍,今天聊两句该如何优化以及从哪些方面入手, ...

  2. 手动更改WIN远程桌面端口,要改两个地方的注册表哟

    看到我的服务器有老多人在用桌面连接,虽然进不去,但他们不停地试,浪费掉不少服务器资源,我看到网上有不少关于修改3389的介绍.修改3389的工具,一些工具一点用都没有,纯属扯淡.修改后照样是3389. ...

  3. 挺苹果的声音,iPhone 5s的两处进步

    苹果iPhone 5s发布后的两处重大进步让我很关注,但看了网上众多网友的点评,又深深的被中国当前手机发烧友圈的这种屌丝文化所震撼,这不是一条正确的道路,这将把中国的手机产业引向歧途,所以我不得不说几 ...

  4. [代码审计]phpshe开源商城后台两处任意文件删除至getshell

    0x00 背景 这套系统审了很久了,审计的版本是1.6,前台审不出个所以然来.前台的限制做的很死. 入库的数据都是经过mysql_real_escape_string,htmlspecialchars ...

  5. 有两个地方,用到了javabean对象和属性字符串值之间的转换

    1.有两个地方,用到了javabean对象和属性字符串值之间的转换 2.一个是接入层spring mvc,将json字符串参数转换为javaBean.通过@RequestBody javaBean方式 ...

  6. 使用 CUDA 进行计算优化的两种思路

    前言 本文讨论如何使用 CUDA 对代码进行并行优化,并给出不同并行思路对均值滤波的实现. 并行优化的两种思路 思路1: global 函数 在 global 函数中创建出多个块多个线程对矩阵每个元素 ...

  7. Makefile 中会在多处地方看到 FORCE

    转载:http://blog.csdn.net/wzw88486969/article/details/11739737 在内核的 Makefile 中会在多处地方看到 FORCE ,比如: # vm ...

  8. 第七篇:使用 CUDA 进行计算优化的两种思路

    前言 本文讨论如何使用 CUDA 对代码进行并行优化,并给出不同并行思路对均值滤波的实现. 并行优化的两种思路 思路1: global 函数 在 global 函数中创建出多个块多个线程对矩阵每个元素 ...

  9. 人不能同时在两个地方做猪(Scrum Team)

    在一个神奇的国度里生活着许多动物, 其中有猪, 鸡, 和鹦鹉. 它们每天搞头脑风暴, 琢磨如何创业, 最后鹦鹉提议它们合伙开一个早餐店: 具体分工如下: 猪: 提供猪肉, 做熏猪肉 (bacon) 鸡 ...

随机推荐

  1. Python学习-26.Python中的三角函数

    Python中的三角函数位于math模块内. 引入模块: import math 输出pi import math print(math.pi) 得:3.141592653589793 math模块内 ...

  2. IocPerformance 常见IOC 功能、性能比较

    IocPerformance IocPerformance 基本功能.高级功能.启动预热三方面比较各IOC,可以用作选型参考. Lamar: StructureMap的替代品 Lamar 文档 兼容S ...

  3. 构建NetCore应用框架之实战篇(二):BitAdminCore框架定位及架构

    本篇承接上篇内容,如果你不小心点击进来,建议重新从第一篇开始完整阅读. 构建NetCore应用框架之实战篇索引 一.BitAdminCore框架简介 从前篇论述我们知道,我们接下来将要去做一个管理系统 ...

  4. 用 vs 2017创建 windows 服务

    转载自:http://www.cnblogs.com/xujie/p/5695673.html 1.新建windows服务项目,我这里选择的是Framework4.0,没有选择高版本是为了防止在服务在 ...

  5. Unity的Shader如何控制投影颜色

    细节慢慢补充,有几个需要注意的地方,必须要有接收投影的pass也就是Name是ShadowCollector的,必须添加#pragma multi_compile_fwdbase,物体的着色器必须有T ...

  6. day 75天 bbs 项目第一天 ,auth登陆

    from django.db import models from django.contrib.auth.models import AbstractUser class UserInfo(Abst ...

  7. AGC032D Rotation Sort

    题目传送门 Description 给定\(N\)的排列(\(N\leq5000\)),将任一区间最左侧的数插到该区间最右边的代价为\(A\),将任一区间最右侧的数插到该区间最左边的代价为\(B\), ...

  8. Statement与PreparedStatement区别

    1.性能区别 Statement statement = conn.createStatement(); PreparedStatement preStatement = conn.prepareSt ...

  9. 双向链表的实现——java

    实现类: /** * Java 实现的双向链表. * 注:java自带的集合包中有实现双向链表,路径是:java.util.LinkedList * * @author skywang * @date ...

  10. 转载:不定义JQuery插件,不要说会JQuery

    转载:http://www.cnblogs.com/xcj26/p/3345556.html 一:导言 有些WEB开发者,会引用一个JQuery类库,然后在网页上写一写$("#") ...