Up to Main Index Up to Journal for December, 2015
JOURNAL FOR MONDAY 28TH DECEMBER, 2015
______________________________________________________________________________
SUBJECT: Improved networking
DATE: Mon 28 Dec 18:03:03 GMT 2015
Due to it being the holiday season things have been a bit quiet. However I've
still been busy working away on WolfMUD.
In my last journal entry[1] I posted some memory usage figures for the new
networking code. I wasn't very happy with the results I was seeing, especially
after about 4,000 players had connected. So I went back and debugged the code
some more and twiddled a few knobs. Here are the before and after results for
8,192 connected players:
#Players Max Alloc Max Heap Objects
Before: 8,192 944Mb 260,687
After: 8,192 14Mb 208,448
Now that is one heck of a difference! Only 14Mb for 8192 players. I then
pushed the server to 64,500. That is the maximum with only minor fiddling of
the networking configuration[2] and using only a single client IP address:
#Players Max Alloc Max Heap Objects
64,500 112Mb 1,608,168
The results were very encouraging and not too shabby at all :)
Most of the memory savings are due to switching from bufio.Scanner to
bufio.NewReader. bufio.Scanner - upto Go 1.5 - uses a 64k buffer per scanner.
For 8,192 clients that's 8,192 * 64Kb = 524,288Kb or 512Mb just for buffers. I
did notice that in the Go 1.6 beta you can now set the scanner buffer size
using Scanner.Buffer. At the moment I'm not using the 1.6 beta so I switched
to a bufio.Reader and used NewReaderSize to set the buffer size.
For WolfMUD we only need a small input buffer, I chose 80 bytes - one line on
a "standard" 80x24 terminal. The total space for the Reader buffers is now
8,192 * 80 bytes = 655,360 bytes or 640Kb. I also switched to 80 bytes for the
network read buffers and 24*80 or 1,920 bytes for the network write buffers.
The network buffers don't change the reported memory usage as they are handled
in the kernel network stack and not in Go. I think they are usually both set to
4Kb for read and write.
Looking at this post I might need to write a handy network setup and tuning
guide for performance...
Also related to networking, I have a working solution for broadcasting
messages to multiple locations. Once that is complete it should be time to
update the public dev branch and go multiplayer :)
--
Diddymus
[1] See: 18.html
[2] My machine already has limits for the number of open files raised and
net.ipv4.ip_local_port_range set to "1024 65535" to increase the number
of available ports.
Up to Main Index Up to Journal for December, 2015