Archive

Archive for the ‘源码分析’ Category

leveldb性能分析和表现

May 30th, 2011 21 comments

原创文章,转载请注明: 转载自系统技术非业余研究

本文链接地址: leveldb性能分析和表现

Leveldb是一个google实现的非常高效的kv数据库,目前的版本1.2能够支持billion级别的数据量了。 在这个数量级别下还有着非常高的性能,主要归功于它的良好的设计。特别是LSM算法。

那么数据库最怕的的随机IO他是如何解决的呢?

先说随机写,它的写都是先记录到日志文件去的,在日志文件满之前只是简单的更新memtable,那么就把随机写转化成了顺序写。在日志满了后,把日志里面的数据排序写成sst表同时和之前的sst进行合并,这个动作也是顺序读和写。大家都知道传统磁盘raid的顺序读写吞吐量是很大的,100M左右是没有问题。在写日志文件的时候,用到是buffer IO,也就是说如果操作系统有足够的内存,这个读写全部由操作系统缓冲,效果非常好。即使是sync写模式,也是以数据累计到4K为一个单位写的,所以效率高。

那么随机读呢?这个它解决不了。但是ssd盘最擅长随机读了。这个硬件很自然的解决了这个问题。

所以leveldb的绝配是ssd盘的raid.
Read more…

Post Footer automatically generated by wp-posturl plugin for wordpress.

Categories: Linux, 源码分析, 调优 Tags:

Snappy(Google家用的快速压缩算法,以前的Zippy)

March 23rd, 2011 4 comments

原创文章,转载请注明: 转载自系统技术非业余研究

本文链接地址: Snappy(Google家用的快速压缩算法,以前的Zippy)

刚刚雕梁同学告诉我google刚刚开源了他自己家用的快速压缩算法,AKA Zippy, 看来下貌似不错。

项目主页: http://code.google.com/p/snappy/

Snappy is a compression/decompression library. It does not aim for maximum compression, or compatibility with any other compression library; instead, it aims for very high speeds and reasonable compression. For instance, compared to the fastest mode of zlib, Snappy is an order of magnitude faster for most inputs, but the resulting compressed files are anywhere from 20% to 100% bigger. On a single core of a Core i7 processor in 64-bit mode, Snappy compresses at about 250 MB/sec or more and decompresses at about 500 MB/sec or more.

Snappy is widely used inside Google, in everything from BigTable and MapReduce to our internal RPC systems. (Snappy has previously been referred to as “Zippy” in some presentations and the likes.)

Read more…

Post Footer automatically generated by wp-posturl plugin for wordpress.

Linux下异步IO(libaio)的使用以及性能

March 21st, 2011 19 comments

原创文章,转载请注明: 转载自系统技术非业余研究

本文链接地址: Linux下异步IO(libaio)的使用以及性能

Linux下异步IO是比较新的内核里面才有的,异步io的好处可以参考这里.
但是文章中aio_*系列的调用是glibc提供的,是glibc用线程+阻塞调用来模拟的,性能很差,千万千万不要用。

我们今天要说的是真正的原生的异步IO接口. 由于这几个系统调用glibc没有提供相应的封装,所以libaio来救急了:
Read more…

Post Footer automatically generated by wp-posturl plugin for wordpress.

推介xz高压缩率算法

March 17th, 2011 8 comments

原创文章,转载请注明: 转载自系统技术非业余研究

本文链接地址: 推介xz高压缩率算法

这几天看到Linux内核2.6.38发布的release说明里面提到:

The version .38 kernel comes with a library for decompressing XZ, a format developed from LZMA and known for its high levels of compression. This library is the basis not only for SquashFS, which now also offers XZ, but also for code that allows the kernel to unpack any parts of itself and of the initial ram disks (initrds) that were compressed with XZ.

觉得比较好奇, Linux下有那么多的压缩算法, 为什么要用这个, 它有什么过人之处? 今天深入了解了下xz, 顺便作了简单的benchmark体验了下.
Read more…

Post Footer automatically generated by wp-posturl plugin for wordpress.

Linux 2.6.38 User-space interface for Crypto API

March 16th, 2011 1 comment

原创文章,转载请注明: 转载自系统技术非业余研究

本文链接地址: Linux 2.6.38 User-space interface for Crypto API

Linux内核里面自带非常多的加密模块,这是模块经过调优性能非常高, 而且现在又很多硬件本身支持加密功能,比如intel的CPU支持AES加密指令,那些内核的那帮人知道更好如何利用这些硬件更快的完成加密功能的, 他们写的这些硬件的驱动在drivers/crypto目录里. 所以如果我们能在用户空间的应用程序中用到这些加密库有二个好处: 1. 无须再造轮子. 2. 性能高.

幸运的是2.6.38的内核给我们带来了这些功能. 这些功能是通过socket方式暴露的,思路非常独特优雅,同时由于支持gather write, scatter read, 无须拷贝数据,性能应该非常高.
Read more…

Post Footer automatically generated by wp-posturl plugin for wordpress.

fastsearch快速字符串查找算法

March 15th, 2011 Comments off

原创文章,转载请注明: 转载自系统技术非业余研究

本文链接地址: fastsearch快速字符串查找算法

最近在做一个项目需要涉及到快速的字符串匹配,每秒几十万次的那种。之前我用过linux内核的的textsearch库的KMP,BM,FSM的算法觉得还不错,这几个算法用于Linux网络模块的关键词过滤系统,支持非线性的字符查找,但是对性能还是不够印象深刻。于是我想起了python的fastsearch. Python这样的脚本语言字符查找用的非常的密集,所以这个算法是非常的高效的,可以说这个算法很大程度影响着python的性能。我们来看下 作者的网站 怎么说的:
Read more…

Post Footer automatically generated by wp-posturl plugin for wordpress.

Linux下pstack的实现

November 28th, 2010 11 comments

原创文章,转载请注明: 转载自系统技术非业余研究

本文链接地址: Linux下pstack的实现

Linux下有时候我们需要知道一个进程在做什么,比如说程序不正常的时候,他到底在干吗?最直接的方法就是打印出他所有线程的调用栈,这样我们从栈再配合程序代码就知道程序在干吗了。
Linux下这个工具叫做pstack. 使用方法是

# pstack
Usage: pstack <process-id>

当然这个被调查的程序需要有符号信息。 比较雷人的是 这个程序竟然是个shell脚本,核心实现是gdb的 thread apply all bt, 我们可以观摩下他的实现,这个我们做类似的程序提供了一个很好的思路:
Read more…

Post Footer automatically generated by wp-posturl plugin for wordpress.

Categories: Linux, 工具介绍, 源码分析 Tags: ,