SlideShare una empresa de Scribd logo
1 de 46
Descargar para leer sin conexión
Parallel and Asynchronous Programming
The server-side story
Panagiotis Kanavos
Parallel Extensions
• Best kept .NET secret known by all
• Since 2010 and .NET 4.0
• Coves Task, Data based processing models
• Close cousins
• TPL Dataflow
• System.Reactive
• Available through NuGet
• SIMD through RyuJIT
Use on the desktop
• async/await for asynchronous events
• Task.Run for background Processing
• Parallel computation
• Priorities
• Avoid blocking the UI
• Reduce execution time
• Use all available cores
What’s different on the Server
• No UI thread
• Multiple concurrent users/requests
• Throughput/Scalability more important than
request durattion
• Then there are timeouts
• Lots of services, lots of combined timeouts
• And …
Server Meltdown
Server Meltdown
• Load Balanced farm
• High load
• First server stuck at 100% CPU
• Timeouts, App pool Recycle
• More requests redirected to other servers
• Second server reaches 100%
• Don’t drop the ball!
• …
Request Queuing in ASP.NET
IIS Queue
• Req 1
• Req 2
• Req 3
ASP.NET Worker
Threads
• Thread 1
• Thread 3
App Domain
• Thread 2
Why …
• Lots of threads  Worse Scalability
• Can’t run more threads than cores
• Thrashing
• When everyone awaits everyone else, no-one finishes
• HATES blocking calls!
• Thread Pool starvation  Can’t serve
• 500 Too Busy
• Immediate actio
• App Pool Recycle
• Only possible action really …
Asynchronous Execution
• More important for server than speed
• Stackless Python  No blocking calls
• A view of the real world
• No blocking I/O at the OS level
• I/O = File, Database, WS/REST calls
• On IIS – IO Threads
• Since the IO Thread is doing the job, why am I
waiting for it?
Async on WebForms
• Basic support through async event handlers
• async void Button_Click μπρρρ…
• <%@ Page Async=“true” %>
• Use Page.RegisterAsyncTask for jobs longer than a
single request
• Raw Background threads can be killed at any time
Async on MVC/Web API
• Async actions!
• Plays well with Database/EF async
• HostingEnvironment.QueueBackgroundWorkItem
• Notifies IIS
• Gives 90 sec to task to finish in case of shutdown/recycle
• HangFire, Azure Web Jobs for repeating tasks
Parallel.For and PLINQ
• Data Parallelism
• Cuts the data in chunks
• Task per chunk
• Generally, 1 Task/Core
• Also uses the calling thread
• Looks like blocking (it’s not)
• Not a concern on the server
Dataflow
DB call
• I:Date
• O:Sales
Web call
• I:Sale
• O:Details
• X3
• Bounded
Analyze Store
• Bulk
Insert to
DB
Dataflow – Old Friend
The basics
• Processing models
• Agent and Pipeline
• and MapReduce data processing
• One task per block (configurable)
• Input/Output Buffer
• Block Types
• Buffering
• Execution
• Grouping
• Links between blocks
Execution Blocks
• Action Block
• Classic Job Queue
• Rudimentary Agent implementation
• Transform Block
• Transform one Input item to one Output
• Call a web service for a Stock to get History as a package
• TransformMany Block
• For one input item multiple output items
• Parallel Execution
Throttling
• BoundedCapacity
• Maximum input size
• Blocks sources
• MaxMessagesPerTask
• Recycle a Task after X messages
• CPU Throttling
Execution Block Demos
Buffering Blocks
• Buffer Block
• Easy Publisher/Subscriber implementation
• Broadcast Block
• Last event sent to many subscribers
• WriteOnce block
Batch Block Demo
Grouping Blocks
• Batching Block
• Join Block
• 2-3 Inputs, 1 Tuple<T1,T2,T3> output
• BatchedJoin Block
• Batch  Join
• T1, T2  Tuple< IList<T1>, IList<T2>>
Grouping Block Demos
Links
• LinkTo  IDisposable
• Disconnect  Dispose
• Settings
• Filter messages through Lambda
• Propagate Completion
Custom combination with Encapsulate
• New block
• One Input, One Output
Error Handling
In case of error a block
• Discards input messages
• Refuses new messages
• Propagate exception
• Caught with await/.Wait()
Dataflow Demos
Reactive Extensions
• Event monitoring and processing
• Control Events
• Records in Event Log
• Calls to a Web Service
• Time-based events
• Handle as a stream
• Works like LINQ
• Foundation for Event Processing
Sources
• Anything implementing IObservable<>
• Time
• Observable.Interval
• Events
• Observable.FromEventPattern
• BeginXXX/EndXXX
• Observable.FromAsyncPattern
• State machines / “Loops”
• Observable.Generate
• Tasks
• Every IEnumerable<T>
• Subject<T>  mySubject.OnNext(data)
Reactive Demos
Useful Functions
• Interval
• Buffer
• Sample
• Throttle
• Window
• Skip
• Take
• TakeUntil
Transformations
• Anything goes
• task ... AsObservable()
• block … AsObservable()
• await Observable
• ToTask<T>
SignalR
• Real Time communication from Server to Client
• Push Notifications
• Long process progress
• Eg. Search for tickets
Multiple Techniques
• Web sockets, falling back to …
• Server Sent Events
• Forever Frame
• Ajax Long Polling
Call function on Browser
• Server-side:
Clients.All.DoSomething(data)
• Browser-side
hub.client.updateProgress = function (data)
Connections and Hubs
Hub
Browser
Browser
Client
application
Browser
Persistent
Connection
Connections and Hubs
Scaleout through Backplane
Supported backplanes
• Windows Azure Bus
• SQL Server
• Redis
• Recommended Distributed memory cache for new Azure
projects
• Open Source Rulez!
SignalR Demos
Useful links- Courses
MVA Course
• Lighting up Real-Time Web Communications with SignalR
Pluralshight Course
• Async and Parallel Programming: Application Design
Books
• The C# Concurrency Cookbook, Stephen Cleary, O’Reilly
Useful Links - Sites
Sites
• Signal R
• TPL Dataflow
• Reactive Extensions
• Using Asynchronous Methods in ASP.NET
• 101 Rx Samples
Blogs
• Stephen Cleary
• The Magic of using Acync in ASP.NET, Scott Hanselman
• How to run background tasks in ASP.NET, Scott Hanselman
Session Evaluation
Your feedback is
important and valuable
Submit before the event’s
close session to WIN
prizes
2ways
to access
Go to
m.itprodevconnections.gr
Ask for an Evaluation Sheet from
the registration desk
Microsoft Virtual Academy for IT Pros
Όλα τα trainings που χρειάζεσαι δωρεάν σε ένα site!
/virtualization/
/server-infrastructure/
/private-cloud/
/hybrid-cloud/
/desktop-devices-management/
/licensing/
/και πολλά άλλα…
www.microsoftvirtualacademy.com
MVA
Microsoft Virtual Academy LIVE
Όλα τα trainings που χρειάζεσαι δωρεάν σε ένα site!
www.microsoftvirtualacademy.com
4 ΜΕΡΕΣ Εκπαίδευση με το Mark Russinovich
ΔΩΡΕΑΝ ΠΡΟΕΤΟΙΜΑΣΙΑ για την Εξέταση 70-533: Implementing Azure Infrastructure Solutions
Και 50% ΕΚΠΤΩΤΙΚΟ VOUCHER ΣΤΟ ΚΟΣΤΟΣ ΤΗΣ ΕΞΕΤΑΣΗΣ
1 ως 4 Δεκεμβρίου
MVA
Microsoft Virtual Academy for Devs
Όλα τα trainings που χρειάζεσαι δωρεάν σε ένα site!
/game development /
/web development /
/cloud development /
/mobile development /
/C#-XAML-HTML/
/app development/
/visual studio και πολλά άλλα…
www.microsoftvirtualacademy.com
MVA
The server side story:  Parallel and Asynchronous programming in .NET - ITProDevConnections 2014

