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
Ø 應用使用了多進程接收鏈接