SlideShare a Scribd company logo
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

More Related Content

What's hot

Building & Testing Scalable Rails Applications
Building & Testing Scalable Rails ApplicationsBuilding & Testing Scalable Rails Applications
Building & Testing Scalable Rails Applications
evilmike
 
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 model
Alex Thissen
 
Getting Started with Web Services
Getting Started with Web ServicesGetting Started with Web Services
Getting Started with Web Services
DataNext 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 - MeetIT
Frank van der Linden
 
4th Lecture: JSP and such
4th Lecture:  JSP and such4th Lecture:  JSP and such
4th Lecture: JSP and such
Manolis 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 Deployment
Alan 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 startup
Tung Ns
 
Learn AJAX at ASIT
Learn AJAX at ASITLearn AJAX at ASIT
Learn AJAX at ASIT
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
Zarafa
 
CFWheels - Pragmatic, Beautiful Code
CFWheels - Pragmatic, Beautiful CodeCFWheels - Pragmatic, Beautiful Code
CFWheels - Pragmatic, Beautiful Code
indiver
 
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 Scalability
Alachisoft
 
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
oazabir
 
Net coreandsimplcommerce
Net coreandsimplcommerceNet coreandsimplcommerce
Net coreandsimplcommerce
Thien Nguyen Le Quynh
 
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 - JavaScript
Filip Mares
 
Денис Резник "Зачем мне знать SQL и Базы Данных, ведь у меня есть ORM?"
Денис Резник "Зачем мне знать SQL и Базы Данных, ведь у меня есть ORM?"Денис Резник "Зачем мне знать SQL и Базы Данных, ведь у меня есть ORM?"
Денис Резник "Зачем мне знать SQL и Базы Данных, ведь у меня есть ORM?"
Fwdays
 
Performance optimization - Advanced techniques
Performance optimization - Advanced techniquesPerformance optimization - Advanced techniques
Performance optimization - Advanced techniques
Filip Mares
 

What's hot (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 to The server side story: Parallel and Asynchronous programming in .NET - ITProDevConnections 2014

Background processing with hangfire
Background processing with hangfireBackground processing with hangfire
Background processing with hangfire
Aleksandar Bozinovski
 
Azure Messaging Crossroads
Azure Messaging CrossroadsAzure Messaging Crossroads
Azure Messaging Crossroads
Sean Feldman
 
Windows 8 Apps and the Outside World
Windows 8 Apps and the Outside WorldWindows 8 Apps and the Outside World
Release it! - Takeaways
Release it! - TakeawaysRelease it! - Takeaways
Release it! - Takeaways
Manuela Grindei
 
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 Scale
C2B2 Consulting
 
How we use Twisted in Launchpad
How we use Twisted in LaunchpadHow we use Twisted in Launchpad
How we use Twisted in Launchpad
Michael Hudson-Doyle
 
Actors or Not: Async Event Architectures
Actors or Not: Async Event ArchitecturesActors or Not: Async Event Architectures
Actors or Not: Async Event Architectures
Yaroslav 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 Management
BIOVIA
 
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
Malam 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 Faster
Brij Mishra
 
App fabric introduction
App fabric introductionApp fabric introduction
App fabric introduction
Dennis van der Stelt
 
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
 
Azure platform for customers
Azure platform for customersAzure platform for customers
Azure platform for customers
Rateb Abu Hawieleh
 
Debugging the Web with Fiddler
Debugging the Web with FiddlerDebugging the Web with Fiddler
Debugging the Web with Fiddler
Ido 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
 
Internals of Presto Service
Internals of Presto ServiceInternals of Presto Service
Internals of Presto Service
Treasure Data, Inc.
 
Gcp dataflow
Gcp dataflowGcp dataflow
Gcp dataflow
Igor Roiter
 
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
Dinusha Kumarasiri
 

Similar to 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
 

More from 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 programming
Panagiotis Kanavos
 
Περατζάδα στο Azure Event Hub
Περατζάδα στο Azure Event HubΠερατζάδα στο Azure Event Hub
Περατζάδα στο Azure Event Hub
Panagiotis Kanavos
 
Ο βασιλιάς Git!
Ο βασιλιάς Git!Ο βασιλιάς Git!
Ο βασιλιάς Git!
Panagiotis Kanavos
 
Το Azure δεν είναι χορτοφάγο! - 59ο DotNetZone Event
Το Azure δεν είναι χορτοφάγο! - 59ο DotNetZone EventΤο Azure δεν είναι χορτοφάγο! - 59ο DotNetZone Event
Το Azure δεν είναι χορτοφάγο! - 59ο DotNetZone Event
Panagiotis 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 Technologies
Panagiotis 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
 