Más contenido relacionado

La actualidad más candente

Building & Testing Scalable Rails Applications
Building & Testing Scalable Rails ApplicationsBuilding & Testing Scalable Rails Applications
Building & Testing Scalable Rails Applicationsevilmike
 
From VMs to Containers: Introducing Docker Containers for Linux and Windows S...
From VMs to Containers: Introducing Docker Containers for Linux and Windows S...From VMs to Containers: Introducing Docker Containers for Linux and Windows S...
From VMs to Containers: Introducing Docker Containers for Linux and Windows S...Ido Flatow
 
MVC 6 - the new unified Web programming model
MVC 6 - the new unified Web programming modelMVC 6 - the new unified Web programming model
MVC 6 - the new unified Web programming modelAlex Thissen
 
Getting Started with Web Services
Getting Started with Web ServicesGetting Started with Web Services
Getting Started with Web ServicesDataNext Solutions
 
A (XPages) developers guide to Cloudant - MeetIT
A (XPages) developers guide to Cloudant - MeetITA (XPages) developers guide to Cloudant - MeetIT
A (XPages) developers guide to Cloudant - MeetITFrank van der Linden
 
4th Lecture: JSP and such
4th Lecture:  JSP and such4th Lecture:  JSP and such
4th Lecture: JSP and suchManolis Vavalis
 
Microsoft ASP.NET 5 - The new kid on the block
Microsoft ASP.NET 5 - The new kid on the block Microsoft ASP.NET 5 - The new kid on the block
Microsoft ASP.NET 5 - The new kid on the block Christos Matskas
 
Real World Rails Deployment
Real World Rails DeploymentReal World Rails Deployment
Real World Rails DeploymentAlan Hecht
 
Tiki.vn - How we scale as a tech startup
Tiki.vn - How we scale as a tech startupTiki.vn - How we scale as a tech startup
Tiki.vn - How we scale as a tech startupTung Ns
 
Learn AJAX at ASIT
Learn AJAX at ASITLearn AJAX at ASIT
Learn AJAX at ASITASIT
 
Zarafa SummerCamp 2012 - Steve Hardy Friday Keynote
Zarafa SummerCamp 2012 - Steve Hardy Friday KeynoteZarafa SummerCamp 2012 - Steve Hardy Friday Keynote
Zarafa SummerCamp 2012 - Steve Hardy Friday KeynoteZarafa
 
CFWheels - Pragmatic, Beautiful Code
CFWheels - Pragmatic, Beautiful CodeCFWheels - Pragmatic, Beautiful Code
CFWheels - Pragmatic, Beautiful Codeindiver
 
DEV03 - How Watson, Bluemix, Cloudant, and XPages Can Work Together In A Real...
DEV03 - How Watson, Bluemix, Cloudant, and XPages Can Work Together In A Real...DEV03 - How Watson, Bluemix, Cloudant, and XPages Can Work Together In A Real...
DEV03 - How Watson, Bluemix, Cloudant, and XPages Can Work Together In A Real...Frank van der Linden
 
Four Ways to Improve ASP .NET Performance and Scalability
 Four Ways to Improve ASP .NET Performance and Scalability Four Ways to Improve ASP .NET Performance and Scalability
Four Ways to Improve ASP .NET Performance and ScalabilityAlachisoft
 
10 performance and scalability secrets of ASP.NET websites
10 performance and scalability secrets of ASP.NET websites10 performance and scalability secrets of ASP.NET websites
10 performance and scalability secrets of ASP.NET websitesoazabir
 
