grub-devel.gnu.org archive mirror
 help / color / mirror / Atom feed
* Patch: Improve HTTP time by sending Connection:close
@ 2016-11-12 17:26 Walter Huf
  2016-11-15 13:21 ` Daniel Kiper
  0 siblings, 1 reply; 8+ messages in thread
From: Walter Huf @ 2016-11-12 17:26 UTC (permalink / raw)
  To: grub-devel

[-- Attachment #1: Type: text/plain, Size: 2225 bytes --]

GRUB's HTTP module declares support for HTTP/1.1, which defaults to
Connection:keepalive. At the end of the content, the server holds the TCP
connection open waiting for the next request.
It seems that grub_net_poll_cards() is watching for the HTTP module to set
net->stall, and otherwise waits the full 400ms GRUB_NET_INTERVAL to return
to processing. However, HTTP module only sets that flag in specific
conditions:

   - parse_line detects that we are at the end of downloading a chunked
   Transfer-Encoding
   - http_err detects a problem with the underlying TCP connection
   - http_receive has queued 20 netbuffer packets for processing

If the file is small and takes less than 20 packets, and the server is not
using chunked encoding, grub_net_poll_cards() will wait the full 400ms
before continuing to process and finish the file download.

This patch sets Connection:close, which will tell the server to close the
connection as soon as it has finished sending the file. GRUB closes any
connections that are left open (in http_seek), so it does not change
performance. When the server disconnects, I think it triggers http_err and
then quits out of grub_net_poll_cards early.

---
diff --git a/grub-core/net/http.c b/grub-core/net/http.c
index 5aa4ad3..a5d64f6 100644
--- a/grub-core/net/http.c
+++ b/grub-core/net/http.c
@@ -318,6 +318,7 @@ http_establish (struct grub_file *file, grub_off_t
offset, int initial)
    + grub_strlen (data->filename)
    + sizeof (" HTTP/1.1\r\nHost: ") - 1
    + grub_strlen (file->device->net->server)
+   + sizeof ("\r\nConnection: close") - 1
    + sizeof ("\r\nUser-Agent: " PACKAGE_STRING
      "\r\n") - 1
    + sizeof ("Range: bytes=XXXXXXXXXXXXXXXXXXXX"
@@ -366,6 +367,17 @@ http_establish (struct grub_file *file, grub_off_t
offset, int initial)
        grub_strlen (file->device->net->server));

   ptr = nb->tail;
+  err = grub_netbuff_put (nb,
+  sizeof ("\r\nConnection: close")
+  - 1);
+  if (err)
+    {
+      grub_netbuff_free (nb);
+      return err;
+    }
+  grub_memcpy (ptr, "\r\nConnection: close",
+       sizeof ("\r\nConnection: close") - 1);
+  ptr = nb->tail;
   err = grub_netbuff_put (nb,
   sizeof ("\r\nUser-Agent: " PACKAGE_STRING "\r\n")
   - 1);

[-- Attachment #2: Type: text/html, Size: 3747 bytes --]

^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2016-11-17 18:42 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-11-12 17:26 Patch: Improve HTTP time by sending Connection:close Walter Huf
2016-11-15 13:21 ` Daniel Kiper
2016-11-15 14:30   ` Andrei Borzenkov
2016-11-15 20:44     ` Daniel Kiper
2016-11-15 21:43       ` Walter Huf
2016-11-16  3:20         ` Andrei Borzenkov
2016-11-17 18:32         ` Daniel Kiper
2016-11-17 18:41           ` Konrad Rzeszutek Wilk

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).