SlideShare a Scribd company logo
Multithreading in
PowerShell with runspaces
1/18/2017
Drew Furgiuele
Senior DBA, IGS Energy
1/18/2017 2
About me
dfurgiuele@igsenergy.com
@pittfurg
http://www.port1433.com
http://www.genesface.com
Contact Info
I’m a Senior SQL Server DBA at
IGS Energy in Dublin, Ohio. I’ve
been using SQL Server since SQL
Server 2000 and I love it. I also
enjoy DevOps, release
management, and PowerShell.
AGENDA
1/18/2017 3
1. Multithreading in PowerShell: Why?
2. How it works
3. Differences between runspaces and Invoke-Job
4. Examples!
Multithreading with PowerShell
• Most PowerShell scripts execute serially
• Which is usually fine!
• … Except when it isn’t
• Some things don’t always run fast, despite all the
optimization in the world
• And if something runs “fast” when applied to n+1
targets, it might become slow
1/18/2017 4
Runspaces – The good
• Runspaces spin up new threads on an existing
process for parallel execution.
• Threads can be invoked asynchronously
• Can automatically manage the number of
threads executing (so you don’t overwhelm
your CPU)
• Can return pretty much anything you want
1/18/2017 5
Runspaces – The not so good
1/18/2017 6
• Can be complex to set up and configure
• Need monitored
• Need cleaned up
• Are hard to troubleshoot
• Modules don’t persist
“… so preoccupied with whether or not you could…”
• “…that you didn't stop to think if you should.”
• Multithreading is a great tool to keep in your
toolbox, but it’s not a hammer looking for a nail
• Ever heard of failing at scale?
• How about failing at scalex?
1/18/2017 7
Creating Runspaces
• CODE!
1/18/2017 8
What about Start-Job / Receive-Job?
• Start-Job incurs a lot of overhead
• No throttling
• Same goes for –AsJob and Invoke-Command
• Does have a –ThrottleLimit, but that just limits
concurrent commands, NOT sessions
• How much of a difference? Let’s see it in action.
1/18/2017 9
Practical Example #1
• Reading Error Logs
• Text parsing in PowerShell is an expensive, slow
process
• Breaking up the workload into threads can vastly
improve performance
1/18/2017 10
Practical Example
• Master Data Management
1/18/2017 11
Learning More
• Runspaces – Hey Scripting Guy!
https://blogs.technet.microsoft.com/heyscriptingguy/
2015/11/26/beginning-use-of-powershell-runspaces-
part-1/
• Runspaces simplified as much as possible:
https://blog.netnerds.net/2016/12/runspaces-
simplified/
• Joe Prox’s PoshRSJob:
https://github.com/proxb/PoshRSJob
1/18/2017 12
1/18/2017 13
About me
dfurgiuele@igsenergy.com
@pittfurg
http://www.port1433.com
http://www.genesface.com
Contact Info
I’m a Senior SQL Server DBA at
IGS Energy in Dublin, Ohio. I’ve
been using SQL Server since SQL
Server 2000 and I love it. I also
enjoy DevOps, release
management, and PowerShell.

More Related Content

PPTX
Full stack development using javascript what and why - ajay chandravadiya
PDF
Creating Hyper Performant Web Apps with React
PPTX
Saving Time By Testing With Jest
PDF
Seven Jobs You Should Be Running #sqlsat126
PDF
Composer manager module for Drupal
PPTX
SQL Server Days 2014 - How to (not) torment your fellow SSIS developer
PPTX
The Five Stages of Chef Grief: My First 6 months with Chef, and Getting Aroun...
PPTX
Tech writing in a continuous deployment environment
Full stack development using javascript what and why - ajay chandravadiya
Creating Hyper Performant Web Apps with React
Saving Time By Testing With Jest
Seven Jobs You Should Be Running #sqlsat126
Composer manager module for Drupal
SQL Server Days 2014 - How to (not) torment your fellow SSIS developer
The Five Stages of Chef Grief: My First 6 months with Chef, and Getting Aroun...
Tech writing in a continuous deployment environment

What's hot (20)