Performance Testing w/ WebPage Test Private Instance (DrupalCamp Ohio)
Performance Testing w/ WebPage Test Private Instance (DrupalCamp Ohio)Performance Testing w/ WebPage Test Private Instance (DrupalCamp Ohio)
Performance Testing w/ WebPage Test Private Instance (DrupalCamp Ohio)Bill Condo
 
Performance optimization - JavaScript
Performance optimization - JavaScriptPerformance optimization - JavaScript
Performance optimization - JavaScriptFilip Mares
 
Денис Резник "Зачем мне знать SQL и Базы Данных, ведь у меня есть ORM?"
Денис Резник "Зачем мне знать SQL и Базы Данных, ведь у меня есть ORM?"Денис Резник "Зачем мне знать SQL и Базы Данных, ведь у меня есть ORM?"
Денис Резник "Зачем мне знать SQL и Базы Данных, ведь у меня есть ORM?"Fwdays
 
Performance optimization - Advanced techniques
Performance optimization - Advanced techniquesPerformance optimization - Advanced techniques
Performance optimization - Advanced techniquesFilip Mares
 

La actualidad más candente (20)

Building & Testing Scalable Rails Applications
Building & Testing Scalable Rails ApplicationsBuilding & Testing Scalable Rails Applications
Building & Testing Scalable Rails Applications
 
From VMs to Containers: Introducing Docker Containers for Linux and Windows S...
From VMs to Containers: Introducing Docker Containers for Linux and Windows S...From VMs to Containers: Introducing Docker Containers for Linux and Windows S...
From VMs to Containers: Introducing Docker Containers for Linux and Windows S...
 
MVC 6 - the new unified Web programming model
MVC 6 - the new unified Web programming modelMVC 6 - the new unified Web programming model
MVC 6 - the new unified Web programming model
 
Getting Started with Web Services
Getting Started with Web ServicesGetting Started with Web Services
Getting Started with Web Services
 
A (XPages) developers guide to Cloudant - MeetIT
A (XPages) developers guide to Cloudant - MeetITA (XPages) developers guide to Cloudant - MeetIT
A (XPages) developers guide to Cloudant - MeetIT
 
4th Lecture: JSP and such
4th Lecture:  JSP and such4th Lecture:  JSP and such
4th Lecture: JSP and such
 
Microsoft ASP.NET 5 - The new kid on the block
Microsoft ASP.NET 5 - The new kid on the block Microsoft ASP.NET 5 - The new kid on the block
Microsoft ASP.NET 5 - The new kid on the block
 
Real World Rails Deployment
Real World Rails DeploymentReal World Rails Deployment
Real World Rails Deployment
 
Tiki.vn - How we scale as a tech startup
Tiki.vn - How we scale as a tech startupTiki.vn - How we scale as a tech startup
Tiki.vn - How we scale as a tech startup
 
Learn AJAX at ASIT
Learn AJAX at ASITLearn AJAX at ASIT
Learn AJAX at ASIT
 
Zarafa SummerCamp 2012 - Steve Hardy Friday Keynote
Zarafa SummerCamp 2012 - Steve Hardy Friday KeynoteZarafa SummerCamp 2012 - Steve Hardy Friday Keynote
Zarafa SummerCamp 2012 - Steve Hardy Friday Keynote
 
CFWheels - Pragmatic, Beautiful Code
CFWheels - Pragmatic, Beautiful CodeCFWheels - Pragmatic, Beautiful Code
CFWheels - Pragmatic, Beautiful Code
 
DEV03 - How Watson, Bluemix, Cloudant, and XPages Can Work Together In A Real...
DEV03 - How Watson, Bluemix, Cloudant, and XPages Can Work Together In A Real...DEV03 - How Watson, Bluemix, Cloudant, and XPages Can Work Together In A Real...
DEV03 - How Watson, Bluemix, Cloudant, and XPages Can Work Together In A Real...
 
Four Ways to Improve ASP .NET Performance and Scalability
 Four Ways to Improve ASP .NET Performance and Scalability Four Ways to Improve ASP .NET Performance and Scalability
Four Ways to Improve ASP .NET Performance and Scalability
 
10 performance and scalability secrets of ASP.NET websites
10 performance and scalability secrets of ASP.NET websites10 performance and scalability secrets of ASP.NET websites
10 performance and scalability secrets of ASP.NET websites
 
Net coreandsimplcommerce
Net coreandsimplcommerceNet coreandsimplcommerce
Net coreandsimplcommerce
 
Performance Testing w/ WebPage Test Private Instance (DrupalCamp Ohio)
Performance Testing w/ WebPage Test Private Instance (DrupalCamp Ohio)Performance Testing w/ WebPage Test Private Instance (DrupalCamp Ohio)
Performance Testing w/ WebPage Test Private Instance (DrupalCamp Ohio)
 
Performance optimization - JavaScript
Performance optimization - JavaScriptPerformance optimization - JavaScript
Performance optimization - JavaScript
 
Денис Резник "Зачем мне знать SQL и Базы Данных, ведь у меня есть ORM?"
Денис Резник "Зачем мне знать SQL и Базы Данных, ведь у меня есть ORM?"Денис Резник "Зачем мне знать SQL и Базы Данных, ведь у меня есть ORM?"
Денис Резник "Зачем мне знать SQL и Базы Данных, ведь у меня есть ORM?"
 
Performance optimization - Advanced techniques
Performance optimization - Advanced techniquesPerformance optimization - Advanced techniques
Performance optimization - Advanced techniques
 

Similar a The server side story: Parallel and Asynchronous programming in .NET - ITProDevConnections 2014

Azure Messaging Crossroads
Azure Messaging CrossroadsAzure Messaging Crossroads
Azure Messaging CrossroadsSean Feldman
 
