HTTP response with payload via socket send() very slow

xenpac
Posts: 25
Joined: Sun Dec 08, 2019 1:20 am

HTTP response with payload via socket send() very slow

Postby xenpac » Sun Apr 12, 2020 10:44 am

Hi all,

I wrote a simple c code http server using the socket-api/lwip, to send camera image data to a client (firefox browser after a request of corse).

Response header:
char *response="HTTP/1.1 200 OK\r\nContent-Type: image/jpeg\r\nContent-Length: 50880\r\nContent-Disposition: inline; filename=capture.jpg\r\nAccess-Control-Allow-Origin: *\r\n\r\n";

send(socket, response, strlen(response),0);// this goes out fast

THEN, i send the image data in a a second send transaction.

send(socket, pbuf, 50880, 0);//the image data is sent. this takes ages from 10 seconds to 1 minute, before function returns.

After send returns, the image starts displaying in the browser.

I am actually sending the complete response in two send() transactions.
I understand, that splitting the response in several send() transactions will still be "one" TCP response.

I am wondering if i did not meet any specific http protocol standards that causes the client to ..? wait for something else?

any clues?

xenpac
Posts: 25
Joined: Sun Dec 08, 2019 1:20 am

Re: HTTP response with payload via socket send() very slow

Postby xenpac » Tue Apr 14, 2020 7:11 pm

Actually, i am using an ethernet adapter, not wifi.
(I did use the iperf example earlier and got around 58Mb network speed, not too bad.)

Now I build in some debug print into emac_main.c.

Here is a log showing how packets of size 1490 Bytes are transmitted over ethernet.

Also they show the timestamps in milliseconds, when they happen.
So you can see how long it take to transmit 50KB. (25 seconds in this case)

Something is not right, i dont know what?!



***log eth send:
sending data...
lwip_send(55, data=0x3ffcacc8, size=47139, flags=0x0)
I (40267) emac: tx netif>1490
I (40267) emac: <tx done
I (40457) emac: tx netif>1490
I (40457) emac: <tx done
I (41507) emac: tx netif>1490
I (41507) emac: <tx done
I (41507) emac: tx netif>1490
I (41507) emac: <tx done
I (41507) emac: tx netif>1490
I (41507) emac: <tx done
I (41517) emac: tx netif>1490
I (41517) emac: <tx done
I (41517) emac: tx netif>1490
I (41527) emac: <tx done
I (43007) emac: tx netif>1490
I (43007) emac: <tx done
I (43007) emac: tx netif>1490
I (43007) emac: <tx done
I (43007) emac: tx netif>1490
I (43007) emac: <tx done
I (44507) emac: tx netif>1490
I (44507) emac: <tx done
I (44507) emac: tx netif>1490
I (44507) emac: <tx done
I (44507) emac: tx netif>1490
I (44507) emac: <tx done
I (44507) emac: tx netif>1490
I (44517) emac: <tx done
I (44517) emac: tx netif>1490
I (44527) emac: <tx done
I (44527) emac: tx netif>1490
I (44527) emac: <tx done
I (44537) emac: tx netif>1490
I (44537) emac: <tx done
I (44537) emac: tx netif>1490
I (44547) emac: <tx done
I (44547) emac: tx netif>1490
I (44547) emac: <tx done
I (44557) emac: tx netif>1490
I (44557) emac: <tx done
I (46007) emac: tx netif>1490
I (46007) emac: <tx done
I (49007) emac: tx netif>1490
I (49007) emac: <tx done
I (49007) emac: tx netif>1490
I (49007) emac: <tx done
I (49007) emac: tx netif>1490
I (49007) emac: <tx done
I (49017) emac: tx netif>1490
I (49017) emac: <tx done
I (49017) emac: tx netif>1490
I (49027) emac: <tx done
I (49027) emac: tx netif>1490
I (49027) emac: <tx done
I (49037) emac: tx netif>1490
I (49037) emac: <tx done
I (50507) emac: tx netif>1490
I (50507) emac: <tx done
I (53507) emac: tx netif>1490
I (53507) emac: <tx done
I (59027) emac: tx netif>54
I (59027) emac: <tx done
I (59507) emac: tx netif>1490
I (59507) emac: <tx done
I (59507) emac: tx netif>1490
I (59507) emac: <tx done
I (59507) emac: tx netif>1490
I (59507) emac: <tx done
I (60367) emac: tx netif>42
I (60367) emac: <tx done
I (61007) emac: tx netif>1490
I (61007) emac: <tx done
I (61007) emac: tx netif>1490
I (61007) emac: <tx done
I (61007) emac: tx netif>1490
I (61007) emac: <tx done
I (62507) emac: tx netif>1490
I (62507) emac: <tx done
I (62507) emac: tx netif>1490
I (62507) emac: <tx done
I (62507) emac: tx netif>1490
I (62507) emac: <tx done
I (62507) emac: tx netif>1490
I (62517) emac: <tx done
I (62517) emac: tx netif>1490
I (62527) emac: <tx done
I (62527) emac: tx netif>1490
I (62527) emac: <tx done
I (62537) emac: tx netif>1490
I (62537) emac: <tx done
lwip_send(55) err=0 written=47139
I (62537) emac: tx netif>1490
I (62547) emac: <tx done
I (62547) emac: tx netif>1490
I (62557) emac: <tx done
I (62557) emac: tx netif>1490
I (62557) emac: <tx done
End of Transaction 3 <<<<<<<<<<<<<<<<<<<<<<<<
lwip_recvfrom(55, 0x3ffb8410, 400, 0x0, ..)
lwip_recvfrom: top while sock->lastdata=0x0
I (64007) emac: tx netif>1490
I (64007) emac: <tx done
I (64007) emac: tx netif>1490
I (64007) emac: <tx done
I (64007) emac: tx netif>1490
I (64007) emac: <tx done
I (65507) emac: tx netif>1490
I (65507) emac: <tx done
I (65507) emac: tx netif>1490
I (65507) emac: <tx done
I (65707) emac: tx netif>1241
I (65707) emac: <tx done
I (65707) emac: tx netif>54
I (65707) emac: <tx done
lwip_recvfrom: netconn_recv err=-15, netbuf=0x0
lwip_recvfrom(55): buf == NULL, error is "Connection closed."!
read failed!
Connection closed
lwip_close(55)

atlascoder
Posts: 51
Joined: Wed Aug 30, 2017 12:36 pm

Re: HTTP response with payload via socket send() very slow

Postby atlascoder » Thu Jul 29, 2021 10:30 am

Hey!
Any progress here?

i am lso facing something similar.. Though, I use simultaneously: 1) http server based on IDF ESP HTTP server, and 2) custom outgoing requests using lwip socket.

Maybe mixing this isn't good?

Also, I don't see CPU overloads - my IDLE tasks take around 90% time.

Who is online

Users browsing this forum: Bing [Bot] and 100 guests