7

I waited as long as I could but finally had to upgrade from Mojave.
I knew something would needlessly break. And of course it did.

Largish files (more than 100k) randomly take 5 seconds to load. It's not always the same file, and not every time, and it only happens in HTTP Apache (tried port 80 and 8080). It works fine in Apache HTTPS/443 and Python's SimpleHTTPServer on HTTP/80.

Things I have tried:

  • It's not DNS. It happens on http://127.0.0.1/large.jpg
  • It's not browser related, it happens on curl.
  • It's not IPv6. Turned it off, same deal.
  • It's not MTU, tried 1492, same thing (you can see my desperation by now)
  • Already reinstalled it via brew reinstall httpd. Nothing.

Steps to reproduce:
i=1; while [ $i -lt 50 ]; do time curl http://127.0.0.1/large.jpg > /dev/null; ((i++)); done

Eventually it will stall for 5 seconds at 96%:
96 395k 96 382k

Another file:
i=1; while [ $i -lt 50 ]; do time curl http://127.0.0.1/jquery-latest.min.js > /dev/null; ((i++)); done

Eventually stalls at 85%
85 95786 85 81390

httpd -v
Server version: Apache/2.4.52 (Unix)
Server built: Dec 20 2021 13:37:44
Installed via brew

macOS Monterey 12.1 (21C52)

I'm loosing my mind, any help is much appreciated.
Thanks

Tambourine Man
  • 311
  • 1
  • 2
  • 10
  • It turns out, it's not the port. The problem also happens on port 8080 – Tambourine Man Feb 07 '22 at 02:06
  • I hope all this talking to myself helps someone else on the internet eventually. It seems like it's not directly Apache's fault either, conecting from another device is fast. For example, accessing http://192.168.0.100 from 192.168.0.101 is fast. http://192.168.0.100 from 192.168.0.100 is slow. – Tambourine Man Feb 10 '22 at 00:08
  • Happens on Big Sur too since a month ago. – Prescol Mar 06 '22 at 12:17
  • 1
    I'm not using Apache, just some very simple test code to listen to a loopback TCP socket and I'm experiencing exactly the same symptom on 12.4, but it's not randomly it's every time. Confirmed that the problem does not occur on Linux. – Jeremy W. Murphy Jun 03 '22 at 06:27

3 Answers3

10

I think I found a solution. Turn off Keep Alive by adding:

KeepAlive Off

To your http.conf

A better answer would be to understand why Keep Alive is misbehaving and fix that, but since it's on my local dev machine, it won't matter.

Tambourine Man
  • 311
  • 1
  • 2
  • 10
  • 1
    I have exactly the same issue as you do, `KeepAlive Off` helped me as well, thank you for figuring this out! My setup: M1 Pro, MacOS 12.2.1 (21D62), Homebrew Apache/2.4.52. Fun fact: I never saw this issue with significantly larger files, only with files of around 70kb of size (CSS and VSG so far). It looks like the limit is at 65324 bytes (which never have the issue), starting at 65325 bytes there is randomly a break of 5 seconds during the download. – Alexander Bondar Feb 23 '22 at 23:26
  • KeepAlive Off fixed the issue. It is curious how it always takes a 5 seconds delay, no matter the value of KeepAliveTimeout, so i do not really understand what could be happening. – Prescol Mar 06 '22 at 12:16
  • Had the same issue. `KeepAlive Off` helped me as well! Thank you – romek Apr 29 '22 at 08:58
2

Thanks to this thread, I've been able to open an issue on apache's bugzilla and the bug has been fixed and released in httpd 2.4.54 already available on brew :)

Atomiix
  • 21
  • 1
  • That's awesome, thank you! So, did macOS changed TCP handling on recent versions or did Apache enabled the TCP_NOPUSH optimization for macOS recently? – Tambourine Man Jun 14 '22 at 14:03
  • Also, why wasn't HTTPS affected? – Tambourine Man Jun 14 '22 at 14:06
  • @TambourineMan - is this information in the bug report? – benc Jun 17 '22 at 15:02
  • @benc I didn't file the bug report – Tambourine Man Jun 19 '22 at 00:12
  • @ TambourineMan - sorry, I wasn't clear. If you read thru the report, does the technical discussion answer your question? I looked at it, but I'm not so good with internals of this area, to confirm. – benc Jun 29 '22 at 06:30
  • @benc no problem. It's not my specialty either, but from after reading the bug report, it wasn't clear to me which update trigered it, Apache or macOS, only that it has to do with the TCP_NOPUSH optimization. – Tambourine Man Jul 20 '22 at 19:27
1

WOW- what an improvement this (KeepAlive Off) made in my case (ubuntu20 apache2 -v 2.4.42)

# apache2 -v
Server version: Apache/2.4.41 (Ubuntu)
Server built:   2023-03-08T17:32:54

I was troubleshooting why random jpg images would take ~ 1sec - 4sec to load, when 90% took less than 200ms. The server is enterprise ssd rd1, great hardware, load rarely above 0.10 , (tried tweaking lots of apache options) So it just didn't make sense- Setting keep alive to off from the default of on instantly resolved this issue!

As an additional datapoint, Below is a Grafana graph of the apache scoreboard (/server-status of mod_status) - u can see the blue line is where i set KeepAlive Off (and restarted apache) - It seems there was an uptick in waiting connections , and ofcourse a drop off in KeepAlive connections):

thanks enter image description here same- zoom in

James Gaul
  • 57
  • 5