Archive

Archive for March, 2013

lz4: Extremely Fast Compression algorithm

March 15th, 2013 9 comments

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

本文链接地址: lz4: Extremely Fast Compression algorithm

最近在不少项目特别是存储相关的项目用到了lz4压缩算法,它有什么特点呢?

LZ4 is a very fast lossless compression algorithm, providing compression speed at 300 MB/s per core, scalable with multi-cores CPU. It also features an extremely fast decoder, with speeds up and beyond 1GB/s per core, typically reaching RAM speed limits on multi-core systems.

这个特性对于需要大吞吐量的压缩场合还是非常有用的,以很小的CPU代价换来更大的存储密度。

官方网站:https://code.google.com/p/lz4/, 摘抄下它的性能指标:

Name Ratio C.speed D.speed
LZ4 (r59) 2.084 330 915
LZO 2.05 1x_1 2.038 311 480
QuickLZ 1.5 -1 2.233 257 277
Snappy 1.0.5 2.024 227 729
LZF 2.076 197 465
FastLZ 2.030 190 420
zlib 1.2.5 -1 2.728 39 195
LZ4 HC (r66) 2.712 18 1020
zlib 1.2.5 -6 3.095 14 210

更多的测试可以看 这里 这里

它还有个高压缩率的版本:

LZ4 HC – High Compression Mode of LZ4

从源码lz4.c可以看到快的原因之一:
lz4

这个技术叫做 “The Blocking Technique”, 见图:
bt

考虑在项目中用起来。

祝玩得开心!

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

Categories: Linux, 杂七杂八, 源码分析 Tags:

Linux下如何知道文件被那个进程写

March 12th, 2013 36 comments

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

本文链接地址: Linux下如何知道文件被那个进程写

晚上朔海同学问:

一个文件正在被进程写 我想查看这个进程 文件一直在增大 找不到谁在写 使用lsof也没找到

这个问题挺有普遍性的,解决方法应该很多,这里我给大家提个比较直观的方法。

linux下每个文件都会在某个块设备上存放,当然也都有相应的inode, 那么透过vfs.write我们就可以知道谁在不停的写入特定的设备上的inode。
幸运的是systemtap的安装包里带了inodewatch.stp,位于/usr/local/share/doc/systemtap/examples/io目录下,就是用来这个用途的。
我们来看下代码:

$ cat inodewatch.stp 
#! /usr/bin/env stap

probe vfs.write, vfs.read
{
  # dev and ino are defined by vfs.write and vfs.read
  if (dev == MKDEV($1,$2) # major/minor device
      && ino == $3)
    printf ("%s(%d) %s 0x%x/%u\n",
      execname(), pid(), probefunc(), dev, ino)
}

这个脚本的使用方法如下: stap inodewatch.stp major minor ino

下面我们构造个场景: dd不停的写入一个文件,查出这个文件的ino, 以及它所在设备的major, minor, 运行stap脚本就可以得到答案。

Read more…

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

Categories: Linux, 工具介绍 Tags: , ,

ulimit限制之nproc问题

March 2nd, 2013 4 comments

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

本文链接地址: ulimit限制之nproc问题

前两天微博上的@王关胜同学问了个问题:

#ulimit问题# 关于nproc设置:centos6,内核版本是2.6.32. 默认情况下,ulimit -u的值为1024,是/etc/security/limits.d/90-nproc.conf的值限制;注释掉这个限制后,值为95044;手工设置90-nproc.conf文件,值为新设置的值。想请 问这个95044是怎么来的?

这个问题挺有意思的,这里面有二个信息点:

1. 为什么limit配置文件是 /etc/security/limits.d/90-nproc.conf 而不是其他?
2. 为什么是nproc的值95044,而不是其他。

之前我也写了些ulimit的问题的解决,参见 这里

我们来简单的做下实验:

$ cat /etc/security/limits.d/90-nproc.conf          
*      soft    nproc   8933
$ ulimit -u
8933

