{"id":277168,"date":"2016-03-29T11:49:03","date_gmt":"2016-03-29T07:49:03","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=277168"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=277168","title":{"rendered":"\u041c\u0438\u043b\u043b\u0438\u043e\u043d \u0444\u0430\u0439\u043b\u043e\u0432 \u0438 \u043e\u0434\u0438\u043d \u043d\u043e\u0443\u0442\u0431\u0443\u043a"},"content":{"rendered":"<p>       \u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043e\u043d-\u043b\u0430\u0439\u043d \u043c\u0430\u0433\u0430\u0437\u0438\u043d\u0430, \u043a\u0430\u043a \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043d\u043e\u0443\u0442\u0431\u0443\u043a\u0430 \u043f\u0440\u043e\u0430\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043c\u0438\u043b\u043b\u0438\u043e\u043d \u0444\u0430\u0439\u043b\u043e\u0432. <\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/26d\/18b\/294\/26d18b294c4a489db6ac7ec4beea8d48.png\"\/><\/p>\n<p>  \u041f\u0440\u0438 \u043d\u0430\u043b\u0438\u0447\u0438\u0438 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0433\u043e \u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440\u0430, \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u00ab\u0441\u0440\u0435\u0434\u043d\u0435\u0433\u043e \u0440\u0430\u0437\u043c\u0435\u0440\u0430\u00bb \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0440\u0430\u0437\u0443\u043c\u043d\u043e\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0443\u0442\u0438\u043b\u0438\u0442\u044b <a href=\"http:\/\/www.gnu.org\/software\/parallel\/\">GNU Parallel<\/a> \u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043f\u043e\u0442\u043e\u043a\u043e\u0432.<\/p>\n<p>  <a name=\"habracut\"><\/a><\/p>\n<h4>\u0428\u0430\u0433 1: Concatenating (cat * &gt;&gt; out.txt ?!)<\/h4>\n<p>  \u041f\u043e\u043b\u044c\u0437\u0430 \u0443\u0442\u0438\u043b\u0438\u0442\u044b <i>cat<\/i> \u0432 Unix-\u0441\u0438\u0441\u0442\u0435\u043c\u0430\u0445 \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u0430 \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u0443 \u0442\u0435\u0445, \u043a\u0442\u043e \u043a\u043e\u0433\u0434\u0430-\u043b\u0438\u0431\u043e \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u043b Terminal. \u0414\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0432\u044b\u0431\u0440\u0430\u0442\u044c \u0432\u0441\u0435 \u0438\u043b\u0438 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0444\u0430\u0439\u043b\u044b \u0432 \u043f\u0430\u043f\u043a\u0435 \u0438 \u0441\u043e\u0435\u0434\u0438\u043d\u0438\u0442\u044c \u0438\u0445 \u0432\u043c\u0435\u0441\u0442\u0435 \u0432 \u043e\u0434\u0438\u043d \u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u0444\u0430\u0439\u043b. \u041d\u043e \u0432\u043e\u0442 \u0447\u0442\u043e \u0432\u044b\u0445\u043e\u0434\u0438\u0442, \u043a\u0430\u043a \u0442\u043e\u043b\u044c\u043a\u043e \u0444\u0430\u0439\u043b\u043e\u0432 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u043c\u043d\u043e\u0433\u043e:<\/p>\n<pre><code class=\"html\">$ cat * &gt;&gt; out.txt -bash: \/bin\/cat: Argument list too long <\/code><\/pre>\n<p>  \u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0444\u0430\u0439\u043b\u043e\u0432 \u043f\u0440\u0435\u0432\u044b\u0448\u0430\u0435\u0442 \u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043c\u043e\u0435 \u0438 \u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440 \u043d\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u043c\u043e\u0436\u0435\u0442 \u0438\u0445 \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u0442\u044c. \u041c\u043d\u043e\u0433\u0438\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b Unix \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u044e\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u043a\u043e\u043b\u043e 10,000 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432; \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0437\u0432\u0435\u0437\u0434\u043e\u0447\u043a\u0438 \u0432 \u043a\u043e\u043c\u0430\u043d\u0434\u0435 <i>cat<\/i> \u0440\u0430\u0441\u0448\u0438\u0440\u044f\u0435\u0442 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442 1,234,567 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0443\u0442\u0438\u043b\u0438\u0442\u0435. \u0412 \u0438\u0442\u043e\u0433\u0435 \u043f\u043e\u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043e\u0431 \u043e\u0448\u0438\u0431\u043a\u0435.<\/p>\n<p>  \u041c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435: <\/p>\n<pre><code class=\"html\">for f in *; do cat &quot;$f&quot; &gt;&gt; ..\/transactions_cat\/transactions.csv; done <\/code><\/pre>\n<p>  \u0418 \u0441\u043f\u0443\u0441\u0442\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e 10,093 \u0441\u0435\u043a\u0443\u043d\u0434\u044b \u043e\u0431\u0440\u0430\u0437\u0443\u0435\u0442\u0441\u044f \u0441\u043e\u0441\u0442\u0430\u0432\u043d\u043e\u0439 \u0444\u0430\u0439\u043b.<\/p>\n<h4>\u0428\u0430\u0433 2: GNU Parallel &#038; Concatenation<\/h4>\n<p>  \u041d\u043e \u043c\u043e\u0436\u043d\u043e \u0443\u043b\u0443\u0447\u0448\u0438\u0442\u044c \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e GNU Parallel:<\/p>\n<pre><code class=\"html\">ls | parallel -m -j $f &quot;cat {} &gt;&gt; ..\/transactions_cat\/transactions.csv&quot; <\/code><\/pre>\n<p>  \u0410\u0440\u0433\u0443\u043c\u0435\u043d\u0442 <i>$f<\/i> \u0432 \u043a\u043e\u0434\u0435 \u0432\u044b\u0434\u0432\u0438\u0433\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u043f\u0435\u0440\u0435\u0434\u043d\u0438\u0439 \u043f\u043b\u0430\u043d, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u0431\u0440\u0430\u0442\u044c \u0443\u0440\u043e\u0432\u0435\u043d\u044c <i>parallelism<\/i>; \u043d\u043e \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u043b\u0438\u043d\u0435\u0439\u043d\u0430\u044f \u0448\u043a\u0430\u043b\u0430 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0432\u043d\u043e\u043c\u0435\u0440\u043d\u043e\u0439 (\u043a\u0430\u043a \u043d\u0430 \u0440\u0438\u0441\u0443\u043d\u043a\u0435 \u043d\u0438\u0436\u0435 \u2014 <a href=\"https:\/\/gist.github.com\/randyzwitch\/ee0f738b5895e059fa2a\">graph code<\/a>):<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/042\/fab\/7c4\/042fab7c4ca34defb0ab61ed25fc31dd.png\"\/><\/p>\n<h4>\u0428\u0430\u0433 3: \u0414\u0430\u043d\u043d\u044b\u0435 &gt; RAM<\/h4>\n<p>  \u041f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u043c\u0438\u043b\u043b\u0438\u043e\u043d \u0444\u0430\u0439\u043b\u0438\u043a\u043e\u0432 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u0442\u0441\u044f \u0432 \u043e\u0434\u0438\u043d \u0444\u0430\u0439\u043b, \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u0434\u0440\u0443\u0433\u0430\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430. \u041e\u0431\u044a\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0445 19.93 \u0413\u0431 \u043d\u0435 \u043f\u043e\u043c\u0435\u0449\u0430\u0435\u0442\u0441\u044f \u0432 RAM (\u0440\u0435\u0447\u044c \u0438\u0434\u0435\u0442 \u043e \u043d\u043e\u0443\u0442\u0431\u0443\u043a\u0435 2014 MBP, 16 \u0413\u0431 RAM). \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u0430\u043d\u0430\u043b\u0438\u0437\u0430 \u043d\u0443\u0436\u043d\u0430 \u043b\u0438\u0431\u043e \u0431\u043e\u043b\u0435\u0435 \u043c\u043e\u0449\u043d\u0430\u044f \u043c\u0430\u0448\u0438\u043d\u0430, \u043b\u0438\u0431\u043e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0447\u0435\u0440\u0435\u0437 \u0441\u0442\u0440\u0438\u043c\u043c\u0438\u043d\u0433. \u0418\u043b\u0438 \u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f <i>chunked<\/i> (<a href=\"https:\/\/ru.wikipedia.org\/wiki\/Chunked_transfer_encoding\">Chunked transfer encoding<\/a>).<\/p>\n<p>  \u041d\u043e \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u044f \u0433\u043e\u0432\u043e\u0440\u0438\u0442\u044c \u043e\u0431 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 GNU Parallel, \u0441\u0442\u043e\u0438\u0442 \u043e\u0442\u0432\u0435\u0442\u0438\u0442\u044c \u043d\u0430 \u0440\u044f\u0434 \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u0432, \u043a\u0430\u0441\u0430\u044e\u0449\u0438\u0445\u0441\u044f \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 (\u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043e\u043d-\u043b\u0430\u0439\u043d \u043c\u0430\u0433\u0430\u0437\u0438\u043d\u0430):<\/p>\n<p>  \u041a\u0430\u043a \u043c\u043d\u043e\u0433\u043e \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0445 \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u043e\u0432 \u0431\u044b\u043b\u043e \u043f\u0440\u043e\u0434\u0430\u043d\u043e?<br \/>  \u041a\u0430\u043a \u043c\u043d\u043e\u0433\u043e \u0441\u0434\u0435\u043b\u043e\u043a \u0431\u044b\u043b\u043e \u043f\u0440\u043e\u0432\u0435\u0434\u0435\u043d\u043e \u0437\u0430 \u0434\u0435\u043d\u044c?<br \/>  \u041a\u0430\u043a \u043c\u043d\u043e\u0433\u043e \u0442\u043e\u0432\u0430\u0440\u043e\u0432 \u0431\u044b\u043b\u043e \u043f\u0440\u043e\u0434\u0430\u043d\u043e \u0432 \u043c\u0430\u0433\u0430\u0437\u0438\u043d\u0435 \u0437\u0430 \u043c\u0435\u0441\u044f\u0446?<\/p>\n<h5>\u0423\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u044b<\/h5>\n<pre><code class=\"css\"># Serial method (i.e. no parallelism) # This is a simple implementation of map & reduce; tr statements represent one map, sort -u statements one reducer  # cut -d ' ' -f 5- transactions.csv | \\     - Using cut, take everything from the 5th column and over from the transactions.csv file # tr -d \\&quot; | \\                              - Using tr, trim off double-quotes. This leaves us with a comma-delimited string of products representing a transaction # sort -u | \\                               - Using sort, put similar items together, but only output the unique values # wc -l                                     - Count number of unique lines, which after de-duping, represents number of unique products  $ time cut -d ' ' -f 5- transactions.csv | tr -d \\&quot; | tr ',' '\\n' | sort -u | wc -l 331  real\t292m7.116s  # Parallelized version, default chunk size of 1MB. This will use 100% of all CPUs (real and virtual) # Also map & reduce; tr statements a single map, sort -u statements multiple reducers (8 by default)  $ time cut -d ' ' -f 5- transactions.csv | tr -d \\&quot; | tr ',' '\\n' | parallel --pipe --block 1M sort -u | sort -u | wc -l 331  # block size performance - Making block size smaller might improve performance # Number of jobs can also be manipulated (not evaluated) # --500K:               73m57.232s  # --Default 1M:         75m55.268s (3.84x faster than serial) # --2M:                 79m30.950s # --3M:                 80m43.311s <\/code><\/pre>\n<h5>\u0421\u0434\u0435\u043b\u043a\u0438 \u0437\u0430 \u0434\u0435\u043d\u044c<\/h5>\n<p>  \u0415\u0441\u043b\u0438 \u0444\u043e\u0440\u043c\u0430\u0442 \u0444\u0430\u0439\u043b\u0430 \u0431\u0443\u0434\u0435\u0442 \u043d\u0435\u0436\u0435\u043b\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u043c \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u043f\u0435\u0440\u0432\u044b\u043c \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u043c, \u0442\u043e \u0434\u043b\u044f \u0432\u0442\u043e\u0440\u043e\u0433\u043e \u043e\u043d \u043e\u0442\u043b\u0438\u0447\u043d\u043e \u043f\u043e\u0434\u043e\u0439\u0434\u0435\u0442. \u0422\u0430\u043a \u043a\u0430\u043a \u043a\u0430\u0436\u0434\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044e, \u0432\u0441\u0435, \u0447\u0442\u043e \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u2014 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u044d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442 SQL \u00abGroup By\u00bb \u0432 \u0434\u0435\u043d\u044c \u0438 \u0441\u0443\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u0442\u0440\u043e\u043a\u0438:<\/p>\n<pre><code class=\"css\"># Data is at transaction level, so just need to do equivalent of 'group by' operation # Using cut again, we choose field 3, which is the date part of the timestamp # sort | uniq -c is a common pattern for doing a 'group by' count operation # Final tr step is to trim the leading quotation mark from date string   time cut -d ' ' -f 3 transactions.csv | sort | uniq -c | tr -d \\&quot;  real\t76m51.223s  # Parallelized version # Quoting can be annoying when using parallel, so writing a Bash function is often much easier than dealing with escaping quotes # To do 'group by' operation using awk, need to use an associative array # Because we are doing parallel operations, need to pass awk output to awk again to return final counts  awksub () { awk '{a[$3]+=1;}END{for(i in a)print i&quot; &quot;a[i];}';} export -f awksub time parallel --pipe awksub &lt; transactions.csv | awk '{a[$1]+=$2;}END{for(i in a)print i&quot; &quot;a[i];}' | tr -d \\&quot; | sort  real\t8m22.674s (9.05x faster than serial) <\/code><\/pre>\n<h5>\u041e\u0431\u0449\u0435\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u0440\u043e\u0434\u0430\u0436 \u0437\u0430 \u0434\u0435\u043d\u044c \u0438 \u0437\u0430 \u043c\u0435\u0441\u044f\u0446<\/h5>\n<p>  \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u043c\u043e\u0433\u043b\u043e \u0441\u043b\u0443\u0447\u0438\u0442\u044c\u0441\u044f \u0442\u0430\u043a, \u0447\u0442\u043e \u043a\u043e\u043c\u0430\u043d\u0434\u043d\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430 <i>fu<\/i> \u0441\u043b\u0430\u0431\u043e\u0432\u0430\u0442\u0430, \u043d\u043e \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u0434\u043d\u0438\u043c \u0438\u0437 \u0441\u0430\u043c\u044b\u0445 \u0431\u044b\u0441\u0442\u0440\u044b\u0445. \u041a\u043e\u043d\u0435\u0447\u043d\u043e \u0432 14-\u043c\u0438\u043d\u0443\u0442\u043d\u043e\u0435 \u0432\u0440\u0435\u043c\u044f \u043f\u0440\u043e\u0431\u0435\u0433\u0430 \u043f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432\u0430 \u0432 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u043c \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0434\u043b\u044f \u00ab\u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u0438\u0437\u0430\u0446\u0438\u0438\u00bb \u043d\u0435 \u043d\u0430\u0441\u0442\u043e\u043b\u044c\u043a\u043e \u0431\u043e\u043b\u044c\u0448\u0438\u0435.<\/p>\n<pre><code class=\"css\"> # Serial method uses 40-50% all available CPU prior to `sort` step. Assuming linear scaling, best we could achieve is halving the time. # Grand Assertion: this pipeline actually gives correct answer! This is a very complex way to calculate this, SQL would be so much easier...  # cut -d ' ' -f 2,3,5                                                       - Take fields 2, 3, and 5 (store, timestamp, transaction) # tr -d '[A-Za-z\\&quot;\/\\- ]'\t\t\t\t\t            - Strip out all the characters and spaces, to just leave the store number, timestamp, and commas to represent the number of items # awk '{print (substr($1,1,5)&quot;-&quot;substr($1,6,6)), length(substr($1,14))+1}'  - Split the string at the store, yearmo boundary, then count number of commas + 1 (since 3 commas = 4 items)  # awk '{a[$1]+=$2;}END{for(i in a)print i&quot; &quot;a[i];}'\t                    - Sum by store-yearmo combo # sort\t\t\t\t\t\t\t\t\t    - Sort such that the store number is together, then the month  time cut -d ' ' -f 2,3,5 transactions.csv | tr -d '[A-Za-z\\&quot;\/\\- ]' | awk '{print (substr($1,1,5)&quot;-&quot;substr($1,6,6)), length(substr($1,14))+1}' | awk '{a[$1]+=$2;}END{for(i in a)print i&quot; &quot;a[i];}' | sort  real\t14m5.657s  # Parallelize the substring awk step # Actually lowers processor utilization!  awksub2 () { awk '{print (substr($1,1,5)&quot;-&quot;substr($1,6,6)), length(substr($1,14))+1}';} export -f awksub2 time cut -d ' ' -f 2,3,5 transactions.csv | tr -d '[A-Za-z\\&quot;\/\\- ]' | parallel --pipe -m  awksub2 | awk '{a[$1]+=$2;}END{for(i in a)print i&quot; &quot;a[i];}' | sort  real\t19m27.407s (worse!)  # Move parallel to aggregation step  awksub3 () { awk '{a[$1]+=$2;}END{for(i in a)print i&quot; &quot;a[i];}';} export -f awksub3 time cut -d ' ' -f 2,3,5 transactions.csv | tr -d '[A-Za-z\\&quot;\/\\- ]' | awk '{print (substr($1,1,5)&quot;-&quot;substr($1,6,6)), length(substr($1,14))+1}' | parallel --pipe awksub3  | awksub3 | sort  real\t19m24.851s (Same as other parallel run) <\/code><\/pre>\n<p>  \u042d\u0442\u0438 \u0442\u0440\u0438 \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u043f\u043e\u043a\u0430\u0437\u0430\u043b\u0438, \u0447\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f GNU Parallel \u0437\u0430 \u043f\u0440\u0438\u0435\u043c\u043b\u0435\u043c\u043e\u0435 \u0432\u0440\u0435\u043c\u044f \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043d\u0430\u0431\u043e\u0440\u044b \u0434\u0430\u043d\u043d\u044b\u0445, \u043f\u0440\u0435\u0432\u044b\u0448\u0430\u044e\u0449\u0438\u0435 RAM. \u041e\u0434\u043d\u0430\u043a\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u0442\u0430\u043a\u0436\u0435 \u043f\u043e\u043a\u0430\u0437\u0430\u043b\u0438, \u0447\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430 \u0441 \u0443\u0442\u0438\u043b\u0438\u0442\u0430\u043c\u0438 Unix \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u0430 \u0443\u0441\u043b\u043e\u0436\u043d\u044f\u0442\u044c\u0441\u044f. \u0421\u0446\u0435\u043d\u0430\u0440\u0438\u0439 \u043a\u043e\u043c\u0430\u043d\u0434\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438 \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 \u0434\u0432\u0438\u0436\u0435\u043d\u0438\u044e \u0432\u043d\u0435 \u201cone-liner\u201d \u0441\u0438\u043d\u0434\u0440\u043e\u043c\u0430, \u043a\u043e\u0433\u0434\u0430 \u043a\u043e\u043d\u0432\u0435\u0439\u0435\u0440\u043d\u0430\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u043d\u0430\u0441\u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u0438\u043d\u043d\u043e\u0439, \u0447\u0442\u043e \u0442\u0435\u0440\u044f\u0435\u0442\u0441\u044f \u0432\u0441\u044f\u043a\u0438\u0439 \u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0441\u043b\u0435\u0434. \u041d\u043e \u0432 \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u043c \u0441\u0447\u0435\u0442\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u043b\u0435\u0433\u043a\u043e \u0440\u0435\u0448\u0430\u044e\u0442\u0441\u044f \u043f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u0434\u0440\u0443\u0433\u0438\u0445 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u0432.               <\/p>\n<div class=\"clear\"><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habrahabr.ru\/post\/280384\/\"> https:\/\/habrahabr.ru\/post\/280384\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>       \u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043e\u043d-\u043b\u0430\u0439\u043d \u043c\u0430\u0433\u0430\u0437\u0438\u043d\u0430, \u043a\u0430\u043a \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043d\u043e\u0443\u0442\u0431\u0443\u043a\u0430 \u043f\u0440\u043e\u0430\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043c\u0438\u043b\u043b\u0438\u043e\u043d \u0444\u0430\u0439\u043b\u043e\u0432. <\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/26d\/18b\/294\/26d18b294c4a489db6ac7ec4beea8d48.png\"\/><\/p>\n<p>  \u041f\u0440\u0438 \u043d\u0430\u043b\u0438\u0447\u0438\u0438 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0433\u043e \u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440\u0430, \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u00ab\u0441\u0440\u0435\u0434\u043d\u0435\u0433\u043e \u0440\u0430\u0437\u043c\u0435\u0440\u0430\u00bb \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0440\u0430\u0437\u0443\u043c\u043d\u043e\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0443\u0442\u0438\u043b\u0438\u0442\u044b <a href=\"http:\/\/www.gnu.org\/software\/parallel\/\">GNU Parallel<\/a> \u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043f\u043e\u0442\u043e\u043a\u043e\u0432.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-277168","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/277168","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=277168"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/277168\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=277168"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=277168"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=277168"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}