Cloud and Software Architecture, Soft skills, IOT and embedded
Browsers open extra connections in anticipation of additional requests
Get link
Facebook
X
Pinterest
Email
Other Apps
Browsers can open extra connections or pre-stage open connections to improve the user experience. You can see this if you build your own web server for IoT devices or monitor the connections and not just the requests. These pre-staged connections do not show up in the browser developer tools.
I was troubleshooting a connection timeout issue in a Python-based web server where there were sometimes suspicious connections that timed out. All my testing was done via a browser rather than Postman so I decided to investigate if it was a browser issue or a problem with my service. The developer tools console in Chrome did not show the extra connection in the network traces.
The Python web server generating the logs has a 10-second connection timeout. A single browser action appears to generate two inbound connection requests but only one HTTP request. The 2nd inbound connection appears to be timing out if the user doesn't click on or initiate any additional browser action.
Got a connection from ('127.0.0.1', 64753)
Request Bytes:706
Request Processing: GET/?out_0=off HTTP/1.1
Parameters: {'out_0': 'off'}
Connection closed
Got a connection from ('127.0.0.1', 64754)
Connection closed on error timed out None
Using Wireshark
Neither the Chrome Browser nor the Edge Browser showed any 2nd connection. I installed Wireshark and set it up to capture inbound traffic on localhost. Then I hit return in the URL bar and saw that two connections were opened to the python server within 5 seconds. This called for more investigation
The HTML contains a markup that causes the browser to not fetch favicon.ico and the trace shows that no favicon.ico request was made.
Chrome: Refresh the URL
This trace shows two sockets opened up when I hit the reload request. The first request is the reloaded HTTP GET on "/". The second request comes about 0.5 seconds after the first. No HTTP request is made on the second socket. The Python code times out the open connection after 10 seconds. You see this around the 10.57 timestamp. Sometime later the Browser attempts to keep the socket open.
Chrome: 2 Button Clicks that both do a GET
This trace shows two sockets opened up when I hit the reload request. The first request is clicking on a link on the page. The second socket opening comes about 0.55 seconds after the first. I then click on a 2nd link about 5 seconds after that and the request is processed on the previously opened socket.
Edge: Retains two open connections
I hit the reload button in edge and ended up with two timeout messages in the logs. Wireshark shows that Edge immediately opens two connections. One services the inbound GET request and the other waits. The inbound requests are processed in about 0.5 seconds like the Chrome numbers above. Edge then opens the 3rd connection so that it has two available. The 2nd connection times out at about the 10-second mark in line with our connection timeout. The 3rd connection times out 10 seconds after that.
Edge: An example of connection staging
This example shows how Edge appears to manage connections across two GET requests. In this case, these were hitting the return key in the URL bar. The browser immediately opens two connections. The first connection handles the GET request. A third connection is opened when the first connection completes. The button on the page generates the GET request around the 4.8 second mark. The python server times out the 3rd connection 10 seconds later at the 14.8 second mark. Then there is some other activity at the 30-second mark, probably the browser timeout.
I do a lot of my development and configuration via ssh into my Raspberry Pi Zero over the RNDIS connection. Some models of the Raspberry PIs can be configured with gadget drivers that let the Raspberry pi emulate different devices when plugged into computers via USB. My favorite gadget is the network profile that makes a Raspberry Pi look like an RNDIS-attached network device. All types of network services travel over an RNDIS device without knowing it is a USB hardware connection. A Raspberry Pi shows up as a Remote NDIS (RNDIS) device when you plug the Pi into a PC or Mac via a USB cable. The gadget in the Windows Device Manager picture shows this RNDIS Gadget connectivity between a Windows machine and a Raspberry Pi. The Problem Windows 11 and Windows 10 no longer auto-installs the RNDIS driver that makes magic happen. Windows recognizes that the Raspberry Pi is some type of generic USB COM device. Manually running W indows Update or Upd...
The Windows Subsystem for Linux operates as a virtual machine that can dynamically grow the amount of RAM to a maximum set at startup time. Microsoft sets a default maximum RAM available to 50% of the physical memory and a swap-space that is 1/4 of the maximum WSL RAM. You can scale those numbers up or down to allocate more or less RAM to the Linux instance. The first drawing shows the default WSL memory and swap space sizing. The images below show a developer machine that is running a dev environment in WSL2 and Docker Desktop. Docker Desktop has two of its own WSL modules that need to be accounted for. You can see that the memory would actually be oversubscribed, 3 x 50% if every VM used its maximum memory. The actual amount of memory used is significantly smaller allowing every piece to fit. Click to Enlarge The second drawing shows the memory allocation on my 64GB laptop. WSL Linux defaul...
The Apache Tika project provides a library capable of parsing and extracting data and meta data from over 1000 file types. Tika is available as a single jar file that can be included inside applications or as a deployable jar file that runs Tika as a standalone service. This blog describes deploying the Tika jar as an auto-scale service in Amazon AWS Elastic Beanstalk. I selected Elastic Beanstalk because it supports jar based deployments without any real Infrastructure configuration. Elastic Beanstalk auto-scale should take care of scaling up and down for for the number of requests you get. Tika parses documents and extracts their text completely in memory. Tika was deployed for this blog using EC2 t2.micro instances available in the AWS free tier. t2.micro VMs are 1GB which means that you are restricted in document complexity and size. You would size your instances appropriately for your largest documents. Preconditions An AWS account. AWS ac...
Comments
Post a Comment