Issue 3173: First call to winsock async connect is slow
http://code.google.com/p/chromium/issues/detail?id=3173
New issue report by [EMAIL PROTECTED]:
I have been doing some startup profiling. I found that on the first call
to ws2_32!connect(), if the socket is async, a bunch of internal work is
performed and a helper thread is spawned. The first call to connect()
takes about 6ms on my machine, all calls after are about 20x faster. One
strategy I tried was to warm up winsock by making a connect() while we are
waiting on the first dns request, avoiding a 6ms block. I verified that
ConnectEx() avoids all of this startup work, so that is probably the
correct solution.
>async_connect.exe
freq: 3579545
25630
1008
1790
844
832
#include <winsock2.h>
#include <mswsock.h>
#include <stdio.h>
void do_connect() {
SOCKET s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
unsigned long opt = 1;
ioctlsocket(s, FIONBIO, &opt);
struct sockaddr_in sa;
sa.sin_family = AF_INET;
sa.sin_addr.s_addr = 0;
sa.sin_port = 0;
connect(s, (SOCKADDR*)&sa, sizeof(sa));
closesocket(s);
}
int main() {
WORD winsock_ver = MAKEWORD(2,2);
WSAData wsa_data;
WSAStartup(winsock_ver, &wsa_data);
LARGE_INTEGER freq, start, end;
QueryPerformanceFrequency(&freq);
printf("freq: %I64d\n", freq.QuadPart);
for (int i = 0; i < 5; ++i) {
QueryPerformanceCounter(&start);
do_connect();
QueryPerformanceCounter(&end);
printf("%I64d\n", end.QuadPart - start.QuadPart);
}
}
Issue attributes:
Status: Assigned
Owner: [EMAIL PROTECTED]
CC: [EMAIL PROTECTED], [EMAIL PROTECTED]
Labels: Type-Bug Pri-2 OS-All Area-Misc
--
You received this message because you are listed in the owner
or CC fields of this issue, or because you starred this issue.
You may adjust your issue notification preferences at:
http://code.google.com/hosting/settings
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Chromium-bugs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/chromium-bugs?hl=en
-~----------~----~----~----~------~----~------~--~---