win32 File.size slow?

N

Nation, Carey

Last week I posted a question about incorrect file sizes coming back
incorrectly from File.size? for really large files. I changed my script
to use the win32 version, which returns the correct sizes, and now the
script is unacceptably slow. The bottleneck is the File.size call. My
scripts startup went from about a minute to, well I don't know because
it's never finished. I'm walking a file path that is somewhat indirect,
but the other file operations perform well. I'm reading files, using
UNC paths, through samba on linux boxes that mount a giant file system
through fiber.

=20

So anyway, does anyone have any alternatives?

=20

________________________________

Carey Nation <mailto:[email protected]> =20

Lead Software Engineer

CNN BEST

Broadcast Production Systems

Video Solutions Group

(404)827-2935 (wk)

(404)824-0033 (cell)

________________________________

=20
 
D

Daniel Berger

Last week I posted a question about incorrect file sizes coming back
incorrectly from File.size? for really large files. =A0I changed my script=
to use the win32 version, which returns the correct sizes, and now the
script is unacceptably slow. The bottleneck is the File.size call. My
scripts startup went from about a minute to, well I don't know because
it's never finished. =A0I'm walking a file path that is somewhat indirect,=
but the other file operations perform well. =A0I'm reading files, using
UNC paths, through samba on linux boxes that mount a giant file system
through fiber.

That's interesting. The File.size method is really a wrapper for
File::Stat#size, which uses stat64() to stat the file in question. I
wonder if it's choking on the Samba/UNC path. Wouldn't be the first
app to do so.

What happens if you replace File.size in lib/win32/file.rb with this
version:

# Untested
class << self
def size(file)
handle =3D CreateFile(
file,
GENERIC_READ,
FILE_SHARE_READ,
nil,
OPEN_EXISTING,
FILE_FLAG_OVERLAPPED | FILE_FLAG_NO_BUFFERING,
nil
)

if handle =3D=3D INVALID_HANDLE_VALUE
raise Error, get_last_error
end

file_size =3D [0].pack('Q')
GetFileSizeEx(handle, file_size)
file_size =3D file_size.unpack('Q')[0]

unless CloseHandle(handle)
raise Error, get_last_error
end

file_size
end
end
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,157
Latest member
MercedesE4
Top