Discussion:
HTTP PUT File upload-Delay in InternetWriteFile() function!
(too old to reply)
Nathan
2007-12-14 05:44:00 UTC
Permalink
Hello,
I am using wininet SDK to upload a file using HTTP PUT to a folder in Apache
Tomcat. Truncated code in c++ is as follows:
hRequest = HttpOpenRequest (hConnect, pwcsOperation, (wchar_t*)
cstrRecStoreFilePath, NULL, NULL, NULL, 0, 0);
hFile = CreateFile (pwcsUploadFileName, GENERIC_READ, FILE_SHARE_READ,
NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);

ZeroMemory(&BufferIn, sizeof(INTERNET_BUFFERS)); // Extra
BufferIn.dwBufferTotal = GetFileSize (hFile, NULL);
BufferIn.dwStructSize = sizeof(INTERNET_BUFFERS); // Extra

InternetSetOption(hRequest, INTERNET_OPTION_SEND_TIMEOUT |
INTERNET_OPTION_CONNECT_TIMEOUT, &dwTimeout, sizeof(DWORD));

if(!HttpSendRequestEx( hRequest, &BufferIn, NULL, HSR_INITIATE &
HSR_ASYNC, 0))
{

InternetGetLastResponseInfoW(&dwError, (wchar_t*) wcsBuffer,
&dwBufferSize);
}
DWORD sum = 0;
do
{
if (!(bRead = ReadFile (hFile, pBuffer, sizeof(pBuffer), &dwBytesRead,
NULL)))
{

break;

}

if (!(bRet=InternetWriteFile( hRequest, pBuffer, dwBytesRead,
&dwBytesWritten)))
{
break;
}
sum += dwBytesWritten;
}
while (sum < BufferIn.dwBufferTotal) ;

// Close File handle
CloseHandle (hFile);
if(!HttpEndRequest(hRequest, NULL, HSR_ASYNC, 0))
{
if (hFile)

{
CloseHandle (hFile);
hFile = NULL;

}
if (hRequest)

{
InternetCloseHandle (hRequest);
hRequest = NULL;

}
return FALSE;

}
// Handle cleanup code
}

catch (...)

{

}

The problem I have is that InternetWriteFile function is causing a delay:
takes more than a second for a file size 10KB. The network connection is 100
MBPS LAN between the machines.

1. What are the possible reasons for InternetWriteFile delay?
2. Is there any permission on the folder that I am missing?
3. If it is a HTTP issue, how do we diagnose the delay?

Any suggestions or inputs appreciated.
Volodymyr Shcherbyna
2007-12-14 08:31:30 UTC
Permalink
Measure precise delay in release binary using GetTickCount function blocks
(before uploading and after file has been uploaded) and please provide
results here.
--
Volodymyr
Post by Nathan
Hello,
I am using wininet SDK to upload a file using HTTP PUT to a folder in Apache
hRequest = HttpOpenRequest (hConnect, pwcsOperation, (wchar_t*)
cstrRecStoreFilePath, NULL, NULL, NULL, 0, 0);
hFile = CreateFile (pwcsUploadFileName, GENERIC_READ,
FILE_SHARE_READ,
NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
ZeroMemory(&BufferIn, sizeof(INTERNET_BUFFERS)); // Extra
BufferIn.dwBufferTotal = GetFileSize (hFile, NULL);
BufferIn.dwStructSize = sizeof(INTERNET_BUFFERS); // Extra
InternetSetOption(hRequest, INTERNET_OPTION_SEND_TIMEOUT |
INTERNET_OPTION_CONNECT_TIMEOUT, &dwTimeout, sizeof(DWORD));
if(!HttpSendRequestEx( hRequest, &BufferIn, NULL, HSR_INITIATE &
HSR_ASYNC, 0))
{
InternetGetLastResponseInfoW(&dwError, (wchar_t*) wcsBuffer,
&dwBufferSize);
}
DWORD sum = 0;
do
{
if (!(bRead = ReadFile (hFile, pBuffer, sizeof(pBuffer), &dwBytesRead,
NULL)))
{
break;
}
if (!(bRet=InternetWriteFile( hRequest, pBuffer, dwBytesRead,
&dwBytesWritten)))
{
break;
}
sum += dwBytesWritten;
}
while (sum < BufferIn.dwBufferTotal) ;
// Close File handle
CloseHandle (hFile);
if(!HttpEndRequest(hRequest, NULL, HSR_ASYNC, 0))
{
if (hFile)
{
CloseHandle (hFile);
hFile = NULL;
}
if (hRequest)
{
InternetCloseHandle (hRequest);
hRequest = NULL;
}
return FALSE;
}
// Handle cleanup code
}
catch (...)
{
}
takes more than a second for a file size 10KB. The network connection is 100
MBPS LAN between the machines.
1. What are the possible reasons for InternetWriteFile delay?
2. Is there any permission on the folder that I am missing?
3. If it is a HTTP issue, how do we diagnose the delay?
Any suggestions or inputs appreciated.
Nathan
2007-12-14 15:15:01 UTC
Permalink
Thanks for your reply. Here is putput for uploading a file with a size of
24104 bytes

Output:
InternetOpenW-16 ms
HttpOpenRequestW-0 ms
CreateFileW-0 ms
HttpSendRequestExW-140 ms
InternetWriteFile-1438 ms
CloseHandle-0 ms
Actual written bytes-24104
HttpEndRequest-0 ms
InternetCloseHandle-0 ms

