Go Back   ZeroC Forums > Bug Reports

Reply
 
LinkBack Thread Tools Rate Thread Display Modes
  #16 (permalink)  
Old 12-23-2007
michi's Avatar
michi michi is offline
ZeroC Staff
 
Name: Michi Henning
Organization: ZeroC
Project: Ice
 
Join Date: Feb 2003
Location: Brisbane, Australia
Posts: 896
Thanks for the tip. Someone on the Mono mailing list mentioned the bind() option to me too. I'll try this out. If it works, that'll get rid of the P/Invoke in this case.

We are using P/Invoke in a number of other places to work around limitations of .NET, and we also use P/Invoke for protocol compression. Getting rid of all of these might be difficult.

Cheers,

Michi.
Reply With Quote
  #17 (permalink)  
Old 12-23-2007
kwaclaw kwaclaw is offline
Registered User
 
Name: Karl Waclawek
Organization: Toronto Star Newspapers Ltd.
Project: Proof of concept
 
Join Date: Sep 2004
Location: Oshawa, Canada
Posts: 128
Quote:
Originally Posted by michi View Post
Thanks for the tip. Someone on the Mono mailing list mentioned the bind() option to me too. I'll try this out. If it works, that'll get rid of the P/Invoke in this case.

We are using P/Invoke in a number of other places to work around limitations of .NET, and we also use P/Invoke for protocol compression. Getting rid of all of these might be difficult.

Cheers,

Michi.
It probably requires some study as to which managed API is a good replacement for some of your interop calls. I just had a quick look, and maybe there are a few avenues worth looking at:

1) For SetConsoleCtrlHandler, the Console.CancelKeyPressEvent would be an alternative, as long as all you care about is capturing Ctrl+C and Ctrl+Break.

2) It looks as if Guid.NewGuid() does the same as UUIDCreate in rpcrt4.dll.

3) It seems there is also a managed alternative for libbz2.dll:
.NET Zip Library #ziplib (SharpZipLib)

Karl
__________________
Karl Waclawek
The Toronto Star - http://www.thestar.com
Reply With Quote
  #18 (permalink)  
Old 12-24-2007
matthew's Avatar
matthew matthew is offline
ZeroC Staff
 
Name: Matthew Newhook
Organization: ZeroC, Inc.
Project: Internet Communications Engine
 
Join Date: Feb 2003
Location: NL, Canada
Posts: 1,027
How much of a performance cost are you willing to bear? Some of the marshaling code is also unsafe -- this could be replaced with safe code but its quite a bit slower.

What environments you are considering that require fully manged code?
Reply With Quote
  #19 (permalink)  
Old 12-24-2007
kwaclaw kwaclaw is offline
Registered User
 
Name: Karl Waclawek
Organization: Toronto Star Newspapers Ltd.
Project: Proof of concept
 
Join Date: Sep 2004
Location: Oshawa, Canada
Posts: 128
Quote:
Originally Posted by matthew View Post
How much of a performance cost are you willing to bear? Some of the marshaling code is also unsafe -- this could be replaced with safe code but its quite a bit slower.

What environments you are considering that require fully manged code?
We have an internal ASP.NET site that runs assemblies in semi-trusted mode. That excludes unsafe code and native interop. We are also considering running one of our apps from a web server (to simplify deployment). Though this app is currently not using ICE, I would not want to exclude ICE in the future simply because it can only run in a fully trusted context. I would also think that in Silverlight 2.0 (which apparently will have Socket support) using full IceCS instead of the HTTP bridge would be advantageous.

I have looked at your ByteBuffer class, the only place where I found unsafe code. I think the overall performance impact might not be as bad. It appears the unsafe code is mostly used for marshaling value types. For example, once could replace the unsafe getShort() and putShort() methods with this (untested!) code:

Code:
private const UInt16 ByteLoMask = 0x00FF;

