bash 符号链接 - 性能受到影响?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12601439/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Symlinks - performance hit?
提问by J.Zil
For deployment reasons, it is slightly easier for me to use symlinks, but these would be for all of my websites core files and configurations which will be accessed 10's of thousands of times a day.
出于部署原因,我使用符号链接稍微容易一些,但这些将用于我所有网站的核心文件和配置,这些文件和配置每天将被访问数十万次。
Am I more sensible to move the documents to the correct positions on the server (slightly more problematic deployment) rather than using symlinks for everything (slight performance degradation?)
我是否更明智地将文档移动到服务器上的正确位置(部署稍微有问题)而不是对所有内容使用符号链接(性能略有下降?)
回答by battery
I have created a file testfile.txtwith 1000 lines of blablablain it, and created a local symlink (testfile.link.txt) to it:
我创建了一个testfile.txt包含 1000 行的文件blablabla,并为其创建了一个本地符号链接 ( testfile.link.txt):
$ ls -n
total 12
lrwxrwxrwx 1 1000 1000 12 2012-09-26 14:09 testfile.link.txt -> testfile.txt
-rw-r--r-- 1 1000 1000 10000 2012-09-26 14:08 testfile.txt
(The -nswitch is only there to hide my super-secret username.:))
(-n开关只是为了隐藏我的超级秘密用户名。:))
And then executed 10 rounds of cating into /dev/null1000 times for both files.
(Results are in seconds.)
然后对两个文件执行 10 轮cating 到/dev/null1000 次。(结果以秒为单位。)
Accessing the file directly:
直接访问文件:
$ for j in `seq 1 10`; do ( time -p ( for i in `seq 1 1000`; do cat testfile.txt >/dev/null; done ) ) 2>&1 | grep 'real'; done
real 2.32
real 2.33
real 2.33
real 2.33
real 2.33
real 2.32
real 2.32
real 2.33
real 2.32
real 2.33
Accessing through symlink:
通过符号链接访问:
$ for j in `seq 1 10`; do ( time -p ( for i in `seq 1 1000`; do cat testfile.link.txt >/dev/null; done ) ) 2>&1 | grep 'real'; done
real 2.30
real 2.31
real 2.36
real 2.32
real 2.32
real 2.31
real 2.31
real 2.31
real 2.32
real 2.32
Measured on (a rather old install of) Ubuntu:
在(相当旧的安装)Ubuntu 上测量:
$ uname -srvm
Linux 2.6.32-43-generic #97-Ubuntu SMP Wed Sep 5 16:43:09 UTC 2012 i686
Of course it's a dumbed-down example, but based on this I wouldn't expect too much of a performance degradation when using symlinks.
当然,这是一个愚蠢的例子,但基于此,我不希望使用符号链接时性能下降太多。
I personally think, that using symlinks is more practical:
我个人认为,使用符号链接更实用:
- As you said, your deployment process will be simpler.
- You can also easily use versioning and roll-back if you include some kind of timestamp or version number in the directory names (e.g.
my_web_files.v1,my_web_files.v2), and use the "official" name in the symlink (e.g.my_web_files) pointing to the "live" version. If you want to change the version, just re-link to another versioned directory.
- 正如您所说,您的部署过程会更简单。
- 如果您在目录名称(例如
my_web_files.v1,my_web_files.v2)中包含某种时间戳或版本号,并在my_web_files指向“实时”版本的符号链接(例如)中使用“官方”名称,您还可以轻松使用版本控制和回滚。如果要更改版本,只需重新链接到另一个版本化目录。
回答by Brian Agnew
Have you measuredthis performance degredation ? I suspect it's hugely negligible compared to the time taken to fetch pages via the network.
你测量过这种性能下降吗?我怀疑与通过网络获取页面所花费的时间相比,它可以忽略不计。

