Today I've been setting up my brand new Raspberry Pi 3 and found out that my ssh session via the built-in wireless adapter was rahter laggy. On top of that, I've faced a few noticeable lag spikes (ranging from 5 to 10 seconds) and even total disconnects:

pi@pi3:~ $ packet_write_wait: Connection to 192.168.1.13: Broken pipe

I pinged the Pi3 from my computer and got response times so high that you would think packets from my own LAN were being routed through the Internet:

$ ping pi3
PING pi3 (192.168.1.13): 56 data bytes
64 bytes from 192.168.1.13: icmp_seq=0 ttl=64 time=262.618 ms
64 bytes from 192.168.1.13: icmp_seq=1 ttl=64 time=175.731 ms
64 bytes from 192.168.1.13: icmp_seq=2 ttl=64 time=93.862 ms
64 bytes from 192.168.1.13: icmp_seq=3 ttl=64 time=319.501 ms
64 bytes from 192.168.1.13: icmp_seq=4 ttl=64 time=240.666 ms
64 bytes from 192.168.1.13: icmp_seq=5 ttl=64 time=156.605 ms
64 bytes from 192.168.1.13: icmp_seq=6 ttl=64 time=77.802 ms

I got suspicious by the fact that disconnects were more likely the longer I left the SSH session idle. Also, it looked like I could bring the Pi back from it's own-induced disconnect just by pinging it's wireless interface:

$ ping pi3
PING pi3 (192.168.1.13): 56 data bytes
Request timeout for icmp_seq 0
Request timeout for icmp_seq 1
Request timeout for icmp_seq 2
Request timeout for icmp_seq 3
Request timeout for icmp_seq 4
Request timeout for icmp_seq 5
Request timeout for icmp_seq 6
Request timeout for icmp_seq 7
Request timeout for icmp_seq 8
Request timeout for icmp_seq 9
Request timeout for icmp_seq 10
Request timeout for icmp_seq 11
Request timeout for icmp_seq 12
64 bytes from 192.168.1.13: icmp_seq=13 ttl=64 time=226.806 ms
64 bytes from 192.168.1.13: icmp_seq=14 ttl=64 time=141.872 ms
64 bytes from 192.168.1.13: icmp_seq=15 ttl=64 time=57.239 ms

All of this pointed to a potential power management issue, so i ran this command on the Pi:

pi@pi3:~ $ sudo iwconfig wlan0 power off

This command disables the wireless interface's power management capabilities. With them disabled, there's no more lag, no more disconnects and ping times are what you would expect form a local area network connection:

$ ping pi3
PING pi3 (192.168.1.13): 56 data bytes
64 bytes from 192.168.1.13: icmp_seq=0 ttl=64 time=4.655 ms
64 bytes from 192.168.1.13: icmp_seq=1 ttl=64 time=4.808 ms
64 bytes from 192.168.1.13: icmp_seq=2 ttl=64 time=4.746 ms
64 bytes from 192.168.1.13: icmp_seq=3 ttl=64 time=6.575 ms

I bet there's a firmware update coming soon for the Raspberry Pi 3 :)