Tcl Socket Performance

I have recently had occaision to test Tcl sockets performance across Gigabit Ethernet links between fairly modern machines (i.e. P IIIs at 700 and 900 Mhz, XEONs at 1 GHz). the following observations devolve from these tests:

  • Tcl Scripts can sustain about 25 MB/sec across a 1 GBit/sec link
  • Equivalent C code can sustain about 50 MBytes/sec across the same links
  • CPU consumption is about 60% on the relevant boxes, the performance differences appear to be related to Tcl internals, particularly buffer transfers.

Special test codes (not real world), are reported to be able to achieve about 60 MBytes/sec across these links. So Tcl sockets appear capable of something like 40 % of link capacity, while a C application can do about 83 % of capacity. Tcl is half the speed of a C application.

The test environment for the above is Linux RH 6.1 with ActiveTcl 8.3.3 binary distribution from ActiveState.

Windows Tests

It appears the Windows 2000 sockets and Tcl sockets are, as a couple, not happily married. It is easy to crash a Windows based Tcl script that uses sockets, apperantly because of a decision by Microsoft to ignore buffer sizes in its socket implementation. This problem is NOT manifest on W95/W98 which run the tests reliably.

Performance over 10BaseT links

On a 10BaseT link, Tcl sockets will run at about 65% of link capacity. The equivalent script running on Linux boxes will achieve 96% of link capacity.

The test environment here is Tcl 8.3.2 on all machines, W98 on the windows box and RH 7.0 and Slackware 96 on the linux boxes. Surprisingly, the test used a rather old 166 Mhz P II box running Slackware. CPU speed is clearly not a factor in these 10 Base T tests. This is also confirmed by some other tests on the GigaBit links that showed that increased CPU speed could result in LOWER link performance.

It is currently thought that this result is due to other factors than CPU, such as the brand of interface card used, the card driver, or some other environmental factor.

Useful Information

  • It appears that Tcl sockets are very efficient on a 10 megabit link, nearing 100 % of link capacity under Linux.
  • Under Windows 9x the results are less impressive, but compared to Linux, many would find that W9x is less impressive.
  • Over high performance links, the performance gap between a Tcl script and a C application is a factor of 2. This is a very significant performance gap and some investigation as to the reason is warranted.
  • Analysis of the cause of the performance gap will require some in depth work on Tcl sockets, as it does appear that CPU speed is NOT a factor. This would imply that some other characteristic of Tcl must be slowing performance.
  • The current evidence indicates that user buffer transfer calls are a large component of the delay.


Here are the scripts used for the tests:

Speed-up sockets on the NT platforms with iocpsock. I think the results are impressive, especially when running a server. iocpsock can get 100% usage on 100mbps ethernet, which can possibly beat non-optimized 'C' [ie. use of select() or WSAAsyncSelect()] ;) -- DG

DKF: I'd expect the best performance to be when using fcopy to shovel data from one channel to another; that's where Tcl could (theoretically?) be the most efficient.

DG: It could even be more efficient if fcopy could Tcl_GetDriverHandle than use TransmitFile bypassing Tcl altogether. Use of fcopy doesn't fix the current winsock driver as winsock itself is getting over-run, thus making Tcl look to be at fault when in fact garbage in == garbage out.

Also of interest: Todd Coram's "Idioms: Building High Performance Networking Servers using Tcl" [L1 ] and "More Tcl socket performance".