public short getShort()
{
  unchecked {
    checkUnderflow(2);
    int ret;
    if(NO._o == _order)
    {
      ret = (_bytes[_position] << 8;
      ret |= _bytes[_position + 1];
    }
    else
    {
      ret = _bytes[_position + 1] << 8;
      ret |= _bytes[_position];
    }
    position += 2;
    return (short)ret;
  }
}

public ByteBuffer putShort(short val)
{
  unchecked {
    checkOverflow(2);
    if(NO._o == _order)
    {
      _bytes[_position] = (byte)(value >> 8);
      _bytes[_position + 1] = (byte)(value & ByteLoMask);
    }
    else
    {
      _bytes[_position + 1] = (byte)(value >> 8);
      _bytes[_position] = (byte)(value & ByteLoMask);
    }
    _position += 2;
  }	
  return this;
}
with no significant performance loss.

Karl
__________________
Karl Waclawek
The Toronto Star - http://www.thestar.com
Reply With Quote
  #20 (permalink)  
Old 12-24-2007
michi's Avatar
michi michi is offline
ZeroC Staff
 
Name: Michi Henning
Organization: ZeroC
Project: Ice
 
Join Date: Feb 2003
Location: Brisbane, Australia
Posts: 896
I agree that getting rid of the P/Invoke calls and the unsafe code would be nice. I wasn't aware that there is a .NET compression library available now--it's worth a try.

It will still be difficult to get rid off all the P/Invoke code though. We are using it for monotonic time, and CancelKeyPressEvent doesn't deal with window closure, logoff, and shutdown events (which SetConsoleCtrlHandler does).

Cheers,

Michi.
Reply With Quote
  #21 (permalink)  
Old 12-24-2007
matthew's Avatar
matthew matthew is offline
ZeroC Staff
 
Name: Matthew Newhook
Organization: ZeroC, Inc.
Project: Internet Communications Engine
 
Join Date: Feb 2003
Location: NL, Canada
Posts: 1,027
Quote:
Originally Posted by kwaclaw View Post
...

with no significant performance loss.

Karl
Its also possible to use BitConverter. At any rate, for sure its slower depending on what your application is doing (for example, marshaling an array of shorts or similar). The question is whether this matters to you
Reply With Quote
  #22 (permalink)  
Old 12-25-2007
kwaclaw kwaclaw is offline
Registered User
 
Name: Karl Waclawek
Organization: Toronto Star Newspapers Ltd.
Project: Proof of concept
 
Join Date: Sep 2004
Location: Oshawa, Canada
Posts: 128
Quote:
Originally Posted by matthew View Post
Its also possible to use BitConverter. At any rate, for sure its slower depending on what your application is doing (for example, marshaling an array of shorts or similar). The question is whether this matters to you
From my experience, .NET optimizes quite well, and since there is also a little overhead pinning memory (as in the 'fixed' statement), I did some benchmarking myself, using your ByteBuffer, but adding safe variants of putInt(), getInt(), putIntSeq() and getIntSeq(). I thought a performance difference would show up more clearly for ints than for shorts. The safe variants are coded like what I outlined previously. I built the app under VS 2005 in release mode, as debug mode is actually slower for this kind of application.

In my measurements, the safe code was most of the time *faster* than the unsafe code (it varied from one test run to the other). I also uncovered one specific *huge* performance issue with your code: if it has to reverse the byte order, the unsafe code is more than 10 times as slow as the safe code. This is normally the case on little-endian CPUs, i.e. almost always. The reason I think is the use of all those Buffer.SetByte/GetByte calls that are obviously not inlined by the compiler.

My CPU is an Athlon x64 dual core 3600.
If you like, I can send you the VS 2005 project (just tell where to) so that you can check for yourself and try it on other CPUs.

Karl
__________________
Karl Waclawek
The Toronto Star - http://www.thestar.com
Reply With Quote
  #23 (permalink)  
Old 12-25-2007
kwaclaw kwaclaw is offline
Registered User
 
Name: Karl Waclawek
Organization: Toronto Star Newspapers Ltd.
Project: Proof of concept
 
Join Date: Sep 2004
Location: Oshawa, Canada
Posts: 128
Quote:
Originally Posted by michi View Post
I agree that getting rid of the P/Invoke calls and the unsafe code would be nice. I wasn't aware that there is a .NET compression library available now--it's worth a try.

It will still be difficult to get rid off all the P/Invoke code though. We are using it for monotonic time, and CancelKeyPressEvent doesn't deal with window closure, logoff, and shutdown events (which SetConsoleCtrlHandler does).

Cheers,

Michi.
I could not find any P/Invoke calls that are time related. Where should I look?

Regarding SetConsoleCtrlHandler : It is only used in your helper class, so it is not an essential part of IceCS. Maybe one could spin off non-essential classes into a separate assembly?

Karl
__________________
Karl Waclawek
The Toronto Star - http://www.thestar.com
Reply With Quote
  #24 (permalink)  
Old 12-26-2007
michi's Avatar
michi michi is offline
ZeroC Staff
 
Name: Michi Henning
Organization: ZeroC
Project: Ice
 
Join Date: Feb 2003
Location: Brisbane, Australia
Posts: 896
Quote:
Originally Posted by kwaclaw View Post
In my measurements, the safe code was most of the time *faster* than the unsafe code (it varied from one test run to the other).
I benchmarked this fairly extensively when I initially wrote the C# implementation. Back then, the unsafe version was faster than than the safe one. But that was several iterations of the compiler and run time ago, so this may have changed in the mean time.

Quote:
I also uncovered one specific *huge* performance issue with your code: if it has to reverse the byte order, the unsafe code is more than 10 times as slow as the safe code. This is normally the case on little-endian CPUs, i.e. almost always. The reason I think is the use of all those Buffer.SetByte/GetByte calls that are obviously not inlined by the compiler.
I'll have a look at this too. It may well be that doing this differently will be faster now with the later version of the compiler and run time. Note that the byte order on the wire is little-endian--for little-endian CPUs, no byte swapping should take place.

Quote:
If you like, I can send you the VS 2005 project (just tell where to) so that you can check for yourself and try it on other CPUs.
Yes, that would be useful. Can you just email me the code please?

Thanks,

Michi.
Reply With Quote
  #25 (permalink)  
Old 12-26-2007
kwaclaw kwaclaw is offline
Registered User
 
Name: Karl Waclawek
Organization: Toronto Star Newspapers Ltd.
Project: Proof of concept
 
Join Date: Sep 2004
Location: Oshawa, Canada
Posts: 128
Quote:
Originally Posted by michi View Post
Yes, that would be useful. Can you just email me the code please?

Thanks,

Michi.
I e-mailed the code to the e-mail address on your home page, hope that is the correct one.

Karl
__________________
Karl Waclawek
The Toronto Star - http://www.thestar.com
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
icecs.dll and Mono kwaclaw Comments 1 11-15-2007 07:28 PM
Mono and IceSSL Status tkrieger Help Center 6 11-10-2006 08:29 AM
IcePack + Debian Linux + Mono + NoEndpointException kovacm Bug Reports 10 07-20-2005 06:29 AM
Problems compiling IceCS with mono on Fedora Core 3 iostream Help Center 5 12-10-2004 05:52 PM
mono c# on win32 panic Help Center 5 12-13-2003 07:14 PM


All times are GMT -4. The time now is 12:41 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0
(c) 2008 ZeroC, Inc.