B4J Question Limit max concurrent requests in HTTPUtils?

Discussion in 'B4J Questions' started by Kevin, May 16, 2015.

  1. Kevin

    Kevin Well-Known Member Licensed User

    I wrote an app in B4J that retrieves a list of folders and files on a FlashAir WiFi SD card and downloads them. For the most part everything is working fine, but I noticed that if I sent a high number of download requests (these are all through http urls) back to back (say, over 90) that the program would just stall out and eventually I would start getting timeouts. The end result was that nothing would get downloaded other than maybe a few files.

    I chalked this up to the FlashAir being overwhelmed by too many consecutive or concurrent requests so I limited the number of files that a user could select at a time. Worked fine for me. But someone else with the same FlashAir card and a more powerful computer is having this problem with just 30 or so files to download.

    Is there a way I can limit the max number of concurrent requests in the core HTTPUtils library? I know I could try to track this myself and send more requests as results come back but I was wondering if there may be an easier way.
  2. Daestrum

    Daestrum Well-Known Member Licensed User

    Could you not create a list of files to download, start the first one, then as each completes, submit the next one until the list is empty.
  3. Kevin

    Kevin Well-Known Member Licensed User

    That is the solution I will likely need to use, but I figured if there were a way to set a limit directly that it would be a "one-line" fix. :D
  4. Erel

    Erel Administrator Staff Member Licensed User

    By default HttpClient (which is used by HttpUtils2) limits the number of concurrent connections to the same host to 5 connections.

    The first thing that you need to try is to significantly increase the requests timeout. If it doesn't help then use a list and download the files one after another.
  5. Kevin

    Kevin Well-Known Member Licensed User

    Good to know the 5 concurrent request limit. It turned out to be a problem related to my submitting the download jobs as I was going through a list in a nested For...Next loop. I think it was just too much to handle at once. I now go through the loops first and send the requests afterwards and this has solved it.