Asynchrony in (ASP).NET Aliaksandr

Slides:



Advertisements
Similar presentations
Dataflow Analysis for Datarace-Free Programs (ESOP 11) Arnab De Joint work with Deepak DSouza and Rupesh Nasre Indian Institute of Science, Bangalore.
Advertisements

Continuation of chapter 6…. Nested while loop A while loop used within another while loop is called nested while loop. Q. An illustration to generate.
Asynchronous Web Services Jaliya N. Ekanayake. Basics of Web Services.
Asynchronous I/O in .NET
Logic Thread Queue DB Thread Queue ASync …n Sync.
CS 443 Advanced OS Fabián E. Bustamante, Spring 2005 Cooperative Task Management without Manual Stack Management or Event-driven programming is not the.
Copyright © 2012 Pearson Education, Inc. Chapter 9 Delegates and Events.
Cole Durdan.  What is asynchronous programming?  Previous patterns  Task Based Async Programming .NET 4.5 Keywords  What happens in an async. method?
Stephen Toub Parallel Computing Platform Microsoft Corporation.
Jon Shemitz Complicated stuff, quickly. Advanced Delegates.
Script# - the.NET response to Google Web Toolkit Gojko Adzic
Java GUI Libraries Swing Programming. Swing Components Swing is a collection of libraries that contains primitive widgets or controls used for designing.
Server Architecture Models Operating Systems Hebrew University Spring 2004.
An introduction to F# (part 2) Bogdan Brinzarea-Iamandi Banca Romaneasca 25 February 2010.
Delegates and Events Tom Roeder CS fa. Motivation – Function Pointers Treat functions as first-class objects eg. Scheme: (map myfunc somelist)
PARALLEL PROGRAMMING ABSTRACTIONS 6/16/2010 Parallel Programming Abstractions 1.
Multi-paradigm language Type inferred Just another.NET language Tools First-class language in VS2010* F# Interactive Window F# PowerPack F# = Fun.
Neal Stublen Practice Solution  Create a new solution  Add a WinForms project  Add a Class Library project  Reference the library.
Java Programming Exception Handling. The exception handling is one of the powerful mechanism provided in java. It provides the mechanism to handle the.
AJAX in ASP.NET James Crowley Developer Fusion
Sofia, Bulgaria | 9-10 October Asynchronous Programming for ASP.NET 2.0 Developers Julie Lerman The Data Farm Julie Lerman The Data Farm.
Joe Hummel, PhD Technical Staff: Pluralsight Adjunct Professor: UIC, LUC
DEV301. // Synchronous TResult Foo(...); // Asynchronous Programming Model (APM) IAsyncResult BeginFoo(..., AsyncCallback callback, object state);
Win32 Programming Lesson 13: Thread Pooling (Wow, Java is good for something…)
Reactive Extensions Ye olde introduction and walk-through, with plenty o’ code.
CIS 3301 C# Lesson 13 Interfaces. CIS 3302 Objectives Understand the Purpose of Interfaces. Define an Interface. Use an Interface. Implement Interface.
Consuming REST Services from C# SoftUni Team Technical Trainers Software University
Jon Shemitz Complicated stuff, quickly..NET 2.0. ● Generics50% & Nullable Types ● Iterators 10% ● Delegate Enhancements35% ● Partial Types5%
Customizing Autodesk® Navisworks® 2013 with the .NET API
ADVANCED WEB SERVICES. Three Advanced Web Service Techniques SOAP Extensions Asynchronous calls Custom wire formatting SOAP Extensions Asynchronous calls.
Working in the Background Radan Ganchev Astea Solutions.
WHO WILL BENEFIT FROM THIS TALK TOPICS WHAT YOU’LL LEAVE WITH ASP.NET developers, including Web Forms & MVC History of async programming in.NET How async.
Synchronizing threads, thread pools, etc.
(1) A Proposal for the Java Public Middleware API Vito Baggiolini SL/CO.
IAsyncResult ar = BeginSomething(…); // Do other work, checking ar.IsCompleted int result = EndSomething(ar);
Module 8: Delegates and Events. Overview Delegates Multicast Delegates Events When to Use Delegates, Events, and Interfaces.
Module 8 Enhancing User Interface Responsiveness.
CreatingClasses-SlideShow-part31 Creating Classes part 3 Barb Ericson Georgia Institute of Technology Dec 2009.
From C++ to C# Part 5. Enums Similar to C++ Similar to C++ Read up section 1.10 of Spec. Read up section 1.10 of Spec.
TAP into async programming
System Reliability and Resilience and stuff. Some things need to be cleared up first.
Computer Science 320 A First Program in Parallel Java.
Multithreading. Multitasking The multitasking is the ability of single processor to perform more than one operation at the same time Once systems allowed.
User Interface Programming in C#: Basics and Events Chris North CS 3724: HCI.
1.NETDelegates & eventsNOEA / PQC 2007 Delegates & events Observer pattern Delegates –Semantics –Cil – code –Usage Events Asynchronious delegates.
Patterns of Parallel Programming with.NET 4 Stephen Toub Principal Architect Parallel Computing Platform Microsoft Corporation
E81 CSE 532S: Advanced Multi-Paradigm Software Development Chris Gill Department of Computer Science and Engineering Washington University in St. Louis.
CIS NET Applications1 Chapter 7 – Asynchronous Calls.
TOPICS WHAT YOU’LL LEAVE WITH WHO WILL BENEFIT FROM THIS TALK.NET developers: familiar with parallel programming support in Visual Studio 2010 and.NET.
THE FUTURE OF C#: GOOD THINGS COME TO THOSE WHO ‘AWAIT’ Joseph Albahari SESSION CODE: DEV411 (c) 2011 Microsoft. All rights reserved.
Lecture 9 Object Oriented Programming Using Java
TechEd /6/2018 6:15 AM © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks.
Advanced Topics in Concurrency and Reactive Programming: Asynchronous Programming Majeed Kassis.
Promises and Asynchronous Programming
Testing and Exceptions
Staying Afloat in the .NET Async Ocean
C# Event Processing Model
Asynchronous Programming
Delegates & Events 1.
Processes and Threads.
Build /2/2019 © 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks.
class PrintOnetoTen { public static void main(String args[]) {
Why Threads Are A Bad Idea (for most purposes)
DELEGATES AND EVENT MODELING
Why Threads Are A Bad Idea (for most purposes)
Why Threads Are A Bad Idea (for most purposes)
CMSC 202 Threads.
.NET Core Summer event 2019 – Brno, CZ
Events, Delegates, and Lambdas
Presentation transcript:

Asynchrony in (ASP).NET Aliaksandr

Developer and a Kettle

1.Wait 2.Make someone to wait 3.Check periodically 4.Make someone to check 5.Put a whistle on a kettle 6.Add a web-interface to a kettle 1.Sync 2.Sync with threads 3.Async-sync 4.Async with threads 5.Async with callbacks 6.Async with events

Comparison Approach Transferring 1K, rps Transferring 1M, rps Sync2844,44100%32,5726% Async with callbacks 2547,2690%125,97100% Async-sync2327,2882%33,0426% Sync with threads861,2330%83,8967% Async with threads604,8421%80,3664%

Evolution: WinAPI struct OVERLAPPED (IAsyncResult) OVERLAPPED_COMPLETION_ROUTINE (AsyncCallback)

6 Evolution:.NET 1.0 – 1.1 IAsyncResult AsyncCallback callback, userState) EndXXX(asyncResult)

7 Evolution:.NET 2.0 – … event XXXCompleted XXXCompletedEventArgs EventHandler userState) CancelAsync() AsyncOperationManager AsyncOperation SyncronizationContext