Thanks.
Post by Volodymyr Shcherbyna
Measure precise delay in release binary using GetTickCount function blocks
(before uploading and after file has been uploaded) and please provide
results here.
--
Volodymyr
Post by Nathan
Hello,
I am using wininet SDK to upload a file using HTTP PUT to a folder in Apache
hRequest = HttpOpenRequest (hConnect, pwcsOperation, (wchar_t*)
cstrRecStoreFilePath, NULL, NULL, NULL, 0, 0);
hFile = CreateFile (pwcsUploadFileName, GENERIC_READ,
FILE_SHARE_READ,
NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
ZeroMemory(&BufferIn, sizeof(INTERNET_BUFFERS)); // Extra
BufferIn.dwBufferTotal = GetFileSize (hFile, NULL);
BufferIn.dwStructSize = sizeof(INTERNET_BUFFERS); // Extra
InternetSetOption(hRequest, INTERNET_OPTION_SEND_TIMEOUT |
INTERNET_OPTION_CONNECT_TIMEOUT, &dwTimeout, sizeof(DWORD));
if(!HttpSendRequestEx( hRequest, &BufferIn, NULL, HSR_INITIATE &
HSR_ASYNC, 0))
{
InternetGetLastResponseInfoW(&dwError, (wchar_t*) wcsBuffer,
&dwBufferSize);
}
DWORD sum = 0;
do
{
if (!(bRead = ReadFile (hFile, pBuffer, sizeof(pBuffer), &dwBytesRead,
NULL)))
{
break;
}
if (!(bRet=InternetWriteFile( hRequest, pBuffer, dwBytesRead,
&dwBytesWritten)))
{
break;
}
sum += dwBytesWritten;
}
while (sum < BufferIn.dwBufferTotal) ;
// Close File handle
CloseHandle (hFile);
if(!HttpEndRequest(hRequest, NULL, HSR_ASYNC, 0))
{
if (hFile)
{
CloseHandle (hFile);
hFile = NULL;
}
if (hRequest)
{
InternetCloseHandle (hRequest);
hRequest = NULL;
}
return FALSE;
}
// Handle cleanup code
}
catch (...)
{
}
takes more than a second for a file size 10KB. The network connection is 100
MBPS LAN between the machines.
1. What are the possible reasons for InternetWriteFile delay?
2. Is there any permission on the folder that I am missing?
3. If it is a HTTP issue, how do we diagnose the delay?
Any suggestions or inputs appreciated.
Volodymyr Shcherbyna
2007-12-19 11:54:10 UTC
Permalink
Possible delay at InternetWriteFile can be caused by wininet caching of data
and the cache logics. If you have requirment to tight within time
constraints, I would consider on your place using own code to put a file on
web server. This would not require much coding, and will allow you to win in
perfomance.
--
Volodymyr
Post by Nathan
Thanks for your reply. Here is putput for uploading a file with a size of
24104 bytes
InternetOpenW-16 ms
HttpOpenRequestW-0 ms
CreateFileW-0 ms
HttpSendRequestExW-140 ms
InternetWriteFile-1438 ms
CloseHandle-0 ms
Actual written bytes-24104
HttpEndRequest-0 ms
InternetCloseHandle-0 ms
Thanks.
Post by Volodymyr Shcherbyna
Measure precise delay in release binary using GetTickCount function blocks
(before uploading and after file has been uploaded) and please provide
results here.
--
Volodymyr
Post by Nathan
Hello,
I am using wininet SDK to upload a file using HTTP PUT to a folder in Apache
hRequest = HttpOpenRequest (hConnect, pwcsOperation, (wchar_t*)
cstrRecStoreFilePath, NULL, NULL, NULL, 0, 0);
hFile = CreateFile (pwcsUploadFileName, GENERIC_READ,
FILE_SHARE_READ,
NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
ZeroMemory(&BufferIn, sizeof(INTERNET_BUFFERS)); // Extra
BufferIn.dwBufferTotal = GetFileSize (hFile, NULL);
BufferIn.dwStructSize = sizeof(INTERNET_BUFFERS); // Extra
InternetSetOption(hRequest, INTERNET_OPTION_SEND_TIMEOUT |
INTERNET_OPTION_CONNECT_TIMEOUT, &dwTimeout, sizeof(DWORD));
if(!HttpSendRequestEx( hRequest, &BufferIn, NULL, HSR_INITIATE &
HSR_ASYNC, 0))
{
InternetGetLastResponseInfoW(&dwError, (wchar_t*) wcsBuffer,
&dwBufferSize);
}
DWORD sum = 0;
do
{
if (!(bRead = ReadFile (hFile, pBuffer, sizeof(pBuffer), &dwBytesRead,
NULL)))
{
break;
}
if (!(bRet=InternetWriteFile( hRequest, pBuffer, dwBytesRead,
&dwBytesWritten)))
{
break;
}
sum += dwBytesWritten;
}
while (sum < BufferIn.dwBufferTotal) ;
// Close File handle
CloseHandle (hFile);
if(!HttpEndRequest(hRequest, NULL, HSR_ASYNC, 0))
{
if (hFile)
{
CloseHandle (hFile);
hFile = NULL;
}
if (hRequest)
{
InternetCloseHandle (hRequest);
hRequest = NULL;
}
return FALSE;
}
// Handle cleanup code
}
catch (...)
{
}
takes more than a second for a file size 10KB. The network connection
is
100
MBPS LAN between the machines.
1. What are the possible reasons for InternetWriteFile delay?
2. Is there any permission on the folder that I am missing?
3. If it is a HTTP issue, how do we diagnose the delay?
Any suggestions or inputs appreciated.
Loading...