May 09, '08 07:30:02AM • Contributed by: djlmc
Just for good measure, I tried (and failed) with these solutions:
- A wide selection of Mac OS versions/subversions, Mac hardware, USB ports, etc.
- All variations of network encryption options.
- Running every version of driver software (D-Link as well as Ralink) I could find.
- Many different USB extension cables, as well as without extension cables.
- Powered hubs - No luck, although this did make things notedly quicker and is highly recommended especially if you are using a G4 PowerBook as their USB power is pathetically unstable.
What I deduced from the system logs was that the Mac OS kernel was reporting repeated issues with the traffic going in and out at the USB end of the chain (USB msg queue errors and the like). This initially lead me (and most others) to always blame the USB ports, cables, etc., but nothing was ever consistent enough to resolve it. Once enough of these kernel misfires occurred, OS X would close the door on the adapter at the USB level, hence the unplug/replug that would reestablish things until the problem decided to recur.
Often the adapter would last longer if I wasn't running Internet Sharing, but it could equally as easily have dropped off after the next packet. I was leaning towards kernel loading as the catalyst, and made worse by any wavering wi-fi strength, unstable available USB power, etc.
My instinct kept saying it wasn't actually a USB-related cause, since it seemed so kernel-load-related rather than solely USB hardware or adapter-load related...perhaps the network stack's configuration was too strictly-set to expect a perfect dataflow from such USB-based wi-fi adapters. In other words, the data handed from the kernel's network layer to the physical USB layer was always too early, too late, not steady -- generally inconsistent. The USB layer seems a precious wee madam and intolerant of such things, so it complains, spits errors, traffic pauses, resumes, rinses/repeats until it has had enough and finally shuts the offending adapter out in the cold. So while we always think it's a USB related problem, if your signal fluctuates (causing the radio to pause and renegotiate, thus causing packet/USB message queues to bloat and empty), then this will cause the problems we've been seeing.
Based on these assumptions, I decided to try tweaking OS X's network settings to make sure the system was being as lenient as possible in terms of buffering more before handing things off to the USB layer, etc. Thus, a fix was born!
At present, I've been able to replicate the following results on my G4 1.33ghz PowerBook and G4 1.42ghz Mac mini, and other users' G5 tower, G5 iMac, G4 iMac. So far, it's solved the problem for each one I've looked at.
Create a txt file called sysctl.conf, paste in the contents below, and save it in /etc with root privileges (if you don't know how to do so, look around for a good how-to):
kern.ipc.somaxconn=512
net.inet.tcp.mssdflt=1460
net.inet.tcp.sendspace=98304
net.inet.tcp.recvspace=98304
kern.ipc.maxsockbuf=1048576
net.inet.udp.maxdgram=57344
net.inet.udp.recvspace=42080
net.local.stream.sendspace=98304
net.local.stream.recvspace=98304
net.inet.tcp.delayed_ack=0
net.inet.tcp.rfc1323=1
net.inet.tcp.rfc1644=1
net.inet.tcp.newreno=1
These OS network adjustments are then loaded at each subsequent boot automatically by OS X's startup routine (no startup item etc. is required). These changes increase the buffer sizes and general network tolerance, meaning traffic via USB will be smoothed out, regular and well behaved, and far less likely to cause the USB layer to freak out and slam the door on the adapter. (This sysctl.conf file will also smooth out any rough network performance on your Apple TV too ... search around if you don't know how to copy the file over to the ATV.)
The result? I am finally allowed a good hard thrash of the adapter for hours and hours -- even via Internet Sharing -- without a single hitch!
To undo the settings, simply sudo rm /etc/sysctl.conf the file and reboot, and OS X's default options return. Note that none of these settings have affected any other LAN performance aside from making file copies go a chunk faster! I also load the settings on my MacBook and other Macs for good measure, but that is entirely up to you.
Previously, when connecting to the net from my Macbook via the DWL-G122 (or any of the above adapters which previously behaved similarly or terribly unreliably) via Internet Sharing, light browsing might survive for a while, but open anything packet-heavy, such as Skype or even trying to watch one of Uncle Steve's Keynotes would drop the adapter out instantly. After applying this fix, I was able to watch a keynote in HD on my MacBook via the D-link sharing the net to me without a single hitch, with Azureus running and my roommate browsing away on her laptop. Good luck!
