android io调度算法,内核的四种IO调度算法

深入理解Linux IO调度算法:noop、anticipatory、deadline与cfq
本文详细介绍了Linux内核中的四种IO调度算法:noop、anticipatory、deadline和cfq。针对每种算法的工作原理进行了详细解释,并提供了如何临时和永久更改IO调度器的方法。此外,还探讨了网络子系统的性能调整,包括带宽测试、内核参数调整和多网卡绑定等,以提升系统的整体性能。
部署运行你感兴趣的模型镜像

内核支持的四种IO调度算法

# cat /sys/block/sda/queue/scheduler

noop anticipatory deadline [cfq]

cfq 完全公平IO调度算法。内核会为每个进程都维护一个IO队列,内核每次都从每个进程IO队列执行一个IO,然后再去执行下一个进程队列中的IO,如此循环。

anticipatory 预读算法。旧版内核默认算法。比较适合比较缓慢的存储设备。当内核选择了一个IO去执行后,他会消耗大约2毫秒时间去思考后面会继续有哪些IO,这些IO会涉及到存储设备哪个地方的数据,然后会提前去读取。

deadline 内核总是想在执行更多的IO。比较适合要求实时性比较强的环境。

noop 非常普通算法, 按招进程产生的IO的时间进行排序,哪个IO先产生,内核就会去执行它。

如何更改?

临时更改:

# echo "deadline" > /sys/block/sda/queue/scheduler

# cat /sys/block/sda/queue/scheduler

noop anticipatory [deadline] cfq

永久修改:

# vim grub.conf

....

kernel /vmlinuz-2.6.18-274.el5 ro root=LABEL=/ rhgb quiet elevator=deadline

===========================================================

网络子系统

1、如何用工具检测当前网络的工作状态

2、调整:

增加带宽

调整应用程序

调整内核参数

增加网卡

# cat /proc/net/dev

Inter-|   Receive                                                |  Transmit

face |bytes    packets errs drop fifo frame compressed multicast|bytes    packets errs drop fifo colls carrier compressed

eth0:12560602  181777    0    0    0     0          0         0 421085182  355989    0    0    0     0       0          0

# sar -n DEV

# iptraf -d eth0

# iptraf -i eth0

测试设备的最大可以使用的带宽

工具基于c/s

前提:测试的c和s都是处于同一类型的网络:例如两个不同机房的机器都是电信网络的。

netperf-2.5.0

服务端

# netserver

Starting netserver with host 'IN(6)ADDR_ANY' port '12865' and family AF_UNSPEC

服务端会打开12865端口

客户端:

# netperf -H 10.1.1.189 -l 30

Recv   Send    Send

Socket Socket  Message  Elapsed

Size   Size    Size     Time     Throughput

bytes  bytes   bytes    secs.    10^6bits/sec

87380  16384  16384    30.91      79.83 

调整内核参数

常规调整:

net.ipv4.tcp_rmem = 4096        87380   4194304

net.ipv4.tcp_wmem = 4096        16384   4194304

net.ipv4.ip_local_port_range = 1024    65000

net.ipv4.tcp_syncookies = 1

net.ipv4.tcp_max_syn_backlog = 8192

net.ipv4.tcp_synack_retries = 3

fs.file-max = 202508

查看内核参数的含义:

# yum install kernel-doc -y

# vim /usr/share/doc/kernel-doc-2.6.18/Documentation/XXX

搜索某个关键的文档

# grep -R "ip_forward" /usr/share/doc/kernel-doc-2.6.18/Documentation/

=======================================

多网卡绑定

物理图

/----eth0-----\

pc  switch

\----eth1-----/

逻辑图

/-----eth0----\

pc  bond0---switch

\-----eth1----/

文档

# vim /usr/share/doc/kernel-doc-2.6.18/Documentation/networking/bonding.txt

临时配置

# modprobe bonding miimon=100 mode=0

# ifconfig bond0 3.3.3.88 netmask 255.255.255.0 up

# ifenslave bond0 eth0 eth1

# ifconfig bond0

留意他的mac是取之于其中一个被绑定的物理网卡,然后另外一个物理网卡的MAC也被临时地更改为同一个