From the Trenches: Effectively Scaling Your Cloud Infrastructure and Optimizi...
From the Trenches: Effectively Scaling Your Cloud Infrastructure and Optimizi...From the Trenches: Effectively Scaling Your Cloud Infrastructure and Optimizi...
From the Trenches: Effectively Scaling Your Cloud Infrastructure and Optimizi...Allan Mangune
 
JUDCon 2013- JBoss Data Grid and WebSockets: Delivering Real Time Push at Scale
JUDCon 2013- JBoss Data Grid and WebSockets: Delivering Real Time Push at ScaleJUDCon 2013- JBoss Data Grid and WebSockets: Delivering Real Time Push at Scale
JUDCon 2013- JBoss Data Grid and WebSockets: Delivering Real Time Push at ScaleC2B2 Consulting
 
Actors or Not: Async Event Architectures
Actors or Not: Async Event ArchitecturesActors or Not: Async Event Architectures
Actors or Not: Async Event ArchitecturesYaroslav Tkachenko
 
Pm ix tutorial-june2019-pub (1)
Pm ix tutorial-june2019-pub (1)Pm ix tutorial-june2019-pub (1)
Pm ix tutorial-june2019-pub (1)ewerkboy
 
(ATS4-PLAT08) Server Pool Management
(ATS4-PLAT08) Server Pool Management(ATS4-PLAT08) Server Pool Management
(ATS4-PLAT08) Server Pool ManagementBIOVIA
 
What's New in .Net 4.5
What's New in .Net 4.5What's New in .Net 4.5
What's New in .Net 4.5Malam Team
 
10 tips to make your ASP.NET Apps Faster
10 tips to make your ASP.NET Apps Faster10 tips to make your ASP.NET Apps Faster
10 tips to make your ASP.NET Apps FasterBrij Mishra
 
Boost the Performance of SharePoint Today!
Boost the Performance of SharePoint Today!Boost the Performance of SharePoint Today!
Boost the Performance of SharePoint Today!Brian Culver
 
Debugging the Web with Fiddler
Debugging the Web with FiddlerDebugging the Web with Fiddler
Debugging the Web with FiddlerIdo Flatow
 
"You Don't Know NODE.JS" by Hengki Mardongan Sihombing (Urbanhire)
"You Don't Know NODE.JS" by Hengki Mardongan Sihombing (Urbanhire)"You Don't Know NODE.JS" by Hengki Mardongan Sihombing (Urbanhire)
"You Don't Know NODE.JS" by Hengki Mardongan Sihombing (Urbanhire)Tech in Asia ID
 
Real-time web applications using SharePoint, SignalR and Azure Service Bus
Real-time web applications using SharePoint, SignalR and Azure Service BusReal-time web applications using SharePoint, SignalR and Azure Service Bus
Real-time web applications using SharePoint, SignalR and Azure Service BusDinusha Kumarasiri
 

Similar a The server side story: Parallel and Asynchronous programming in .NET - ITProDevConnections 2014 (20)

Background processing with hangfire
Background processing with hangfireBackground processing with hangfire
Background processing with hangfire
 
Azure Messaging Crossroads
Azure Messaging CrossroadsAzure Messaging Crossroads
Azure Messaging Crossroads
 
Windows 8 Apps and the Outside World
Windows 8 Apps and the Outside WorldWindows 8 Apps and the Outside World
Windows 8 Apps and the Outside World
 
Release it! - Takeaways
Release it! - TakeawaysRelease it! - Takeaways
Release it! - Takeaways
 
From the Trenches: Effectively Scaling Your Cloud Infrastructure and Optimizi...
From the Trenches: Effectively Scaling Your Cloud Infrastructure and Optimizi...From the Trenches: Effectively Scaling Your Cloud Infrastructure and Optimizi...
From the Trenches: Effectively Scaling Your Cloud Infrastructure and Optimizi...
 
JUDCon 2013- JBoss Data Grid and WebSockets: Delivering Real Time Push at Scale
JUDCon 2013- JBoss Data Grid and WebSockets: Delivering Real Time Push at ScaleJUDCon 2013- JBoss Data Grid and WebSockets: Delivering Real Time Push at Scale
JUDCon 2013- JBoss Data Grid and WebSockets: Delivering Real Time Push at Scale
 
How we use Twisted in Launchpad
How we use Twisted in LaunchpadHow we use Twisted in Launchpad
How we use Twisted in Launchpad
 
Actors or Not: Async Event Architectures
Actors or Not: Async Event ArchitecturesActors or Not: Async Event Architectures
Actors or Not: Async Event Architectures
 
Pm ix tutorial-june2019-pub (1)
Pm ix tutorial-june2019-pub (1)Pm ix tutorial-june2019-pub (1)
Pm ix tutorial-june2019-pub (1)
 
(ATS4-PLAT08) Server Pool Management
(ATS4-PLAT08) Server Pool Management(ATS4-PLAT08) Server Pool Management
(ATS4-PLAT08) Server Pool Management
 
What's New in .Net 4.5
What's New in .Net 4.5What's New in .Net 4.5
What's New in .Net 4.5
 
10 tips to make your ASP.NET Apps Faster
10 tips to make your ASP.NET Apps Faster10 tips to make your ASP.NET Apps Faster
10 tips to make your ASP.NET Apps Faster
 
App fabric introduction
App fabric introductionApp fabric introduction
App fabric introduction
 
Boost the Performance of SharePoint Today!
Boost the Performance of SharePoint Today!Boost the Performance of SharePoint Today!
Boost the Performance of SharePoint Today!
 
Azure platform for customers
Azure platform for customersAzure platform for customers
Azure platform for customers
 
Debugging the Web with Fiddler
Debugging the Web with FiddlerDebugging the Web with Fiddler
Debugging the Web with Fiddler
 
