Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Speed up require on win32

15 views
Skip to first unread message

Alex 2k8

unread,
Dec 14, 2008, 10:11:21 AM12/14/08
to
Hello,

I am trying to speedup the ruby1.8.6 'require' function for Windows.
I've noticed that for file that successfully found FileMon reports too
many such errors:

DeviceIoControl, FAST IO DISALLOWED, Control: 0x12043
DeviceIoControl, INVALID PARAMETER, Control: 0x12043

One of the sources of these messages is:
win32.c > rb_w32_fclose > is_socket > getsockopt

I decided to reproduce this error. So, I wrote a test application linked
with msvcr80-ruby18-static.lib:

- - - - -
FILE * fp = fopen(fname, "r");
fclose(fp); // This results in rb_w32_fclose call.
- - - - -

But I do NOT get DeviceIoControl errors from my_test!

So in short
1. I get DeviceIoControl errors from rb_w32_fclose called by ruby.exe
2. I do NOT get DeviceIoControl from rb_w32_fclose called by my_test.exe
3. Errors come from the 'getsockopt' function.

Can any one explain this, please? How can we avoid errors comming from
ruby.exe?

Thank you,
- Alex
--
Posted via http://www.ruby-forum.com/.

Alex 2k8

unread,
Dec 14, 2008, 10:47:10 AM12/14/08
to
Aha.. I forgot to call WSAStartup. No my_test.exe reports
DeviceIoControl errors too.

Btw, is not there any better alternative for 'win32.c > is_socket'
function?

Robert Klemme

unread,
Dec 14, 2008, 1:26:05 PM12/14/08
to
On 14.12.2008 16:47, Alex 2k8 wrote:
> Aha.. I forgot to call WSAStartup. No my_test.exe reports
> DeviceIoControl errors too.
>
> Btw, is not there any better alternative for 'win32.c > is_socket'
> function?

I did this with cygwin's version of Ruby

$ ruby -r a -e '1'

There was an empty file a.rb in the current directory.

I used Process Monitor 2.03 which is the successor of File Mon. I
exported the trace filtered for the file name in field "Path" and
"Process Name" for "ruby.exe". Please find the result attached. I did
not find any DeviceIoControl which might be because of the other ruby
version.

HTH

Cheers

robert

Logfile.CSV

Robert Klemme

unread,
Dec 14, 2008, 2:32:26 PM12/14/08
to
My reply is over there in Usenet, apparently the attachment was too large:

http://groups.google.com/group/comp.lang.ruby/msg/8f85de91d3c3ba77

Cheers

robert

--
remember.guy do |as, often| as.you_can - without end

getch...@gmail.com

unread,
Dec 14, 2008, 8:20:10 PM12/14/08
to
Hello, Robert

Your logs looks good.

I tested again in such environment:
OS: Vista
Process Monitor: 2.03
Ruby: 1.8.6, 1.8.7, 1.9.0

Used the same a.rb and command line as you. I got similar results for
all ruby versions: every successfull read of a.rb is followed by ~60
DeviceIoControl.

I can't attach my CVS (posting from google site). How did you attach
it?

- Alex

Robert Klemme

unread,
Dec 15, 2008, 1:17:35 AM12/15/08
to
On 15.12.2008 02:20, getch...@gmail.com wrote:
> Hello, Robert
>
> Your logs looks good.

And I also do not notice any slowdowns of require.

> I tested again in such environment:
> OS: Vista
> Process Monitor: 2.03
> Ruby: 1.8.6, 1.8.7, 1.9.0

My version was

ruby 1.8.7 (2008-08-11 patchlevel 72) [i386-cygwin]

> Used the same a.rb and command line as you. I got similar results for
> all ruby versions: every successfull read of a.rb is followed by ~60
> DeviceIoControl.

Maybe it's in your environment? Do you somehow require "rubygems"?

> I can't attach my CVS (posting from google site). How did you attach
> it?

I sent it via Newsreader to the newsgroup comp.lang.ruby.

Kind regards

robert

Alex 2k8

unread,
Dec 16, 2008, 10:26:39 PM12/16/08
to
Hi, Robert

> ruby 1.8.7 (2008-08-11 patchlevel 72) [i386-cygwin]

Probably cygwin is not calling the same OS functions.

> Maybe it's in your environment? Do you somehow require "rubygems"?

I tested on Windows Server 2003. And I tryed with/without rubygems -
same results.

Btw, I compiled ruby from sources, and changed rb_w32_fclose.

//if (!is_socket(sock)) {
if(1) {
...
return fclose(fp);
}

The DeviceIoControl lines are gone. Then I checked the speed. I
installed rails 2.2.2, then did:
1. irb -rubygems
2. s = Time.now; require 'activesupport'; e = Time.now; e.to_f - s.to_f

For normal ruby results was:
~ 1.16 sec

For patched ruby:
~ 1.00 sec

Not a big advantage, but any way. Going to see if in more complex
situations this can be more valuable...

Robert Klemme

unread,
Dec 17, 2008, 3:41:17 AM12/17/08
to
2008/12/17 Alex 2k8 <abc...@gmail.com>:

>> ruby 1.8.7 (2008-08-11 patchlevel 72) [i386-cygwin]
> Probably cygwin is not calling the same OS functions.

Yes, that's a likely explanation.

> For normal ruby results was:
> ~ 1.16 sec
>
> For patched ruby:
> ~ 1.00 sec
>
> Not a big advantage, but any way. Going to see if in more complex
> situations this can be more valuable...

I don't think it's worth the hassle. Just my 0.02EUR...

Kind regards

Lars Christensen

unread,
Dec 17, 2008, 4:00:36 AM12/17/08
to
On Dec 17, 4:26 am, Alex 2k8 <abc3...@gmail.com> wrote:
> Hi, Robert
>
> > ruby 1.8.7 (2008-08-11 patchlevel 72) [i386-cygwin]
>
> Probably cygwin is not calling the same OS functions.
>
> > Maybe it's in your environment?  Do you somehow require "rubygems"?
>
> I tested on Windows Server 2003. And I tryed with/without rubygems -
> same results.

I see the same issue here, with MSVC builds. However, with MingW
builds, i don't get the problem. The is_socket function you mention
has been changed significantly in 1.9.1 anyway.

Roger Pack

unread,
Dec 18, 2008, 12:26:53 AM12/18/08
to

> For normal ruby results was:
> ~ 1.16 sec
>
> For patched ruby:
> ~ 1.00 sec
>
> Not a big advantage, but any way. Going to see if in more complex
> situations this can be more valuable...
>
> - Alex

Submit a patch to core :)
-=R

Alex 2k8

unread,
Dec 18, 2008, 9:03:14 AM12/18/08
to
> Submit a patch to core :)

This was not a patch, just an experiment. I simply commented a call to
is_socket in rb_w32_fclose function. The 'require' works, but socket
related functionality whould be broken :-) And as for now I see no
significant improvements, not going to continue.

0 new messages