Bir bash betiğinden 5 curlistek göndermenin en iyi yolu nedir parallel? Performans nedeniyle onları seri halinde çalıştıramıyorum.
Bir bash betiğinden 5 curlistek göndermenin en iyi yolu nedir parallel? Performans nedeniyle onları seri halinde çalıştıramıyorum.
Yanıtlar:
İşlemi arka plana çıkarmak için komuttan sonra '&' kullanın ve bitmelerini beklemek için 'wait' (bekleyin). Bir alt kabuk oluşturmanız gerekirse komutların etrafında '()' kullanın.
#!/bin/bash
curl -s -o foo http://example.com/file1 && echo "done1" &
curl -s -o bar http://example.com/file2 && echo "done2" &
curl -s -o baz http://example.com/file3 && echo "done3" &
wait
xargs, işlemleri paralel olarak çalıştırmak için bir "-P" parametresine sahiptir. Örneğin:
wget -nv http://en.wikipedia.org/wiki/Linux -O- | egrep -o "http://[^[:space:]]*.jpg" | xargs -P 10 -r -n 1 wget -nv
Referans: http://www.commandlinefu.com/commands/view/3269/parallel-file-downloading-with-wget
Bu tür işler için paralel gnu kullanıyorum .
curlyapmak için bir örnek verebilir misiniz gnu parallel?
İşte bir curlörnek xargs:
$ cat URLS.txt | xargs -P 10 -n 1 curl
Yukarıdaki örnekte curlURL'lerin her biri paralel olarak, her defasında 10 olmalıdır. -n 1Böylece orada xargssadece 1 hattı kullanır URLS.txtbaşına dosya curlyürütme.
Xargs parametrelerinin her biri ne yapar:
$ man xargs
-P maxprocs
Parallel mode: run at most maxprocs invocations of utility at once.
-n number
Set the maximum number of arguments taken from standard input for
each invocation of utility. An invocation of utility will use less
than number standard input arguments if the number of bytes
accumulated (see the -s option) exceeds the specified size or there
are fewer than number arguments remaining for the last invocation of
utility. The current default value for number is 5000.