473,804 Members | 3,757 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Asynchronous I/O really saves resources?

Asynchronous I/O is said to be using native completion port. However,
i checked rotor2.0 code, it seems not
in stream.cs. BeginRead is defined in below way. In my understanding,
If BeginInvoke is used, the task is queued; and when there is free
worker thread in ThreadPool, the task is performed in specified worker
thread. Then, Asynchronous I/O doesn't save thread in ThreadPool. Is
my understanding correct?
[HostProtection( ExternalThreadi ng=true)]
public virtual IAsyncResult BeginRead(byte[] buffer, int
offset, int count, AsyncCallback callback, Object state)
{
if (!CanRead) __Error.ReadNot Supported();

// Increment the count to account for this async operation
BCLDebug.Assert (_asyncActiveCo unt >= 1, "ref counting
mismatch, possible race in the code");
Interlocked.Inc rement(ref _asyncActiveCou nt);

ReadDelegate d = new ReadDelegate(Re ad);

// To avoid a race with a stream's position pointer &
generating race
// conditions with internal buffer indexes in our own
streams that
// don't natively support async IO operations when there
are multiple
// async requests outstanding, we will block the
application's main
// thread if it does a second IO request until the first
one completes.
if (_asyncActiveEv ent == null) {
lock(this) {
if (_asyncActiveEv ent == null)
_asyncActiveEve nt = new AutoResetEvent( true);
}
}
bool r = _asyncActiveEve nt.WaitOne();
BCLDebug.Assert (r, "AutoResetE vent didn't get a signal
when we called WaitOne!");

BCLDebug.Assert (_readDelegate == null && _writeDelegate ==
null, "Expected no other readers or writers!");

// Set delegate before we call BeginInvoke, to avoid a
race
_readDelegate = d;
IAsyncResult asyncResult = d.BeginInvoke(b uffer, offset,
count, callback, state);

return asyncResult;
}

Jun 26 '07 #1
3 1971
On Jun 26, 6:42 am, Morgan Cheng <morgan.chen... @gmail.comwrote :
Asynchronous I/O is said to be using native completion port. However,
i checked rotor2.0 code, it seems not
in stream.cs. BeginRead is defined in below way. In my understanding,
If BeginInvoke is used, the task is queued; and when there is free
worker thread in ThreadPool, the task is performed in specified worker
thread. Then, Asynchronous I/O doesn't save thread in ThreadPool. Is
my understanding correct?
1) The code for Rotor isn't exactly the same as the code for .NET
2) You're looking at just Stream.BeginRea d, which is virtual. Stream
itself can't use IO completion ports, as it doesn't know whether the
stream *actually* uses anything that IO completion ports are
interested in (think about StringReader, for example). Instead,
derived classes (such as FileStream) are responsible for providing
more performant implementations where appropriate.

Jon

Jun 26 '07 #2
On Jun 26, 3:09 pm, "Jon Skeet [C# MVP]" <s...@pobox.com wrote:
On Jun 26, 6:42 am, Morgan Cheng <morgan.chen... @gmail.comwrote :
Asynchronous I/O is said to be using native completion port. However,
i checked rotor2.0 code, it seems not
in stream.cs. BeginRead is defined in below way. In my understanding,
If BeginInvoke is used, the task is queued; and when there is free
worker thread in ThreadPool, the task is performed in specified worker
thread. Then, Asynchronous I/O doesn't save thread in ThreadPool. Is
my understanding correct?

1) The code for Rotor isn't exactly the same as the code for .NET
Yes, but I suppose major design is same.
2) You're looking at just Stream.BeginRea d, which is virtual. Stream
itself can't use IO completion ports, as it doesn't know whether the
stream *actually* uses anything that IO completion ports are
interested in (think about StringReader, for example). Instead,
derived classes (such as FileStream) are responsible for providing
more performant implementations where appropriate.
In some post, it is said FileStream is using completion port. In
FileStream.cs, it reads
return base.BeginRead( array, offset, numBytes, userCallback,
stateObject);
Simply call basclass(Stream )'s implementation.

Well, by calling BeginInvoke(), the queued task is surely called by
worker thread? or it is possible to be performed by I/O thread in
thread pool?

>
Jon

Jun 26 '07 #3
On Jun 26, 8:16 am, Morgan Cheng <morgan.chen... @gmail.comwrote :
1) The code for Rotor isn't exactly the same as the code for .NET

Yes, but I suppose major design is same.
It was at one point - but I doubt that nearly as much work as gone
into optimising Rotor. Bear in mind that Rotor also works on non-MS
platforms, not all of which even *have* IO completion ports.
2) You're looking at just Stream.BeginRea d, which is virtual. Stream
itself can't use IO completion ports, as it doesn't know whether the
stream *actually* uses anything that IO completion ports are
interested in (think about StringReader, for example). Instead,
derived classes (such as FileStream) are responsible for providing
more performant implementations where appropriate.

In some post, it is said FileStream is using completion port. In
FileStream.cs, it reads
return base.BeginRead( array, offset, numBytes, userCallback,
stateObject);
Simply call basclass(Stream )'s implementation.
For Rotor, right? Don't assume that's the same for .NET.
Well, by calling BeginInvoke(), the queued task is surely called by
worker thread? or it is possible to be performed by I/O thread in
thread pool?
That implementation will just use the thread pool, by the looks of it.
Again, don't assume the same is true for .NET itself.

Jon

Jun 26 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
1792
by: Sam Loveridge | last post by:
Hi all. I'm relatively new to delegates and asynchronous threading and am running into an issue. I need to asynchronously call a method (which I'm doing with a delegate and BeginInvoke) and from the callback method, or at some point after the EndInvoke has been called to end the asynchronous operation I need to asynchronously call a different method. I really want to keep this event based and use delegates and callbacks rather than loop...
6
3844
by: Anders Both | last post by:
In my application the fowing call: workSocket.BeginSend(byteData, 0, byteData.Length,0, new AsyncCallback(SendMesCallBack), null); Takes between 156250 and 312500 Ticks . And when like 20 calls are made at a time, they really sum up to something that I did not exspect att all. Why does I exspirence this thing, is this normal ? (I am 100% sure that the time is consumed by only this single line)
48
5440
by: Steve - DND | last post by:
I'm trying to determine if I need to make my application multi-threaded, or if it can be done with asynchronous programming. I realize that asynch calls do create a new thread in the background, but when they come back, they return to the thread that launched them, is that correct? If I go multi-threaded, then I just need to spawn a new thread for each new connection, right? What I'm doing here is making a service that accepts...
3
1432
by: Thomas Nielsen | last post by:
Hi, I need to make a web page that wait for 3 asynchronous processes to finish. So I am considering these options 1) Poll the status of the processes from the web page using the "REFRESH" metatag in HTML. 2) Synchronously call a monitor function on the server that poll the status of the processes, and returns when they are done.
4
3823
by: taskswap | last post by:
I have a legacy application written in C that I'm trying to convert to C#. It processes a very large amount of data from many clients (actually, upstream servers - this is a mux) simultaneously. I've read through what must be dozens of ways to do socket communication in C#, and it seems they all devolve into three basic options - Socket.Select, IOCP through a native interface, and Asynchronous callbacks. I'm fine using Asynchronous...
0
1760
by: Bishoy George | last post by:
Hi, I have a asp.net 2.0 web application. I want to implement the asynchronous model through http handler in web.config ------------------------------------------------------------------------------------------------------------------------- My web.config file: ---------------------
3
2098
by: =?Utf-8?B?bWs=?= | last post by:
Hi everyone, I need to refactor some of our processes using the asynchronous programming model. I have defined a couple of arrays of delegates to pipline the asynchronous invocations through different stages of execution. However I was wondering if there was any information available regarding the limitations of the asynchronous model, in particular maximum numbers of asynchronous elements, and limitations of multiple requests potentially...
3
1539
by: senfo | last post by:
I recently read an MSDN article by Jeff Prosise titled, Scalable Apps with Asynchronous Programming in ASP.NET (http://msdn.microsoft.com/msdnmag/issues/07/03/WickedCode/). In the article, Jeff discusses scaling problems that some users experience with ASP.NET applications. The problem, Jeff writes, isn't that ASP.NET isn't capable of scaling; but has more to do with ASP.NET applications that use threads inefficiently. In the article,...
2
3440
by: Nicolas Le Gland | last post by:
Hello everyone here. This is my first post in this newsgroup, I hope I won't be to much off-topic. Feel free to redirect me to any better group. I am getting strange timing issues when failing to asynchronously connect sockets on closed or filtered ports, but I'm quite unsure if this is a PHP issue or my misunderstanding, as it seems that socket streams only wrap around <sys/socket.h>.
0
9706
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10571
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10317
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9143
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7615
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5520
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3815
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2990
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.