PDF
ClojureScript: I can't believe this is JavaScript
PDF
Why puppet? Why now?
PDF
New Server in an Hour
PDF
An introduction in to the world of front end automation - frontend ne (02 07-15)
PPTX
Introduction to Coffeescript
PDF
Kanban @ nine.ch
PDF
Performance - When, What and How
PDF
GETTING STARTED WITH JavaScript and ReactJS
PDF
DevOps for Drupal: Why We Cook With Chef
PPT
Coffee script final
PPTX
Raven db byexample
PPTX
Zeev Suraski "The PHP 7 Story, and beyond"
PDF
No More Cowboy Coding: Modern WordPress Development Workflow That Scales
PPTX
Coding for the cloud - development of modern web applications
PDF
It Sounded Good on Paper - Lessons Learned with Puppet
PPT
Developer Week
PDF
Supporting large scale React applications
PPTX
Building large scalable mission critical business applications on the web
PDF
Getting started with dev tools (atl)
PDF
Devops at Startup Weekend BXL
ClojureScript: I can't believe this is JavaScript
Why puppet? Why now?
New Server in an Hour
An introduction in to the world of front end automation - frontend ne (02 07-15)
Introduction to Coffeescript
Kanban @ nine.ch
Performance - When, What and How
GETTING STARTED WITH JavaScript and ReactJS
DevOps for Drupal: Why We Cook With Chef
Coffee script final
Raven db byexample
Zeev Suraski "The PHP 7 Story, and beyond"
No More Cowboy Coding: Modern WordPress Development Workflow That Scales
Coding for the cloud - development of modern web applications
It Sounded Good on Paper - Lessons Learned with Puppet
Developer Week
Supporting large scale React applications
Building large scalable mission critical business applications on the web
Getting started with dev tools (atl)
Devops at Startup Weekend BXL
Ad

Similar to PowerShell Runspaces (20)

PDF
I6 - State of the art SharePoint PowerShell Nation 2017 - Spencer Harbar
PDF
Erlang factory SF 2011 "Erlang and the big switch in social games"
PDF
Erlang, the big switch in social games
PDF
How to get started with Site Reliability Engineering
ODP
Devops in with the old, in with the new
PPTX
Learn from my Mistakes - Building Better Solutions in SPFx
PPTX
Bringing Open-Source Practices to Your Day Job
PDF
Why use Go for web development?
PPTX
CI_CONF 2012: Scaling
PPTX
CI_CONF 2012: Scaling - Chris Miller
PPTX
HyperDB, MySQL Performance, & Flavors of MySQL
PPTX
Untangling spring week11
PDF
The Characteristics of a Successful SPA
PDF
PostgreSQL worst practices, version FOSDEM PGDay 2017 by Ilya Kosmodemiansky
PPTX
Profiling and Tuning a Web Application - The Dirty Details
PPTX
Software development fundamentals
PPTX
Untangling spring week1
PPT
Apache Con 2008 Top 10 Mistakes
PPTX
Untangling - fall2017 - week 7
PDF
Neo4j Training Cypher
I6 - State of the art SharePoint PowerShell Nation 2017 - Spencer Harbar
Erlang factory SF 2011 "Erlang and the big switch in social games"
Erlang, the big switch in social games
How to get started with Site Reliability Engineering
Devops in with the old, in with the new
Learn from my Mistakes - Building Better Solutions in SPFx
Bringing Open-Source Practices to Your Day Job
Why use Go for web development?
CI_CONF 2012: Scaling
CI_CONF 2012: Scaling - Chris Miller
HyperDB, MySQL Performance, & Flavors of MySQL
Untangling spring week11
The Characteristics of a Successful SPA
PostgreSQL worst practices, version FOSDEM PGDay 2017 by Ilya Kosmodemiansky
Profiling and Tuning a Web Application - The Dirty Details
Software development fundamentals
Untangling spring week1
Apache Con 2008 Top 10 Mistakes
Untangling - fall2017 - week 7
Neo4j Training Cypher
Ad

Recently uploaded (20)

PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
Spectroscopy.pptx food analysis technology
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Approach and Philosophy of On baking technology
PDF
Electronic commerce courselecture one. Pdf
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Encapsulation theory and applications.pdf
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
MIND Revenue Release Quarter 2 2025 Press Release
Network Security Unit 5.pdf for BCA BBA.
Spectroscopy.pptx food analysis technology
Spectral efficient network and resource selection model in 5G networks
Unlocking AI with Model Context Protocol (MCP)
Dropbox Q2 2025 Financial Results & Investor Presentation
Approach and Philosophy of On baking technology
Electronic commerce courselecture one. Pdf
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Encapsulation_ Review paper, used for researhc scholars
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Chapter 3 Spatial Domain Image Processing.pdf
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Encapsulation theory and applications.pdf
Digital-Transformation-Roadmap-for-Companies.pptx
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Mobile App Security Testing_ A Comprehensive Guide.pdf
Understanding_Digital_Forensics_Presentation.pptx
“AI and Expert System Decision Support & Business Intelligence Systems”
MIND Revenue Release Quarter 2 2025 Press Release

PowerShell Runspaces

  • 1. Multithreading in PowerShell with runspaces 1/18/2017 Drew Furgiuele Senior DBA, IGS Energy
  • 2. 1/18/2017 2 About me dfurgiuele@igsenergy.com @pittfurg http://www.port1433.com http://www.genesface.com Contact Info I’m a Senior SQL Server DBA at IGS Energy in Dublin, Ohio. I’ve been using SQL Server since SQL Server 2000 and I love it. I also enjoy DevOps, release management, and PowerShell.
  • 3. AGENDA 1/18/2017 3 1. Multithreading in PowerShell: Why? 2. How it works 3. Differences between runspaces and Invoke-Job 4. Examples!
  • 4. Multithreading with PowerShell • Most PowerShell scripts execute serially • Which is usually fine! • … Except when it isn’t • Some things don’t always run fast, despite all the optimization in the world • And if something runs “fast” when applied to n+1 targets, it might become slow 1/18/2017 4
  • 5. Runspaces – The good • Runspaces spin up new threads on an existing process for parallel execution. • Threads can be invoked asynchronously • Can automatically manage the number of threads executing (so you don’t overwhelm your CPU) • Can return pretty much anything you want 1/18/2017 5
  • 6. Runspaces – The not so good 1/18/2017 6 • Can be complex to set up and configure • Need monitored • Need cleaned up • Are hard to troubleshoot • Modules don’t persist
  • 7. “… so preoccupied with whether or not you could…” • “…that you didn't stop to think if you should.” • Multithreading is a great tool to keep in your toolbox, but it’s not a hammer looking for a nail • Ever heard of failing at scale? • How about failing at scalex? 1/18/2017 7
  • 9. What about Start-Job / Receive-Job? • Start-Job incurs a lot of overhead • No throttling • Same goes for –AsJob and Invoke-Command • Does have a –ThrottleLimit, but that just limits concurrent commands, NOT sessions • How much of a difference? Let’s see it in action. 1/18/2017 9
  • 10. Practical Example #1 • Reading Error Logs • Text parsing in PowerShell is an expensive, slow process • Breaking up the workload into threads can vastly improve performance 1/18/2017 10
  • 11. Practical Example • Master Data Management 1/18/2017 11
  • 12. Learning More • Runspaces – Hey Scripting Guy! https://blogs.technet.microsoft.com/heyscriptingguy/ 2015/11/26/beginning-use-of-powershell-runspaces- part-1/ • Runspaces simplified as much as possible: https://blog.netnerds.net/2016/12/runspaces- simplified/ • Joe Prox’s PoshRSJob: https://github.com/proxb/PoshRSJob 1/18/2017 12
  • 13. 1/18/2017 13 About me dfurgiuele@igsenergy.com @pittfurg http://www.port1433.com http://www.genesface.com Contact Info I’m a Senior SQL Server DBA at IGS Energy in Dublin, Ohio. I’ve been using SQL Server since SQL Server 2000 and I love it. I also enjoy DevOps, release management, and PowerShell.