"You Don't Know NODE.JS" by Hengki Mardongan Sihombing (Urbanhire)
"You Don't Know NODE.JS" by Hengki Mardongan Sihombing (Urbanhire)"You Don't Know NODE.JS" by Hengki Mardongan Sihombing (Urbanhire)
"You Don't Know NODE.JS" by Hengki Mardongan Sihombing (Urbanhire)
 
Internals of Presto Service
Internals of Presto ServiceInternals of Presto Service
Internals of Presto Service
 
Gcp dataflow
Gcp dataflowGcp dataflow
Gcp dataflow
 
Real-time web applications using SharePoint, SignalR and Azure Service Bus
Real-time web applications using SharePoint, SignalR and Azure Service BusReal-time web applications using SharePoint, SignalR and Azure Service Bus
Real-time web applications using SharePoint, SignalR and Azure Service Bus
 

Más de Panagiotis Kanavos

77o dotNETZone Meetup: Pattern matching expressions. One small step for one l...
77o dotNETZone Meetup: Pattern matching expressions. One small step for one l...77o dotNETZone Meetup: Pattern matching expressions. One small step for one l...
77o dotNETZone Meetup: Pattern matching expressions. One small step for one l...Panagiotis Kanavos
 
65ο DotNetZone event: Tpl data flow και railway oriented programming
65ο DotNetZone event: Tpl data flow και railway oriented programming65ο DotNetZone event: Tpl data flow και railway oriented programming
65ο DotNetZone event: Tpl data flow και railway oriented programmingPanagiotis Kanavos
 
Περατζάδα στο Azure Event Hub
Περατζάδα στο Azure Event HubΠερατζάδα στο Azure Event Hub
Περατζάδα στο Azure Event HubPanagiotis Kanavos
 
Το Azure δεν είναι χορτοφάγο! - 59ο DotNetZone Event
Το Azure δεν είναι χορτοφάγο! - 59ο DotNetZone EventΤο Azure δεν είναι χορτοφάγο! - 59ο DotNetZone Event
Το Azure δεν είναι χορτοφάγο! - 59ο DotNetZone EventPanagiotis Kanavos
 
The Server-SIde Story: Παράλληλος και ασύγχρονος προγραμματισμός στο .NET - I...
The Server-SIde Story: Παράλληλος και ασύγχρονος προγραμματισμός στο .NET - I...The Server-SIde Story: Παράλληλος και ασύγχρονος προγραμματισμός στο .NET - I...
The Server-SIde Story: Παράλληλος και ασύγχρονος προγραμματισμός στο .NET - I...Panagiotis Kanavos
 
Pithos - Architecture and .NET Technologies
Pithos - Architecture and .NET TechnologiesPithos - Architecture and .NET Technologies
Pithos - Architecture and .NET TechnologiesPanagiotis Kanavos
 
Πίθος - Αρχιτεκτονική και τεχνολογίες .NET
Πίθος - Αρχιτεκτονική και τεχνολογίες .NETΠίθος - Αρχιτεκτονική και τεχνολογίες .NET
Πίθος - Αρχιτεκτονική και τεχνολογίες .NETPanagiotis Kanavos
 
Real Life Task Parallel Library, ITProDevConnections 2011 (Greek)
Real Life Task Parallel Library, ITProDevConnections 2011 (Greek)Real Life Task Parallel Library, ITProDevConnections 2011 (Greek)
Real Life Task Parallel Library, ITProDevConnections 2011 (Greek)Panagiotis Kanavos
 

Más de Panagiotis Kanavos (9)

77o dotNETZone Meetup: Pattern matching expressions. One small step for one l...
77o dotNETZone Meetup: Pattern matching expressions. One small step for one l...77o dotNETZone Meetup: Pattern matching expressions. One small step for one l...
77o dotNETZone Meetup: Pattern matching expressions. One small step for one l...
 
65ο DotNetZone event: Tpl data flow και railway oriented programming
65ο DotNetZone event: Tpl data flow και railway oriented programming65ο DotNetZone event: Tpl data flow και railway oriented programming
65ο DotNetZone event: Tpl data flow και railway oriented programming
 
Περατζάδα στο Azure Event Hub
Περατζάδα στο Azure Event HubΠερατζάδα στο Azure Event Hub
Περατζάδα στο Azure Event Hub
 
Ο βασιλιάς Git!
Ο βασιλιάς Git!Ο βασιλιάς Git!
Ο βασιλιάς Git!
 
Το Azure δεν είναι χορτοφάγο! - 59ο DotNetZone Event
Το Azure δεν είναι χορτοφάγο! - 59ο DotNetZone EventΤο Azure δεν είναι χορτοφάγο! - 59ο DotNetZone Event
Το Azure δεν είναι χορτοφάγο! - 59ο DotNetZone Event
 
The Server-SIde Story: Παράλληλος και ασύγχρονος προγραμματισμός στο .NET - I...
The Server-SIde Story: Παράλληλος και ασύγχρονος προγραμματισμός στο .NET - I...The Server-SIde Story: Παράλληλος και ασύγχρονος προγραμματισμός στο .NET - I...
The Server-SIde Story: Παράλληλος και ασύγχρονος προγραμματισμός στο .NET - I...
 
Pithos - Architecture and .NET Technologies
Pithos - Architecture and .NET TechnologiesPithos - Architecture and .NET Technologies
Pithos - Architecture and .NET Technologies
 
Πίθος - Αρχιτεκτονική και τεχνολογίες .NET
Πίθος - Αρχιτεκτονική και τεχνολογίες .NETΠίθος - Αρχιτεκτονική και τεχνολογίες .NET
Πίθος - Αρχιτεκτονική και τεχνολογίες .NET
 
