Execute as fast as possible many curl commands

Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
I am gathering some data locally at home on a Raspberry Pi and I want to send the data as fast as possible to a REST API (which I own) on a server on the web.
The locally gathered data could flow as fast as 100 records per second.
If I execute a curl command in a loop it will send the data... Wait for the 200 response then process the next record... Much slower than my internal data flow.
I have found some hints here on Stackoverflow and tried to adapt them but it wouldn't send the curl commands in parallel.
I know my code is not the prettiest (particularly about the usage of the mycurl function ) and I am ready for suggestions
#!/bin/bash
host="localhost"
port="********"
mycurl()
data="field1=$1&field2=$2&field3=$3&field4=$4&field5=$5&field6=$6&field7=$7&field8=$8&field9=$9&field10=$10"
curl --output /dev/null -d $data --silent -X POST https://myapi/myendpoint;
export -f mycurl
#----------------------LOOP starts------------------------
while true;
do
nc -d $host $port | while IFS="," read -r f1 f2 f3 f4 f5 f6 f7 f8 f9 f10 f11 f12 f13 f14 f15 f16 f17 f18 f19 f20 f21 f22
do
if [ "$f15" != "" ]; then
seq 1000 | parallel --no-notice --joblog log -j0 mycurl ::: $f5 ::: $f7 ::: $f8 ::: $f15 ::: $f16 ::: $17 ::: $18 ::: $19 ::: $20 ::: $21;
fi
done
done
linux bash curl gnu-parallel seq
add a comment |Â
up vote
1
down vote
favorite
I am gathering some data locally at home on a Raspberry Pi and I want to send the data as fast as possible to a REST API (which I own) on a server on the web.
The locally gathered data could flow as fast as 100 records per second.
If I execute a curl command in a loop it will send the data... Wait for the 200 response then process the next record... Much slower than my internal data flow.
I have found some hints here on Stackoverflow and tried to adapt them but it wouldn't send the curl commands in parallel.
I know my code is not the prettiest (particularly about the usage of the mycurl function ) and I am ready for suggestions
#!/bin/bash
host="localhost"
port="********"
mycurl()
data="field1=$1&field2=$2&field3=$3&field4=$4&field5=$5&field6=$6&field7=$7&field8=$8&field9=$9&field10=$10"
curl --output /dev/null -d $data --silent -X POST https://myapi/myendpoint;
export -f mycurl
#----------------------LOOP starts------------------------
while true;
do
nc -d $host $port | while IFS="," read -r f1 f2 f3 f4 f5 f6 f7 f8 f9 f10 f11 f12 f13 f14 f15 f16 f17 f18 f19 f20 f21 f22
do
if [ "$f15" != "" ]; then
seq 1000 | parallel --no-notice --joblog log -j0 mycurl ::: $f5 ::: $f7 ::: $f8 ::: $f15 ::: $f16 ::: $17 ::: $18 ::: $19 ::: $20 ::: $21;
fi
done
done
linux bash curl gnu-parallel seq
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I am gathering some data locally at home on a Raspberry Pi and I want to send the data as fast as possible to a REST API (which I own) on a server on the web.
The locally gathered data could flow as fast as 100 records per second.
If I execute a curl command in a loop it will send the data... Wait for the 200 response then process the next record... Much slower than my internal data flow.
I have found some hints here on Stackoverflow and tried to adapt them but it wouldn't send the curl commands in parallel.
I know my code is not the prettiest (particularly about the usage of the mycurl function ) and I am ready for suggestions
#!/bin/bash
host="localhost"
port="********"
mycurl()
data="field1=$1&field2=$2&field3=$3&field4=$4&field5=$5&field6=$6&field7=$7&field8=$8&field9=$9&field10=$10"
curl --output /dev/null -d $data --silent -X POST https://myapi/myendpoint;
export -f mycurl
#----------------------LOOP starts------------------------
while true;
do
nc -d $host $port | while IFS="," read -r f1 f2 f3 f4 f5 f6 f7 f8 f9 f10 f11 f12 f13 f14 f15 f16 f17 f18 f19 f20 f21 f22
do
if [ "$f15" != "" ]; then
seq 1000 | parallel --no-notice --joblog log -j0 mycurl ::: $f5 ::: $f7 ::: $f8 ::: $f15 ::: $f16 ::: $17 ::: $18 ::: $19 ::: $20 ::: $21;
fi
done
done
linux bash curl gnu-parallel seq
I am gathering some data locally at home on a Raspberry Pi and I want to send the data as fast as possible to a REST API (which I own) on a server on the web.
The locally gathered data could flow as fast as 100 records per second.
If I execute a curl command in a loop it will send the data... Wait for the 200 response then process the next record... Much slower than my internal data flow.
I have found some hints here on Stackoverflow and tried to adapt them but it wouldn't send the curl commands in parallel.
I know my code is not the prettiest (particularly about the usage of the mycurl function ) and I am ready for suggestions
#!/bin/bash
host="localhost"
port="********"
mycurl()
data="field1=$1&field2=$2&field3=$3&field4=$4&field5=$5&field6=$6&field7=$7&field8=$8&field9=$9&field10=$10"
curl --output /dev/null -d $data --silent -X POST https://myapi/myendpoint;
export -f mycurl
#----------------------LOOP starts------------------------
while true;
do
nc -d $host $port | while IFS="," read -r f1 f2 f3 f4 f5 f6 f7 f8 f9 f10 f11 f12 f13 f14 f15 f16 f17 f18 f19 f20 f21 f22
do
if [ "$f15" != "" ]; then
seq 1000 | parallel --no-notice --joblog log -j0 mycurl ::: $f5 ::: $f7 ::: $f8 ::: $f15 ::: $f16 ::: $17 ::: $18 ::: $19 ::: $20 ::: $21;
fi
done
done
linux bash curl gnu-parallel seq
linux bash curl gnu-parallel seq
edited Aug 26 at 9:16
Rui F Ribeiro
36.7k1271117
36.7k1271117
asked Aug 26 at 8:21
Pierre H.
143
143
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
0
down vote
GNU Parallel has an overhead of 2-5 ms per job which is getting close to your 100 entries per second. To mitigate that you can wrap it with parallel --pipe. This should run around 25000 jobs in parallel per second on a 100 core machine:
#!/bin/bash
host="localhost"
port="********"
mycurl()
if [ "$15" != "" ]; then
# The numbering here should probably be adjusted
data="field1=$1&field2=$2&field3=$3&field4=$4&field5=$5&field6=$6&field7=$7&field8=$8&field9=$9&field10=$10"
curl --output /dev/null -d $data --silent -X POST https://myapi/myendpoint;
fi
export -f mycurl
#----------------------LOOP starts------------------------
while true;
do
nc -d $host $port
done |
parallel -j100 --pipe --block 100k parallel --colsep , -j0 mycurl
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
GNU Parallel has an overhead of 2-5 ms per job which is getting close to your 100 entries per second. To mitigate that you can wrap it with parallel --pipe. This should run around 25000 jobs in parallel per second on a 100 core machine:
#!/bin/bash
host="localhost"
port="********"
mycurl()
if [ "$15" != "" ]; then
# The numbering here should probably be adjusted
data="field1=$1&field2=$2&field3=$3&field4=$4&field5=$5&field6=$6&field7=$7&field8=$8&field9=$9&field10=$10"
curl --output /dev/null -d $data --silent -X POST https://myapi/myendpoint;
fi
export -f mycurl
#----------------------LOOP starts------------------------
while true;
do
nc -d $host $port
done |
parallel -j100 --pipe --block 100k parallel --colsep , -j0 mycurl
add a comment |Â
up vote
0
down vote
GNU Parallel has an overhead of 2-5 ms per job which is getting close to your 100 entries per second. To mitigate that you can wrap it with parallel --pipe. This should run around 25000 jobs in parallel per second on a 100 core machine:
#!/bin/bash
host="localhost"
port="********"
mycurl()
if [ "$15" != "" ]; then
# The numbering here should probably be adjusted
data="field1=$1&field2=$2&field3=$3&field4=$4&field5=$5&field6=$6&field7=$7&field8=$8&field9=$9&field10=$10"
curl --output /dev/null -d $data --silent -X POST https://myapi/myendpoint;
fi
export -f mycurl
#----------------------LOOP starts------------------------
while true;
do
nc -d $host $port
done |
parallel -j100 --pipe --block 100k parallel --colsep , -j0 mycurl
add a comment |Â
up vote
0
down vote
up vote
0
down vote
GNU Parallel has an overhead of 2-5 ms per job which is getting close to your 100 entries per second. To mitigate that you can wrap it with parallel --pipe. This should run around 25000 jobs in parallel per second on a 100 core machine:
#!/bin/bash
host="localhost"
port="********"
mycurl()
if [ "$15" != "" ]; then
# The numbering here should probably be adjusted
data="field1=$1&field2=$2&field3=$3&field4=$4&field5=$5&field6=$6&field7=$7&field8=$8&field9=$9&field10=$10"
curl --output /dev/null -d $data --silent -X POST https://myapi/myendpoint;
fi
export -f mycurl
#----------------------LOOP starts------------------------
while true;
do
nc -d $host $port
done |
parallel -j100 --pipe --block 100k parallel --colsep , -j0 mycurl
GNU Parallel has an overhead of 2-5 ms per job which is getting close to your 100 entries per second. To mitigate that you can wrap it with parallel --pipe. This should run around 25000 jobs in parallel per second on a 100 core machine:
#!/bin/bash
host="localhost"
port="********"
mycurl()
if [ "$15" != "" ]; then
# The numbering here should probably be adjusted
data="field1=$1&field2=$2&field3=$3&field4=$4&field5=$5&field6=$6&field7=$7&field8=$8&field9=$9&field10=$10"
curl --output /dev/null -d $data --silent -X POST https://myapi/myendpoint;
fi
export -f mycurl
#----------------------LOOP starts------------------------
while true;
do
nc -d $host $port
done |
parallel -j100 --pipe --block 100k parallel --colsep , -j0 mycurl
edited Aug 26 at 23:03
answered Aug 26 at 22:52
Ole Tange
11.5k1345103
11.5k1345103
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f464890%2fexecute-as-fast-as-possible-many-curl-commands%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password