Execute as fast as possible many curl commands

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
1
down vote

favorite
1












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









share|improve this question



























    up vote
    1
    down vote

    favorite
    1












    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









    share|improve this question

























      up vote
      1
      down vote

      favorite
      1









      up vote
      1
      down vote

      favorite
      1






      1





      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









      share|improve this question















      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






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Aug 26 at 9:16









      Rui F Ribeiro

      36.7k1271117




      36.7k1271117










      asked Aug 26 at 8:21









      Pierre H.

      143




      143




















          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





          share|improve this answer






















            Your Answer







            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "106"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            convertImagesToLinks: false,
            noModals: false,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













             

            draft saved


            draft discarded


















            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






























            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





            share|improve this answer


























              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





              share|improve this answer
























                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





                share|improve this answer














                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






                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Aug 26 at 23:03

























                answered Aug 26 at 22:52









                Ole Tange

                11.5k1345103




                11.5k1345103



























                     

                    draft saved


                    draft discarded















































                     


                    draft saved


                    draft discarded














                    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













































































                    Popular posts from this blog

                    Peggy Mitchell

                    Palaiologos

                    The Forum (Inglewood, California)