Fastsocket 是一个高扩展性的 Socket 以及 Linux 内核的底层网络实现。能够在多核机器上提供极好的性能,此外使用和维护还很是简单。目前该项目已经在新浪的生产环境中使用。该项目由清华大学和新浪网联合组成的 Fastos 团队开发,该团队的使命是提高 Linux 内核的效率。nginx
Fastsocket 目前已经使用在新浪微博的生产环境上,主要用于提供负载均衡服务的 HAProxy,线上实际性能提高一倍,从2014年3月份稳定运行至今,预计2014年末完成负载均衡所有集群的 Fastsocket 升级。git
Fastsocket 彻底兼容 BSD Socket API,现有各种基于 Socket 的网络应用能够直接使用 Fastsockt。 目前通过兼容测试的经常使用服务软件有:HAProxy、Nginx、Lighttpd、Redis 和 Memcached。github
项目地址:https://github.com/fastos/fastsocketbash
安装编译:网络
[root@localhost ~]# git clone https://github.com/fastos/fastsocket.git [root@localhost ~]# cd fastsocket/kernel [root@localhost kernel]# make defconfig [root@localhost kernel]# make [root@localhost kernel]# make modules_install [root@localhost kernel]# make install
Enter the library directory and make the library:负载均衡
[root@localhost fastsocket]# cd library [root@localhost library]# make
After that, libfsocket.so is created in the same directory.socket
使用方法:tcp
使用fastsocket启动nginx性能
[root@localhost fastsocket]# cd library [root@localhost library]# LD_PRELOAD=./libfsocket.so nginx
不使用fastsocket 启动nginx测试
[root@localhost ~]# nginx
在fastsocket主要由一个内核模块和一个用户态动态连接库,经过LD_PRELOAD拦截系统调用,通过libfsocket.so处理后,采用ioctl的形式和fastsocket内核模块进行通讯,内核模块进行实际的优化工做。
fastsocket是一个fastos的一个网络方面的优化,由新浪开源。fastsocket主要优化内核中的accept由于锁而致使的串行,对于短链接会极大的提升其性能,cpu核越多性能提高越明显。基于内核模块和一个动态连接库,对于某些应用程序不需修改就可以使用。可是并不是全部应用都能经过fastsocket得到性能提高。
适用场景:
Ø 系统至少很多于8个cpu
Ø 系统的很大一部分开销用于处理网络软中断以及socket相关系统调用
Ø tcp短链接不少
Ø 应用使用了epool处理网络io
Ø 应用使用了多进程接收链接