$ cat /etc/security/limits.d/90-nproc.conf      #注释掉
#*      soft    nproc   8933
$ ulimit -u
385962

我们可以看出就是说当注释掉限制的话,不同的机器值是不同的。

我们先来回答第一个问题:为什么limit配置文件是 /etc/security/limits.d/90-nproc.conf 而不是其他
这个问题早些时候 杨德华 同学碰到了,也写了篇 博文 来解释redhat6下面如何破解nproc的限制,但是文章没提到这个问题。
Read more…

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

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

开源压缩算法Zopfli介绍

March 1st, 2013 1 comment

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

本文链接地址: 开源压缩算法Zopfli介绍

谷歌近日推出了全新开源压缩算法Zopfli, 官方主页在 这里,相关文档在 这里

Zopfli is a new deflate compatible compressor that was inspired by compression improvements
developed originally for the lossless mode of WebP image compression. Being compatible with
deflate makes Zopfli compatible with zlib and gzip. Most internet browsers support deflate
decompression, and it has a wide range of other applications. This means that Zopflicompatible
decompression is readily widely available.

二个特点:
1. The output produced by Zopfli is 3.7–8.3 % smaller than that of gzip 9.
2. Zopfli is 81 times slower than the fastest measured algorithm gzip 9.

最大的特点是压缩好的数据和zip兼容,也就是说目前标准的zip uncompress算法都能解开,看起来比较适合web服务器的数据存储,降低成本,虽然只有3-8%点的提高,但是数据规模大了,还是很可观的。

下载源码,编译得到zopfli:

$ ./zopfli  -h
Usage: zopfli [OPTION]... FILE
  -h    gives this help
  -c    write the result on standard output, instead of disk filename + '.gz'
  -v    verbose mode
  --gzip  output to gzip format (default)
  --deflate  output to deflate format instead of gzip
  --zlib  output to zlib format instead of gzip
  --i5  less compression, but faster
  --i10  less compression, but faster
  --i15  default compression, 15 iterations
  --i25  more compression, but slower
  --i50  more compression, but slower
  --i100  more compression, but slower
  --i250  more compression, but slower
  --i500  more compression, but slower
  --i1000  more compression, but slower

祝玩得开心。

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

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

记录下过去2年多去过的地方

March 1st, 2013 5 comments

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

本文链接地址: 记录下过去2年多去过的地方

截止2013-03-01 at 5.31.17 PM 旅行过的地方

旅行开阔视野。

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

Categories: 生活 Tags:

Understanding Linux CPU Load 资料汇总

March 1st, 2013 3 comments

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

本文链接地址: Understanding Linux CPU Load 资料汇总

最近关注线上CPU load的人挺多,很多人觉得load太高系统就有问题,就想各种办法来折腾。其实在我看来load只是系统CPU运行队列的在运行进程数的近似值, 如下图:
load

对于Unix发展的初期,机器的性能比较差,CPU核数也少,参考意义比较大。现在的机器都是非常强悍的,CPU,内存,IO各个部件都可以并行运作,这个load相应的就应该和机器的变化相应的变大,我觉得很正常,无需担心,反而应该把注意力放到服务的QPS和RT才是王道。

在微博上讨论了一下午CPU Load,收到非常多的反馈,这里我顺手整理下方便大家:

1. Understanding Linux CPU Load – when should you be worried? 谢谢@nizen靖
参考: 这里 中文版

2. Understanding Linux Load Average 谢谢 @jametong
参考:part1 part2 part3

3. UNIX Load Average 谢谢 @jametong
参考:part1 part2 part3

4. Loadavg问题分析 谢谢 @淘木名、 @淘伯瑜、 @何_登成
参考 这里

小结:群众的力量无穷,很短的时间内挖出这么多有意义的材料。

祝玩得开心!

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

Categories: Linux, 杂七杂八 Tags: