Live data from Hacker News

Everything .NET programmers know about Asynchronous Programming is wrong

hanselminutes.com

21–30 of 57 posts

Re: Everything .NET programmers know about Asynchronous Programming is wrong

#21
post #17

Earlier quoted context omitted.

> In fact, unless you're wasting time, 80,000,000 averages less than 10 requests/second... Please show your math. I took 80000000 / (24 * 60 * 60) and I got 925. So you seem off by about two orders of magnitude.

Please show your math. I took 80,000,000/86400 and I got 926. So you seem to be off by about 1.

I used bc. It's probably an issue of floor vs round....

Re: Everything .NET programmers know about Asynchronous Programming is wrong

#22
post #10

Genuine question... We have way over a million lines of c#, in asp.net, mvc and windows forms. We get 80,000,000 http requests a day. We have no async (delegates or 4.5 stuff), no threading other than what WCF, AppFabric and ASP.Net give us. About 25% is generic CRUD code but the rest is complicated matching, integration and math code. We also touch most fundamental computer science domains. This begs the question: y…

> This begs the question: you really need async in the language? Or even delegates. Or interfaces. Or LINQ. Basically you could write the same thing in C. Or assembly.

Strawman.

The parent isn't arguing that the new async constructs in the language don't make asynchronous programming easier.

He's questioning the need for using asynchronous programming models at all, for the common use case of ASP.NET applications.

Re: Everything .NET programmers know about Asynchronous Programming is wrong

#23
post #12

Genuine question... We have way over a million lines of c#, in asp.net, mvc and windows forms. We get 80,000,000 http requests a day. We have no async (delegates or 4.5 stuff), no threading other than what WCF, AppFabric and ASP.Net give us. About 25% is generic CRUD code but the rest is complicated matching, integration and math code. We also touch most fundamental computer science domains. This begs the question: y…

I think async is a systems programming tool rather than an application programming tool. If you're writing a web server or a web browser, it'd be useful. But for a web application, you're already sitting on a highly scalable and robust async library called IIS so when you need a background task the easiest thing to do is to make it a RESTful API call. I find many web developers now intuitively break up their applicat…

When you say that a background task should be made into a RESTful API call, I assume you mean that instead of spinning up a local thread to do the work you should defer it to another service. Certainly you can do that, but async/await is still relevant in that case.

The key question is: while said REST call is happening, what is the caller doing? Normally, he's sitting there and blocking his thread until the call finishes (i.e. consuming one thread from the connection thread pool). With async/await, the thread is released back into the thread pool until the result is ready, then it picks up where it left off.

So anything where you might want to deal with background operations that take a long time (including network / db / filesystem access, i.e. most applications that aren't pure functions) in a connection-oriented system can greatly benefit from async/await. Even if it's just a regular desktop app, it appears to be a useful mechanism for coordinating different background tasks.

Re: Everything .NET programmers know about Asynchronous Programming is wrong

#24

Genuine question... We have way over a million lines of c#, in asp.net, mvc and windows forms. We get 80,000,000 http requests a day. We have no async (delegates or 4.5 stuff), no threading other than what WCF, AppFabric and ASP.Net give us. About 25% is generic CRUD code but the rest is complicated matching, integration and math code. We also touch most fundamental computer science domains. This begs the question: y…

> This begs the question: you really need async in the language?

I too have applications that do a lot of stuff relying of asynchronous toolsets but without much explicit asynchronicity. However, I did a simple experiment a couple weeks back - I coded one of our simple but very asynchronous programs in Go. Compared to the Python original (which uses Twisted), the Go version had 70% of the lines and was much more readable and understandable by even team mates who had never seen Go.

I believe that's the point of having async operation elegantly merged into the language.

Re: Everything .NET programmers know about Asynchronous Programming is wrong

#25
post #23
post #12

Earlier quoted context omitted.

I think async is a systems programming tool rather than an application programming tool. If you're writing a web server or a web browser, it'd be useful. But for a web application, you're already sitting on a highly scalable and robust async library called IIS so when you need a background task the easiest thing to do is to make it a RESTful API call. I find many web developers now intuitively break up their applicat…

When you say that a background task should be made into a RESTful API call, I assume you mean that instead of spinning up a local thread to do the work you should defer it to another service. Certainly you can do that, but async/await is still relevant in that case. The key question is: while said REST call is happening, what is the caller doing? Normally, he's sitting there and blocking his thread until the call fin…

Your point is a good one. Without wanting to get too deep into a design for some hypothetical system, I guess I was thinking that I'd either try and modify the current request such that it can return something to its caller (e.g. Render a web page saying "Loading..." with a setTimeout call in it). Or use .NET's HTTP request library which has a delegate callback option that lets you get on with other stuff.

Re: Everything .NET programmers know about Asynchronous Programming is wrong

#26
post #25
post #23

Earlier quoted context omitted.

When you say that a background task should be made into a RESTful API call, I assume you mean that instead of spinning up a local thread to do the work you should defer it to another service. Certainly you can do that, but async/await is still relevant in that case. The key question is: while said REST call is happening, what is the caller doing? Normally, he's sitting there and blocking his thread until the call fin…

Your point is a good one. Without wanting to get too deep into a design for some hypothetical system, I guess I was thinking that I'd either try and modify the current request such that it can return something to its caller (e.g. Render a web page saying "Loading..." with a setTimeout call in it). Or use .NET's HTTP request library which has a delegate callback option that lets you get on with other stuff.

One benefit to something like async/await is letting you get on with other stuff without having to murk up your code with callbacks/delegates which read more like GOTOs than async/await.

Re: Everything .NET programmers know about Asynchronous Programming is wrong

#27

Genuine question... We have way over a million lines of c#, in asp.net, mvc and windows forms. We get 80,000,000 http requests a day. We have no async (delegates or 4.5 stuff), no threading other than what WCF, AppFabric and ASP.Net give us. About 25% is generic CRUD code but the rest is complicated matching, integration and math code. We also touch most fundamental computer science domains. This begs the question: y…

Need? Of course not. It's always been possible to do the same thing "by hand". But you certainly do need to not have all your threads blocking while external calls happen (although from elsewhere in the thread it sounds like your peak is 500 requests/second/machine? That's not so many, maybe you can afford to make blocking DB calls in the request path), one way or another.

A better question is how many lines of code the async feature saves, compared to the code you would write without it.

Re: Everything .NET programmers know about Asynchronous Programming is wrong

#28
post #12

Earlier quoted context omitted.

I think async is a systems programming tool rather than an application programming tool. If you're writing a web server or a web browser, it'd be useful. But for a web application, you're already sitting on a highly scalable and robust async library called IIS so when you need a background task the easiest thing to do is to make it a RESTful API call. I find many web developers now intuitively break up their applicat…

The problem is that it's pretty useless in non-systems programming language.

It is pretty useful for ui stuff, you can start a wait cursor in a button event, do what you need to then put the cursor back when your done, all in one thread without having to use background threads or anything.

It is pretty simple for that scenario and avoids the cross thread marshalling you need to do in win forms.

Re: Everything .NET programmers know about Asynchronous Programming is wrong

#30

Genuine question... We have way over a million lines of c#, in asp.net, mvc and windows forms. We get 80,000,000 http requests a day. We have no async (delegates or 4.5 stuff), no threading other than what WCF, AppFabric and ASP.Net give us. About 25% is generic CRUD code but the rest is complicated matching, integration and math code. We also touch most fundamental computer science domains. This begs the question: y…

There millions if not billions of lines of c code in production today doing everything from web servers/cgi web pages to low level embedded oses. A shit ton of it is not using oo programming: do we really need it?

It's about doing more, better, and easier. async allows a pretty complicated process to be much easier to write.

Post reply on HN