我们如何使用unix sort更快地进行排序? [英] How do we sort faster using unix sort?

查看:84
本文介绍了我们如何使用unix sort更快地进行排序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在对一个具有37个字段的5GB文件进行排序,并使用5个键对其进行排序.大文件由1000个5MB的文件组成.

We are sorting a 5GB file with 37 fields and sort it with 5 keys. The big file is composed of 1000 files of 5MB each.

190分钟后,它仍然没有结束.

After 190 minutes it still hasn't finished.

我想知道是否还有其他方法可以加快排序速度.我们选择unix排序是因为我们不希望它用完所有内存,因此任何基于内存的方法都不行.

I am wondering if there are other methods to speed up the sorting. We choose unix sort because we don't want it to use up all the memory, so any memory based approach is not okay.

分别对每个文件进行排序,然后使用-m选项进行合并排序有什么好处?

What is the advantage of sorting each files independently, and then use -m option to merge sort it?

推荐答案

使用-S将其缓冲在内存中.例如,要将(最多)50%的内存用作排序缓冲区,请执行以下操作:

Buffer it in memory using -S. For example, to use (up to) 50% of your memory as a sorting buffer do:

sort -S 50% file

请注意,现代Unix sort可以并行排序.我的经验是,它会自动使用尽可能多的内核.您可以直接使用--parallel进行设置.要使用4个线程进行排序:

Note that modern Unix sort can sort in parallel. My experience is that it automatically uses as many cores as possible. You can set it directly using --parallel. To sort using 4 threads:

sort --parallel=4 file

总而言之,您应该将所有内容放入一个文件并执行类似的操作:

So all in all, you should put everything into one file and execute something like:

sort -S 50% --parallel=4 file

这篇关于我们如何使用unix sort更快地进行排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