More from 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)
 

Recently uploaded

UI5con 2024 - Bring Your Own Design System
UI5con 2024 - Bring Your Own Design SystemUI5con 2024 - Bring Your Own Design System
UI5con 2024 - Bring Your Own Design System
Peter Muessig
 
E-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet DynamicsE-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet Dynamics
Hornet Dynamics
 
Microservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we workMicroservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we work
Sven Peters
 
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian CompaniesE-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
Quickdice ERP
 
All you need to know about Spring Boot and GraalVM
All you need to know about Spring Boot and GraalVMAll you need to know about Spring Boot and GraalVM
All you need to know about Spring Boot and GraalVM
Alina Yurenko
 
How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?
ToXSL Technologies
 
Malibou Pitch Deck For Its €3M Seed Round
Malibou Pitch Deck For Its €3M Seed RoundMalibou Pitch Deck For Its €3M Seed Round
Malibou Pitch Deck For Its €3M Seed Round
sjcobrien
 
316895207-SAP-Oil-and-Gas-Downstream-Training.pptx
316895207-SAP-Oil-and-Gas-Downstream-Training.pptx316895207-SAP-Oil-and-Gas-Downstream-Training.pptx
316895207-SAP-Oil-and-Gas-Downstream-Training.pptx
ssuserad3af4
 
GreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-JurisicGreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-Jurisic
Green Software Development
 
在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样
在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样
在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样
mz5nrf0n
 
Using Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query PerformanceUsing Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query Performance
Grant Fritchey
 
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CDKuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
rodomar2
 
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Łukasz Chruściel
 
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling ExtensionsUI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
Peter Muessig
 
Mobile app Development Services | Drona Infotech
Mobile app Development Services  | Drona InfotechMobile app Development Services  | Drona Infotech
Mobile app Development Services | Drona Infotech
Drona Infotech
 
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdfTop Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
VALiNTRY360
 
WWDC 2024 Keynote Review: For CocoaCoders Austin
WWDC 2024 Keynote Review: For CocoaCoders AustinWWDC 2024 Keynote Review: For CocoaCoders Austin
WWDC 2024 Keynote Review: For CocoaCoders Austin
Patrick Weigel
 
Artificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension FunctionsArtificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension Functions
Octavian Nadolu
 
What next after learning python programming basics
What next after learning python programming basicsWhat next after learning python programming basics
What next after learning python programming basics
Rakesh Kumar R
 
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Julian Hyde
 

Recently uploaded (20)

UI5con 2024 - Bring Your Own Design System
UI5con 2024 - Bring Your Own Design SystemUI5con 2024 - Bring Your Own Design System
UI5con 2024 - Bring Your Own Design System
 
E-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet DynamicsE-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet Dynamics
 
Microservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we workMicroservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we work
 
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian CompaniesE-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
 
All you need to know about Spring Boot and GraalVM
All you need to know about Spring Boot and GraalVMAll you need to know about Spring Boot and GraalVM
All you need to know about Spring Boot and GraalVM
 
How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?
 
Malibou Pitch Deck For Its €3M Seed Round
Malibou Pitch Deck For Its €3M Seed RoundMalibou Pitch Deck For Its €3M Seed Round
Malibou Pitch Deck For Its €3M Seed Round
 
316895207-SAP-Oil-and-Gas-Downstream-Training.pptx
316895207-SAP-Oil-and-Gas-Downstream-Training.pptx316895207-SAP-Oil-and-Gas-Downstream-Training.pptx
316895207-SAP-Oil-and-Gas-Downstream-Training.pptx
 
GreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-JurisicGreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-Jurisic
 
在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样
在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样
在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样
 
Using Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query PerformanceUsing Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query Performance
 
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CDKuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
 
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
 
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling ExtensionsUI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
 
Mobile app Development Services | Drona Infotech
Mobile app Development Services  | Drona InfotechMobile app Development Services  | Drona Infotech
Mobile app Development Services | Drona Infotech
 
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdfTop Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
 
WWDC 2024 Keynote Review: For CocoaCoders Austin
WWDC 2024 Keynote Review: For CocoaCoders AustinWWDC 2024 Keynote Review: For CocoaCoders Austin
WWDC 2024 Keynote Review: For CocoaCoders Austin
 
Artificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension FunctionsArtificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension Functions
 
What next after learning python programming basics
What next after learning python programming basicsWhat next after learning python programming basics
What next after learning python programming basics
 
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)
 

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