thttpd http server 内存使用量太大的疑问 

前段时间搞了个腾讯云的7天体验服务器,难得国内的机房没备案的域名也能解析。就折腾了一下。

搞了一个号称最迷你的httpd server - thttpd.

官网:https://acme.com/software/thttpd/

下载最新的版本源码:
https://acme.com/software/thttpd/thttpd-2.28.tar.gz

解压,编译,安装。

复制 源码包内的配置文件,稍加修改,运行。

一看进程表,吓我一跳,咋thttpd 一个进程就占掉了我VPS 19%的内存!!!






ubuntu@powerpc:~$ free -m
total used free shared buff/cache available
Mem: 857 315 368 24 173 364
Swap: 0 0 0
ubuntu@powerpc:~$ ps aux | grep http
root 8320 0.0 3.2 251016 28484 ? Sl Mar07 0:01 php http.php
root 8321 0.0 0.6 176788 5644 ? S Mar07 0:00 php http.php
root 8323 0.0 1.2 179084 10652 ? S Mar07 0:00 php http.php
root 12666 0.0 5.0 669132 44024 ? Ssl Mar06 1:55 jexus: httpd worker jwsHttpd.exe
www-data 23634 0.2 18.8 191308 165948 ? Ss 15:51 0:06 /opt/thttpd/sbin/thttpd -C /opt/thttpd/config/thttpd.conf
ubuntu 26157 0.0 0.1 13232 1088 pts/0 S+ 16:34 0:00 grep --color=auto http
ubuntu@powerpc:~$


我tmd 当场就惊呆了,这内存占用快赶上MySQL了。

于是,在它的网站上找找,看有没有关于内存使用的相关配置字段,很遗憾没找到。而且由于它的功能定位很简单,导致了配置文件的选项也很少。目测不超过15个。
这是我的配置:

ubuntu@powerpc:~$ cat /opt/thttpd/config/thttpd.conf
# This section overrides defaults
port=80
dir=/var/www/html
nochroot
#data_dir
nosymlinkcheck
novhost
noglobalpasswd
user=www-data
host=0.0.0.0
logfile=/var/log/thttpd.log
pidfile=/var/run/thttpd.pid
charset=gbk
max_age=60


应该没啥毛病啊~

在它的首页我看到这样一句话:

Small:
See the comparison chart. It also has a very small run-time size, since it does not fork and is very careful about memory allocation.


意思就是:“我很小,我不会无聊的复制我自己,而且在内存分配方面我很谨慎”

这……我该如何理解这句话。

1.它不像nginx、php-fpm 那样会派生出很多worker,按说内存使用总量应该不会太大。
2.如果它没有派生功能,一直都是单进程。那么好像初始运行内存开辟大点,好像也没问题。

实在是看不懂。

后来我没辙,只能看看网友有没有和我一样有这样的疑惑,结果找到了一封18年前的邮件列表记录:

https://marc.info/?l=thttpd&m=102182637422558&w=2

面对用户关于“thttpd memory usage?”的疑问,acme的成员解释道:你用的内存查看工具是有问题的,是不准确的!

如下:

On some OSs, top seems to count memory-mapped files as part of the
program size. That makes thttpd look much bigger than it really is.


666~在下服了。

评论