Skip to content
Tcl Source Code Artifact [a4fbea3799]
Login

Artifact [a4fbea3799]

Artifact a4fbea37995f3edca0b88bc8ca5f56cd61736caa:

Ticket change [a4fbea3799] - New ticket [3056775fffffffff|3056775fff] <i>Socket -server stops accepting connections under load</i>. by twylite on 2010-08-31 15:14:35.
D 2010-08-31T15:14:35
J assignee andreas_kupries
J cmimetype text/plain
J comment TL;DR\sand\sfix\n-------------\n\nSocket\s-server\smay\sstop\saccepting\snew\sconnections\son\sWindows.\s\sThis\sappears\sto\sbe\scaused\sby\sa\srace\scondition\swhile\smodifying\sacceptEventCount\sand\sreadyEvents\s(members\sof\sSocketInfo*\sinfoPtr\sin\stclWinSock.c)\sfrom\stwo\sdifferent\sthreads.\n\nAffects\sTcl\sversions\s8.4.11\sthrough\sCVS-HEAD.\n\nAdding\sa\slock\saround\saccess\sto\sthese\smembers\sin\sTcpAccept()\s(tclWinSock.c)\sresolves\sthe\sissue.\n\n\ndiff\s-r1.73\stclWinSock.c\n1481a1482,1487\n>\n>\s\s\s\s\s/*\n>\s\s\s\s\s\s\s\s\s\s*\sAll\saccess\sto\ssockets\sin\ssocketList\shas\sto\sbe\sprotected\sby\sthe\slock.\n>\s\s\s\s\s\s\s\s\s\s*\sFix\sfor\sSF\sTcl\sBug\s#xxxxxx\n>\s\s\s\s\s\s\s\s\s\s*/\n>\s\s\s\s\s\s\sWaitForSingleObject(tsdPtr->socketListLock,\sINFINITE);\n1487a1494\n>\s\s\s\s\s\s\sSetEvent(tsdPtr->socketListLock);\n\n\nFull\sdescription\sand\sdiagnosis\sincluded\sbecause\sI\salready\styped\sup\s90+%\sof\sit\sbefore\sfinding\sthe\ssolution\s(and\sit\sshould\sbe\sa\suseful\sreference).\n\n\nDescription\sof\sproblem\n----------------------\n\nWhen\ssubjected\sto\sload\susing\sthe\sOpenLoad\s(http://openwebload.sourceforge.net/)\stool,\sa\sTcl\sinterpreter\son\sx86/WIN32\smay\sstop\saccepting\sconnections\son\sthe\sloaded\ssocket.\n\n-\sTcl\sdoes\snot\slock\sup\sor\scrash;\sa\sconsole\sis\sable\sto\srespond\snormally.\n-\sTcl's\snetworking\ssubsystem\sdoes\snot\slock\sup;\sother\ssockets\sopened\spreviously\sor\ssubsequently\sbehave\snormally.\n-\sThe\ssymptom\sof\sthe\s"lock\sup"\sis\sthat\sthe\sport\swill\saccept\sthe\sconnection,\sbut\sthere\sis\sno\sevidence\sthat\sthe\saccept\scommand\s(i.e.\ssocket\s-server\s$acceptcmd)\sis\sever\sexecuted.\n-\sOnce\slocked\sup\sthe\ssocket\smay\soccasionally\srecover,\sbut\sin\smost\sinstances\sremains\s"locked\sup"\seven\sif\sleft\sfor\s15\sminutes\sor\smore.\n-\sCan\sbe\sreproduced\swith\sTcl\s8.4.11,\s8.5.2,\s8.6b1.1,\sand\sCVS\sHEAD\s2010/08/26\s(8.6b1.2).\n-\sCan\sbe\sreproduced\sin\sbuilds\swith\sOPTS=threads\sand\sOPTS=nothreads.\n-\sCan\sbe\sreproduced\sin\stclsh\sand\swish.\n\n\nReproducing\sthe\sproblem\n-----------------------\n\nI\sinitially\snoticed\sthe\sproblem\swhile\ssubjecting\sWub\sto\sperformance\stests.\s\sTo\sisolate\sthe\scause\sI\sended\sup\screated\sa\sstripped-down\sversion\sof\sWub,\sthen\sa\ssimple\sevent-based\sserver\sthat\sfakes\sthe\sHTTP\sprotocol\s(attached).\n\n(This\sissue\swas\soriginally\sreported\sas\sa\sWub\sissue\s-\shttp://code.google.com/p/wub/issues/detail?id=23)\n\nSend\sa\ssingle\srequest\swith\sOpenload\sto\svalidate\sthe\sURL\n\s\sopenload\s-h\sUser-Agent\s"MSIE\s5.0"\shttp://localhost/\s-t\n\s\s\nSimulate\sa\ssingle\sclient\sat\smax\sload\n\s\sopenload\s-h\sUser-Agent\s"MSIE\s5.0"\shttp://localhost/\s1\n\s\s\nSimulate\s10\sclients\sat\smax\sload\n\s\sopenload\s-h\sUser-Agent\s"MSIE\s5.0"\shttp://localhost/\s10\n\s\s\nThe\s"User-Agent"\smay\sbe\somitted\swith\sthe\stest\sscript;\sfor\stesting\sagainst\sWub\sit\sis\srequired\sor\sopenload\swill\sbe\sflagged\sas\sa\sspider.\n\nThe\stest\sscript\stypically\slocks\sup\sin\sunder\s15,000\srequests\swith\s10\sclients,\sand\sunder\s4,000\srequests\swith\s20\sclients.\s\sBeaviour\swith\s5\sor\sfewer\sclients\sis\seratic\s(sometimes\sno\slockup\soccurs).\n\nWub\swill\stypically\slock\sup\sin\sunder\s10,000\srequests\swith\s5\sclients.\n\nUsing\sa\ssingle\sclient\sseldom\sresults\sin\sa\slock\sup,\sbut\sI\shave\sseen\sit\swith\sWub.\n\n\nThings\sit\sis\s(most\slikely)\snot\n------------------------------\n\n(1)\sWindows\sTcpipParameters\n\nIn\sHKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters\sI\shave:\nTcpTimedWaitDelay\s(DWORD)\sset\sto\s30\s(decimal)\nMaxUserPort\s(DWORD)\sset\sto\s65000\s(decimal)\nReservedPorts\s(MULTI_SZ)\sincludes\sonly\s1433-1434\n\nThis\sgives\snearly\s64000\sports\swhich\swill\slinger\sfor\s30\sseconds,\sallowing\sa\ssustained\s2100\sTPS\sat\sminimum.\n\nRunning\sopenload\sagainst\sshttpd\s(shttpd.sourceforge.net)\sconfirms\sa\ssustained\s1689\sTPS\sover\s220+\sseconds\s(377555\srequests)\swith\s5\sclients,\sor\s1718\sTPS\sover\s230+\sseconds\s(401904\srequests)\swith\s20\sclients.\n\nSockets\sare\sclearly\sbeing\srecycled\shere,\sand\sat\sa\srate\ssufficient\sto\ssustain\sin\sexcess\sof\s1700\sTPS.\n\n(2)\sWindows\sTCP/IP\snetworking\sin\sgeneral\n\nAs\sindicated\sabove,\sshttpd\s(a\sC\sapplication)\sis\sable\sto\srun\son\sthe\ssame\ssystem\swithout\ssymptoms\sof\sa\s"lock\sup".\n\nAs\sa\sfurther\stest,\sLightTPD\s1.4.26-1\s(downloaded\sfrom\shttp://files.dtech.hu/pub/WLMP-Project/LightTPD-Win32/)\swas\sable\sto\ssustain\s1336\sTPS\swith\s1\sclient\s(140\sseconds,\s187137\srequests),\s1461\sTPS\swith\s5\sclients\s(150+\sseconds,\s220045\srequests),\sand\s1517\sTPS\swith\s20\sclients\s(340+\sseconds,\s519545\srequests).\n\n\n(3)\sCompiler,\stclsh\svs\swish,\sOPTS=threads\n\nUsing\sCVS\sHEAD\s2010/08/26\sI\sbuilt\s5\sbinaries,\sall\sof\swhich\sshow\sthe\s"lock\sup"\sin\sunder\s10,000\srequests\swhen\susing\sOpenload\swith\s10\sclients:\n\nopenload\s-h\sUser-Agent\s"MSIE\s5.0"\shttp://localhost/\s10\n\nBinary\sconfigurations:\n-\stclsh86t.exe,\sMSVC\s6\sProfessional,\sOPTS=threads\n-\stclsh86.exe,\sMSVC\s6\sProfessional,\sOPTS=nothreads\n-\swish86t.exe,\sMSVC\s6\sProfessional,\sOPTS=threads,\sincludes\sTk\n-\stclsh86.exe,\sMSVC\s9\sExpress,\sOPTS=nothreads\n-\stclsh86t.exe,\sMSVC\s9\sExpress,\sOPTS=threads\n\nUsing\sthe\slast\sbuild\sattempts\swere\smade\sto\scheck\sfor\srecovery\safter\sthe\s"lock\sup"\sby\strying\sa\ssingle\sconnection\severy\sfew\sminutes.\s\sAfter\s15+\sminutes\sthe\sserver\ssocket\swas\sstill\snot\sresponding.\s\sA\s"netstat\s-an"\sconfirmed\sthat\sall\swaiting\ssockets\swere\sgone\swithin\sthe\sfirst\sminute\safter\sthe\slockup.\n\n\n(4)\slisten()\sbacklog\n\nIncoming\sconnections\safter\sthe\s"lock\sup"\sare\snot\srejected\sby\sthe\sWindows\snetworking\slayer;\sthe\sconnection\sis\saccepted.\n\nThis\shas\sbeen\sconfirmed\susing\stelnet\sto\sconnect\sto\sthe\sport:\sthe\sconnection\sis\saccepted.\s\sInstrumentation\sin\sthe\s$acceptcmd\s(e.g.\stracing\sor\sincrementing\sa\sglobal\svariable)\sdoes\snot\sappear\sto\srun.\n\nCROSS-CHECK:\sIn\saddition\san\sinstrumented\sbuild\swas\smade\s(see\sbelow)\swith\sbacklog=1024\s(as\susing\sin\sLightTPD\s1.4.26),\swhich\sdid\snot\ssolve\sthe\sproblem.\n\n\n(5)\sFD_SETSIZE\n\nParts\sof\sTcl's\snetworking\ssubsystem\sfor\sWIN32\suse\sselect(),\swhich\smeans\sthat\sthe\smaximum\ssimultaneous\sconnections\smay\sbe\slimited\sby\sFD_SETSIZE.\n\nOpenload\ssimulates\smultiple\sclients\sin\sparallel,\sbut\seach\sclient\sbehaves\ssynchronously:\sa\sresponse\sis\sexpected\sbefore\sthe\snext\srequest\sis\ssent.\s\sAs\sa\sresult\sthe\sTcl\sserver\sshould\snever\sbe\shandling\smore\sthan\s(num_clients\s+\sSTD\shandles)\sconnections.\n\nSince\sFD_SETSIZE\sdefaults\sto\s64\sin\sthe\sWIN32\sSDK,\sand\swe\scan\sreproduce\sthe\sproblem\sat\sless\sthan\s10\sclients,\sit\sstands\sto\sreason\sthat\sFD_SETSIZE\sis\snot\sthe\scause.\n\nCROSS-CHECK:\sIn\saddition\san\sinstrumented\sbuild\swas\smade\s(see\sbelow)\swith\sFD_SETSIZE=512,\swhich\sdid\snot\ssolve\sthe\sproblem.\n\n\nInstrumented\sBuild\n------------------\n\nCVS\sHEAD\s2010/08/26\swas\smodified\sas\sfollows\sto\screate\san\sinstrumented\sbuild:\n\n-\sIn\smakefile.vc,\sappend\s"-DFD_SETSIZE=512"\sto\sTCL_DEFINES\n-\sIn\stclWinSock.c,\sadd\sa\sprintf()\sof\swsaData.iMaxSockets\safter\sWSAStartup()\n-\sIn\stclWinSock.c,\schange\sSOMAXCONN\sto\s1024\sin\slisten()\n\nThe\supdated\ssources\swere\sbuilt\swith\sMSVC\s9\sExpress\sand\sOPTS=threads.\n\nRunning\sthe\sbinary\sconfirms\siMaxSockets\s=\s32767,\sand\sthe\s"lock\sup"\soccurs\sas\susual\swhen\susing\sopenload\sto\ssimulate\s10\sclients.\n\nFurther\sinstrumentation\s(specifically\sprintf()\straces\saround\sconnection\saccepting\slogic,\sintended\sto\spinpoint\swhere\sthe\snotice\sof\snew\sconnections\swas\s"getting\slost")\scaused\sthe\sissue\sto\soccur\smore\sfrequently\s(sometimes\salmost\spredictably)\sor\sto\salmost\scompletely\svanish.\s\sThis\spointed\sto\sa\sheisenbug\sprobably\sinvolving\sa\ssynchronisation\sproblem\sor\srace\scondition\sbetween\sthe\stwo\sthreads\sinvolved.\n\nThis\srealisation\sled\sto\sthe\sidentification\sof\sa\spossible\srace\scondition\saround\sinfoPtr->acceptEventCount\sand\sinfoPtr->readyEvents.\s\sTests\safter\sadding\sthe\slock\sconfirm\sthat\sthis\swas\sindeed\sthe\sproblem.\n\n\nREFERENCE:\sConfigure\sWindows\sTcpip\sParameters\sfor\shigh\sperformance\sservers\n--------------------------------------------------------------------------\n\n1.\sIn\sthe\sRegistry\snavigate\sto\n\s\s\sHKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters\n\n2.\sCreate\sor\sedit\sTcpTimedWaitDelay\s(DWORD),\sset\sto\s30\s(decimal)\n\n3.\sCreate\sor\sedit\sMaxUserPort\s(DWORD),\sset\sto\s10000\s(deicmal)\n\n4.\sEnsure\sthat\sReservedPorts\s(MULTI_SZ)\sreserved\sat\sleast\s1433-1434\n\n5.\sReboot\n\nThe\smaximum\sTPS\sthat\syour\sserver\scan\ssustain\swill\sbe\s\n((MaxUserPort\s-\s1024\s-\s(number\sof\sreserved\sports))\s/\sTcpTimedWaitDelay)\swhen\sthe\nprocessing\slatency\sper\scall\sis\slow\s(and\slower\sas\slatency\sincreases).\n\nReferences\n\n-\sMS\sKB\s328476:\sDescription\sof\sTCP/IP\ssettings\sthat\syou\smay\shave\sto\sadjust\swhen\n\s\sSQL\sServer\sconnection\spooling\sis\sdisabled\n\s\shttp://support.microsoft.com/kb/328476\n\s\s\n-\sMS\sTechNet\s(Cable\sGuy\s-\sDec\s2005):\sWindows\sTCP/IP\sEphemeral,\sReserved,\sand\s\n\s\sBlocked\sPort\sBehavior\n\s\shttp://technet.microsoft.com/en-us/library/bb878133.aspx\n\s\s\n-\sIBM\sExpress:\sWeb\sserver\splug-in\stuning\stips\n\s\shttp://publib.boulder.ibm.com/infocenter/wasinfo/v6r1/index.jsp?topic=/com.ibm.websphere.express.doc/info/exp/ae/rprf_plugin.html\n\n-\sMS\sKB\s812873:\sHow\sto\sreserve\sa\srange\sof\sephemeral\sports\son\sa\scomputer\sthat\sis\n\s\srunning\sWindows\sServer\s2003\sor\sWindows\s2000\sServer\n\s\shttp://support.microsoft.com/kb/812873/\n\s\s\n
J foundin obsolete:\s8.6b1.1
J is_private 0
J priority 5\sMedium
J resolution None
J status Open
J submitter twylite
J subsystem 25.\sChannel\sSystem
J title Socket\s-server\sstops\saccepting\sconnections\sunder\sload
J type Bug
K 3056775fffffffffffffffffffffffffffffffff
U twylite
Z 884e58822904cf5118dcc60e4d9c31a3