测试:

发送一个大文件

# watch 'ifconfig | grep "RX packets"'

永久配置

# vim /etc/modprobe.conf

alias bond0 bonding

options bonding miimon=100 mode=0

# vim /etc/sysconfig/network-scripts/ifcfg-bond0

DEVICE=bond0

BOOTPROTO=static

ONBOOT=yes

IPADDR=3.3.3.88

NETMASK=255.255.255.0

# vim /etc/sysconfig/network-scripts/ifcfg-eth0

DEVICE=eth0

BOOTPROTO=none

ONBOOT=yes

SLAVE=yes

MASTER=bond0

# vim /etc/sysconfig/network-scripts/ifcfg-eth1

DEVICE=eth1

BOOTPROTO=none

ONBOOT=yes

SLAVE=yes

MASTER=bond0

# ifup bond0

=======================================

搭建Lnmp,搭建一个论坛

location /status {

stub_status on;

access_log off;

}

Active connections: 1

server accepts handled requests

26 26 155 

Reading: 0 Writing: 1 Waiting: 0

Reading: 正在接受(读取)客户端的访问请求

Writing: 正在处理客户端的访问请求(根据请求正在寻找访问的页面,处理访问的页面,或者正在把客户端需要的内容发送给客户端)

Waiting: 如果打开keepalive选项,保持了多少个活动连接。

一般查看writing,确定当前nginx的并发访问量。

# ab -c 1000 -n 20000 http://10.1.1.22/

大概4000左右的并发服务器就反应非常慢,基本不能访问

能够瞬间达到最高值8000,但访问不了

架构:

php-fpm ---> php-fpm.conf ---> php.ini 启动php-cgi进程

nginx -->nginx.conf ---> 启动nginx进程

验证进程分别使用不同cpu

# ps -eo pid,psr,pcpu,user,comm | grep nginx

4494   1 root     nginx

4495   0 daemon   nginx 

4496   1 daemon   nginx 

# vim /usr/local/php//etc/php-fpm.conf

...

127.0.0.1:9000

24

65535

600 每个php-cgi进程能够处理多少个并发请求

...

# php-fpm restart

实验使用的配置文件

user  daemon;

error_log  logs/error.log  info;

pid        logs/nginx.pid;

worker_processes  2;

worker_cpu_affinity 01 10;

worker_rlimit_nofile 204800;

events {

use epoll;

worker_connections  10240;

}

http {

include       mime.types;

default_type  application/octet-stream;

log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '

'$status $body_bytes_sent "$http_referer" '

'"$http_user_agent" "$http_x_forwarded_for"';

sendfile        on;

#tcp_nopush     on;

keepalive_timeout  8;

client_header_buffer_size 4k;

large_client_header_buffers  4 4k;

client_max_body_size  8m;

server_names_hash_bucket_size  128;

open_file_cache max=204800 inactive=20s;

open_file_cache_valid    30s;

open_file_cache_min_uses 1;

open_file_cache_errors off;

fastcgi_buffer_size 4k;

fastcgi_buffers 256 4k;

server {

listen       80 ;

server_name  www.upl.com;

access_log  /web/www/logs/upl.com.access.log  main;

root   /web/www/wwwroot;

index  index.html index.htm index.php;

location ~* \.(gif|jpg|png|bmp|jpeg)$ {

expires 7d;

}

location ~*  \.(js|css)$ {

expires 1d;

}

location  /p_w_upload {

limit_rate  100k;

}

location ~ \.php$ {

if ($uri ~ /phpmyadmin) {

root /web;

}

fastcgi_pass   127.0.0.1:9000;

fastcgi_index  index.php;

fastcgi_param  SCRIPT_FILENAME  $document_root/$fastcgi_script_name;

include        fastcgi_params;

}

location /status {

stub_status on;

access_log off;

}

}

}

您可能感兴趣的与本文相关的镜像

Python3.10

Python3.10

Conda
Python

Python 是一种高级、解释型、通用的编程语言,以其简洁易读的语法而闻名,适用于广泛的应用,包括Web开发、数据分析、人工智能和自动化脚本

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值