Forum: Ruby Speed up require on win32

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
E1e2dd8c03c8e9e0680cfd802df0a04b?d=identicon&s=25 Alex 2k8 (alex_2k8)
on 2008-12-14 16:18
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
E1e2dd8c03c8e9e0680cfd802df0a04b?d=identicon&s=25 Alex 2k8 (alex_2k8)
on 2008-12-14 16:54
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?

- Alex
E0d864d9677f3c1482a20152b7cac0e2?d=identicon&s=25 Robert Klemme (Guest)
on 2008-12-14 20:41
(Received via mailing list)
My reply is over there in Usenet, apparently the attachment was too
large:

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

Cheers

robert
5e94c32913c94eb773bf5ca92da446f4?d=identicon&s=25 unknown (Guest)
on 2008-12-15 19:28
(Received via mailing list)
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
E0d864d9677f3c1482a20152b7cac0e2?d=identicon&s=25 Robert Klemme (Guest)
on 2008-12-16 00:23
(Received via mailing list)
On 15.12.2008 02:20, getcha.2k8@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
E1e2dd8c03c8e9e0680cfd802df0a04b?d=identicon&s=25 Alex 2k8 (alex_2k8)
on 2008-12-17 04:34
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...

- Alex
E0d864d9677f3c1482a20152b7cac0e2?d=identicon&s=25 Robert Klemme (Guest)
on 2008-12-17 09:49
(Received via mailing list)
2008/12/17 Alex 2k8 <abc3def@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

robert
76caedd87445c17860358841ae0de620?d=identicon&s=25 Lars Christensen (Guest)
on 2008-12-17 10:05
(Received via mailing list)
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.
Bec38d63650c8912b6ba9b557fb953b9?d=identicon&s=25 Roger Pack (rogerdpack)
on 2008-12-18 06:34
> 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
E1e2dd8c03c8e9e0680cfd802df0a04b?d=identicon&s=25 Alex 2k8 (alex_2k8)
on 2008-12-18 15:11
> 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.
This topic is locked and can not be replied to.