Real Life Task Parallel Library, ITProDevConnections 2011 (Greek)
Real Life Task Parallel Library, ITProDevConnections 2011 (Greek)Real Life Task Parallel Library, ITProDevConnections 2011 (Greek)
Real Life Task Parallel Library, ITProDevConnections 2011 (Greek)
 

Último

Optimizing Business Potential: A Guide to Outsourcing Engineering Services in...
Optimizing Business Potential: A Guide to Outsourcing Engineering Services in...Optimizing Business Potential: A Guide to Outsourcing Engineering Services in...
Optimizing Business Potential: A Guide to Outsourcing Engineering Services in...Jaydeep Chhasatia
 
Your Vision, Our Expertise: TECUNIQUE's Tailored Software Teams
Your Vision, Our Expertise: TECUNIQUE's Tailored Software TeamsYour Vision, Our Expertise: TECUNIQUE's Tailored Software Teams
Your Vision, Our Expertise: TECUNIQUE's Tailored Software TeamsJaydeep Chhasatia
 
ARM Talk @ Rejekts - Will ARM be the new Mainstream in our Data Centers_.pdf
ARM Talk @ Rejekts - Will ARM be the new Mainstream in our Data Centers_.pdfARM Talk @ Rejekts - Will ARM be the new Mainstream in our Data Centers_.pdf
ARM Talk @ Rejekts - Will ARM be the new Mainstream in our Data Centers_.pdfTobias Schneck
 
Top Software Development Trends in 2024
Top Software Development Trends in  2024Top Software Development Trends in  2024
Top Software Development Trends in 2024Mind IT Systems
 
online pdf editor software solutions.pdf
online pdf editor software solutions.pdfonline pdf editor software solutions.pdf
online pdf editor software solutions.pdfMeon Technology
 
About .NET 8 and a first glimpse into .NET9
About .NET 8 and a first glimpse into .NET9About .NET 8 and a first glimpse into .NET9
About .NET 8 and a first glimpse into .NET9Jürgen Gutsch
 
ERP For Electrical and Electronics manufecturing.pptx
ERP For Electrical and Electronics manufecturing.pptxERP For Electrical and Electronics manufecturing.pptx
ERP For Electrical and Electronics manufecturing.pptxAutus Cyber Tech
 
IA Generativa y Grafos de Neo4j: RAG time
IA Generativa y Grafos de Neo4j: RAG timeIA Generativa y Grafos de Neo4j: RAG time
IA Generativa y Grafos de Neo4j: RAG timeNeo4j
 
eAuditor Audits & Inspections - conduct field inspections
eAuditor Audits & Inspections - conduct field inspectionseAuditor Audits & Inspections - conduct field inspections
eAuditor Audits & Inspections - conduct field inspectionsNirav Modi
 
20240330_고급진 코드를 위한 exception 다루기
20240330_고급진 코드를 위한 exception 다루기20240330_고급진 코드를 위한 exception 다루기
20240330_고급진 코드를 위한 exception 다루기Chiwon Song
 
OpenChain Webinar: Universal CVSS Calculator
OpenChain Webinar: Universal CVSS CalculatorOpenChain Webinar: Universal CVSS Calculator
OpenChain Webinar: Universal CVSS CalculatorShane Coughlan
 
JS-Experts - Cybersecurity for Generative AI
JS-Experts - Cybersecurity for Generative AIJS-Experts - Cybersecurity for Generative AI
JS-Experts - Cybersecurity for Generative AIIvo Andreev
 
Kubernetes go-live checklist for your microservices.pptx
Kubernetes go-live checklist for your microservices.pptxKubernetes go-live checklist for your microservices.pptx
Kubernetes go-live checklist for your microservices.pptxPrakarsh -
 
Growing Oxen: channel operators and retries
Growing Oxen: channel operators and retriesGrowing Oxen: channel operators and retries
Growing Oxen: channel operators and retriesSoftwareMill
 
Deep Learning for Images with PyTorch - Datacamp
Deep Learning for Images with PyTorch - DatacampDeep Learning for Images with PyTorch - Datacamp
Deep Learning for Images with PyTorch - DatacampVICTOR MAESTRE RAMIREZ
 
AI Embracing Every Shade of Human Beauty
AI Embracing Every Shade of Human BeautyAI Embracing Every Shade of Human Beauty
AI Embracing Every Shade of Human BeautyRaymond Okyere-Forson
 
Transforming PMO Success with AI - Discover OnePlan Strategic Portfolio Work ...
Transforming PMO Success with AI - Discover OnePlan Strategic Portfolio Work ...Transforming PMO Success with AI - Discover OnePlan Strategic Portfolio Work ...
Transforming PMO Success with AI - Discover OnePlan Strategic Portfolio Work ...OnePlan Solutions
 
Introduction-to-Software-Development-Outsourcing.pptx
Introduction-to-Software-Development-Outsourcing.pptxIntroduction-to-Software-Development-Outsourcing.pptx
Introduction-to-Software-Development-Outsourcing.pptxIntelliSource Technologies
 
Why Choose Brain Inventory For Ecommerce Development.pdf
Why Choose Brain Inventory For Ecommerce Development.pdfWhy Choose Brain Inventory For Ecommerce Development.pdf
Why Choose Brain Inventory For Ecommerce Development.pdfBrain Inventory
 

Último (20)

Optimizing Business Potential: A Guide to Outsourcing Engineering Services in...
Optimizing Business Potential: A Guide to Outsourcing Engineering Services in...Optimizing Business Potential: A Guide to Outsourcing Engineering Services in...
Optimizing Business Potential: A Guide to Outsourcing Engineering Services in...
 
Your Vision, Our Expertise: TECUNIQUE's Tailored Software Teams
Your Vision, Our Expertise: TECUNIQUE's Tailored Software TeamsYour Vision, Our Expertise: TECUNIQUE's Tailored Software Teams
Your Vision, Our Expertise: TECUNIQUE's Tailored Software Teams
 