Evolution:.NET 4.0 Task Parallel Library

IAsyncResult vs Events IAsyncResult 1.Callbacks are not thread safe 2.No context in callbacks (i.e. no HttpContext) 3.Complexity of chaining (custom IAsyncResult, etc.) 4.Poor support of components Events 1.Event handlers are under lock 2.HttpContext available 3.Chaining is simple 4.Component-oriented ContextAwareResult, but no guarantee

SyncronizationContext Event-based async pattern Thread #1 XAsyncYAsync Thread #3YCompleted Thread #2 ZAsync Thread #4 ZCompleted PreRenderComplete PreRender AsyncOperationManager XY XCompleted Z All operations are completed

TTT #1: Use closures var asyncResult = component.BeginSomeOperation(parameter, aresult => TrickyCallback(aresult, component), state); void TrickyCallback(IAsyncResult state, Component component) { bool result = component.EndOperation(state); }

TTT#2: Use userState carefully static void Main(string[] args) { var asyncResult = component.BeginSomeOperation( parameter, Callback, state); } void Callback(IAsyncResult aresult) { bool result = component.EndOperation(aresult); object state = asyncResult.AsyncState; }

TTT#3: Unsubscribe from events static void Main(string[] args) { component.OperationCompleted += component_OperationCompleted; component.OperationAsync("data", null); } static void component_OperationCompleted(object sender, EventArgs e) { component.OperationCompleted -= component_OperationCompleted; }

TTT#5: There is no timeout support in both async patterns

TTT#6 AsyncResult callbacks don’t have HttpContext It could be, but there is no guarantee

TTT#7 Do not convert event-based pattern to IAsyncResult one Event-based pattern uses locks, that could be not desirable

TTT #8: Do not use [ThreadStatic] Do not forget about ThreadPool

TTT#9: Do not throw exceptions in callbacks Even WSE 3.0 has had a bug we had spotted.

Q&A