I created an HTTP Request with some code from @Azdle in another post. I’m looping through and just reading a small robots.txt file off of a web site. When I pull the file in my browser the response is in a couple hundred milliseconds, but when I pull the file from my Spark board, it averages 1.8 seconds.
Here is the code. Feel free to try with your favorite robots.txt file and your favorite “someurl”. Is there a way to make the connection faster? Can we open a socket and keep it open so multiple requests can be made? Are others seeing the same speed problem?
What I’m really trying to do is push data to a server with a POST and it was crazy slow (10-20 seconds). I thought this simple example would show the issue to others.
The code above could be doing a lot of printing at 9600 baud or 960 characters per second depending on the size of the file. This is about 1ms per character, so 1.8 seconds is only a bit over 1700 characters. Could the serial port be slowing you down?
Maybe you could measure the time without the printing to serial?
If you need to print to the serial port, you could try a high baud rate.
My experience reading yahoo weather web pages with the core is that it is not slow.
I turned off the printing of the response (it was only a 3 line robots.txt file) and it had no impact on the time. It is still looking like 1.9 sec per request average.
I added some more metrics and the result was interesting. I separately tracked the write portion, the wait for response portion, and then the reading the response portion. The third piece was far and away the slowest, even if the response was fairly small. Here are tests against my personal website (3-line robots.txt file) and Google’s much larger robots.txt file:
Transmit Elapsed Time:199
Waiting for Response Time:195
Roundtrip Elapsed Time:1882
I’d appreciate if others could try the code and replicate or repudiate my results. That would eliminate concerns about my Wifi connection, provider, etc.
Thank you for the sanity check. “someurl.com” wasn’t a real URL.
Now the question is how to reduce that time. It certainly limits what data can be captured, especially if the processor can’t do anything while it is doing much of that waiting.