ARM Talk @ Rejekts - Will ARM be the new Mainstream in our Data Centers_.pdf
ARM Talk @ Rejekts - Will ARM be the new Mainstream in our Data Centers_.pdfARM Talk @ Rejekts - Will ARM be the new Mainstream in our Data Centers_.pdf
ARM Talk @ Rejekts - Will ARM be the new Mainstream in our Data Centers_.pdf
 
Top Software Development Trends in 2024
Top Software Development Trends in  2024Top Software Development Trends in  2024
Top Software Development Trends in 2024
 
online pdf editor software solutions.pdf
online pdf editor software solutions.pdfonline pdf editor software solutions.pdf
online pdf editor software solutions.pdf
 
About .NET 8 and a first glimpse into .NET9
About .NET 8 and a first glimpse into .NET9About .NET 8 and a first glimpse into .NET9
About .NET 8 and a first glimpse into .NET9
 
ERP For Electrical and Electronics manufecturing.pptx
ERP For Electrical and Electronics manufecturing.pptxERP For Electrical and Electronics manufecturing.pptx
ERP For Electrical and Electronics manufecturing.pptx
 
IA Generativa y Grafos de Neo4j: RAG time
IA Generativa y Grafos de Neo4j: RAG timeIA Generativa y Grafos de Neo4j: RAG time
IA Generativa y Grafos de Neo4j: RAG time
 
eAuditor Audits & Inspections - conduct field inspections
eAuditor Audits & Inspections - conduct field inspectionseAuditor Audits & Inspections - conduct field inspections
eAuditor Audits & Inspections - conduct field inspections
 
20240330_고급진 코드를 위한 exception 다루기
20240330_고급진 코드를 위한 exception 다루기20240330_고급진 코드를 위한 exception 다루기
20240330_고급진 코드를 위한 exception 다루기
 
OpenChain Webinar: Universal CVSS Calculator
OpenChain Webinar: Universal CVSS CalculatorOpenChain Webinar: Universal CVSS Calculator
OpenChain Webinar: Universal CVSS Calculator
 
JS-Experts - Cybersecurity for Generative AI
JS-Experts - Cybersecurity for Generative AIJS-Experts - Cybersecurity for Generative AI
JS-Experts - Cybersecurity for Generative AI
 
Kubernetes go-live checklist for your microservices.pptx
Kubernetes go-live checklist for your microservices.pptxKubernetes go-live checklist for your microservices.pptx
Kubernetes go-live checklist for your microservices.pptx
 
Growing Oxen: channel operators and retries
Growing Oxen: channel operators and retriesGrowing Oxen: channel operators and retries
Growing Oxen: channel operators and retries
 
Deep Learning for Images with PyTorch - Datacamp
Deep Learning for Images with PyTorch - DatacampDeep Learning for Images with PyTorch - Datacamp
Deep Learning for Images with PyTorch - Datacamp
 
AI Embracing Every Shade of Human Beauty
AI Embracing Every Shade of Human BeautyAI Embracing Every Shade of Human Beauty
AI Embracing Every Shade of Human Beauty
 
Transforming PMO Success with AI - Discover OnePlan Strategic Portfolio Work ...
Transforming PMO Success with AI - Discover OnePlan Strategic Portfolio Work ...Transforming PMO Success with AI - Discover OnePlan Strategic Portfolio Work ...
Transforming PMO Success with AI - Discover OnePlan Strategic Portfolio Work ...
 
Program with GUTs
Program with GUTsProgram with GUTs
Program with GUTs
 
Introduction-to-Software-Development-Outsourcing.pptx
Introduction-to-Software-Development-Outsourcing.pptxIntroduction-to-Software-Development-Outsourcing.pptx
Introduction-to-Software-Development-Outsourcing.pptx
 
Why Choose Brain Inventory For Ecommerce Development.pdf
Why Choose Brain Inventory For Ecommerce Development.pdfWhy Choose Brain Inventory For Ecommerce Development.pdf
Why Choose Brain Inventory For Ecommerce Development.pdf
 

The server side story: Parallel and Asynchronous programming in .NET - ITProDevConnections 2014

  • 1. Parallel and Asynchronous Programming The server-side story Panagiotis Kanavos
  • 2. Parallel Extensions • Best kept .NET secret known by all • Since 2010 and .NET 4.0 • Coves Task, Data based processing models • Close cousins • TPL Dataflow • System.Reactive • Available through NuGet • SIMD through RyuJIT
  • 3. Use on the desktop • async/await for asynchronous events • Task.Run for background Processing • Parallel computation • Priorities • Avoid blocking the UI • Reduce execution time • Use all available cores
  • 4. What’s different on the Server • No UI thread • Multiple concurrent users/requests • Throughput/Scalability more important than request durattion • Then there are timeouts • Lots of services, lots of combined timeouts • And …
  • 6. Server Meltdown • Load Balanced farm • High load • First server stuck at 100% CPU • Timeouts, App pool Recycle • More requests redirected to other servers • Second server reaches 100% • Don’t drop the ball! • …
  • 7. Request Queuing in ASP.NET IIS Queue • Req 1 • Req 2 • Req 3 ASP.NET Worker Threads • Thread 1 • Thread 3 App Domain • Thread 2
  • 8. Why … • Lots of threads  Worse Scalability • Can’t run more threads than cores • Thrashing • When everyone awaits everyone else, no-one finishes • HATES blocking calls! • Thread Pool starvation  Can’t serve • 500 Too Busy • Immediate actio • App Pool Recycle • Only possible action really …
  • 9. Asynchronous Execution • More important for server than speed • Stackless Python  No blocking calls • A view of the real world • No blocking I/O at the OS level • I/O = File, Database, WS/REST calls • On IIS – IO Threads • Since the IO Thread is doing the job, why am I waiting for it?
  • 10. Async on WebForms • Basic support through async event handlers • async void Button_Click μπρρρ… • <%@ Page Async=“true” %> • Use Page.RegisterAsyncTask for jobs longer than a single request • Raw Background threads can be killed at any time
  • 11. Async on MVC/Web API • Async actions! • Plays well with Database/EF async • HostingEnvironment.QueueBackgroundWorkItem • Notifies IIS • Gives 90 sec to task to finish in case of shutdown/recycle • HangFire, Azure Web Jobs for repeating tasks
  • 12. Parallel.For and PLINQ • Data Parallelism • Cuts the data in chunks • Task per chunk • Generally, 1 Task/Core • Also uses the calling thread • Looks like blocking (it’s not) • Not a concern on the server
  • 13. Dataflow DB call • I:Date • O:Sales Web call • I:Sale • O:Details • X3 • Bounded Analyze Store • Bulk Insert to DB
  • 15. The basics • Processing models • Agent and Pipeline • and MapReduce data processing • One task per block (configurable) • Input/Output Buffer • Block Types • Buffering • Execution • Grouping • Links between blocks
  • 16. Execution Blocks • Action Block • Classic Job Queue • Rudimentary Agent implementation • Transform Block • Transform one Input item to one Output • Call a web service for a Stock to get History as a package • TransformMany Block • For one input item multiple output items • Parallel Execution
  • 17. Throttling • BoundedCapacity • Maximum input size • Blocks sources • MaxMessagesPerTask • Recycle a Task after X messages • CPU Throttling
  • 19. Buffering Blocks • Buffer Block • Easy Publisher/Subscriber implementation • Broadcast Block • Last event sent to many subscribers • WriteOnce block
  • 21. Grouping Blocks • Batching Block • Join Block • 2-3 Inputs, 1 Tuple<T1,T2,T3> output • BatchedJoin Block • Batch  Join • T1, T2  Tuple< IList<T1>, IList<T2>>
  • 23. Links • LinkTo  IDisposable • Disconnect  Dispose • Settings • Filter messages through Lambda • Propagate Completion
  • 24. Custom combination with Encapsulate • New block • One Input, One Output
  • 25. Error Handling In case of error a block • Discards input messages • Refuses new messages • Propagate exception • Caught with await/.Wait()
  • 27. Reactive Extensions • Event monitoring and processing • Control Events • Records in Event Log • Calls to a Web Service • Time-based events • Handle as a stream • Works like LINQ • Foundation for Event Processing
  • 28. Sources • Anything implementing IObservable<> • Time • Observable.Interval • Events • Observable.FromEventPattern • BeginXXX/EndXXX • Observable.FromAsyncPattern • State machines / “Loops” • Observable.Generate • Tasks • Every IEnumerable<T> • Subject<T>  mySubject.OnNext(data)
  • 30. Useful Functions • Interval • Buffer • Sample • Throttle • Window • Skip • Take • TakeUntil
  • 31. Transformations • Anything goes • task ... AsObservable() • block … AsObservable() • await Observable • ToTask<T>
  • 32. SignalR • Real Time communication from Server to Client • Push Notifications • Long process progress • Eg. Search for tickets
  • 33. Multiple Techniques • Web sockets, falling back to … • Server Sent Events • Forever Frame • Ajax Long Polling
  • 34. Call function on Browser • Server-side: Clients.All.DoSomething(data) • Browser-side hub.client.updateProgress = function (data)
  • 38. Supported backplanes • Windows Azure Bus • SQL Server • Redis • Recommended Distributed memory cache for new Azure projects • Open Source Rulez!
  • 40. Useful links- Courses MVA Course • Lighting up Real-Time Web Communications with SignalR Pluralshight Course • Async and Parallel Programming: Application Design Books • The C# Concurrency Cookbook, Stephen Cleary, O’Reilly
  • 41. Useful Links - Sites Sites • Signal R • TPL Dataflow • Reactive Extensions • Using Asynchronous Methods in ASP.NET • 101 Rx Samples Blogs • Stephen Cleary • The Magic of using Acync in ASP.NET, Scott Hanselman • How to run background tasks in ASP.NET, Scott Hanselman
  • 42. Session Evaluation Your feedback is important and valuable Submit before the event’s close session to WIN prizes 2ways to access Go to m.itprodevconnections.gr Ask for an Evaluation Sheet from the registration desk
  • 43. Microsoft Virtual Academy for IT Pros Όλα τα trainings που χρειάζεσαι δωρεάν σε ένα site! /virtualization/ /server-infrastructure/ /private-cloud/ /hybrid-cloud/ /desktop-devices-management/ /licensing/ /και πολλά άλλα… www.microsoftvirtualacademy.com MVA
  • 44. Microsoft Virtual Academy LIVE Όλα τα trainings που χρειάζεσαι δωρεάν σε ένα site! www.microsoftvirtualacademy.com 4 ΜΕΡΕΣ Εκπαίδευση με το Mark Russinovich ΔΩΡΕΑΝ ΠΡΟΕΤΟΙΜΑΣΙΑ για την Εξέταση 70-533: Implementing Azure Infrastructure Solutions Και 50% ΕΚΠΤΩΤΙΚΟ VOUCHER ΣΤΟ ΚΟΣΤΟΣ ΤΗΣ ΕΞΕΤΑΣΗΣ 1 ως 4 Δεκεμβρίου MVA
  • 45. Microsoft Virtual Academy for Devs Όλα τα trainings που χρειάζεσαι δωρεάν σε ένα site! /game development / /web development / /cloud development / /mobile development / /C#-XAML-HTML/ /app development/ /visual studio και πολλά άλλα… www.microsoftvirtualacademy.com MVA