Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
PDX Python lightning talk
Search
Kevin McConnell
March 27, 2014
Programming
180
2
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
PDX Python lightning talk
Kevin McConnell
March 27, 2014
Other Decks in Programming
See All in Programming
自サークルのIdPからログアウトできるようになるまで
taiseiue
1
140
Rでドレミ/Do-Re-Mi_with_R
florets1
0
130
Verilogで学ぶCPU自作入門
uyuki234
8
4.1k
APNsからLive Activityを開始する話
yumnumm
0
170
機械に任せるテスト、人が見るテスト ⽣成AIで引き直した、運⽤保守フェーズの線引き
dske104
0
190
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
180
FactoryBotをやめればRSpecは速くなるのか?
yuta_onishi_97
0
270
Jetpack Compose Mechanisms
skydoves
3
820
Web Framework Benchmark Battle 2026, Any%
a_matsuda
2
2k
Unity6 URPによる海底をテーマにしたVJシステムの解説 | Unity Shader 完全に理解した 勉強会
gam0022
0
370
HTML-in-Canvasで作る未来のWeb UI表現
clockmaker
5
5.1k
複雑なUIコンポーネントとの ⻑い付き合い⽅:波及するバグからテスト戦略を経て、安全な再設計へ
mixplace
0
410
Featured
See All Featured
How to optimise 3,500 product descriptions for ecommerce in one day using ChatGPT
katarinadahlin
PRO
3
3.9k
Marketing Yourself as an Engineer | Alaka | Gurzu
gurzu
0
330
My Coaching Mixtape
mlcsv
0
360
Abbi's Birthday
coloredviolet
4
10k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
6.1k
Why You Should Never Use an ORM
jnunemaker
PRO
61
10k
Typedesign – Prime Four
hannesfritz
42
3.2k
Believing is Seeing
oripsolob
1
240
DBのスキルで生き残る技術 - AI時代におけるテーブル設計の勘所
soudai
PRO
68
58k
Navigating Team Friction
lara
192
16k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
18k
Digital Ethics as a Driver of Design Innovation
axbom
PRO
1
460
Transcript
None
Kevin McConnell @kevinmcconnell
A tiny thread pool class
A tiny thread pool class or The impact on performance
of a Service Oriented Architecture
A tiny thread pool class or The impact on performance
of a Service Oriented Architecture or That time we had that really slow website and we made it much faster with only about 10 lines of code
A typical web application • Is written using a framework
• Has some business logic • Talks to other systems • Databases • Caches • APIs
parsing business logic rendering time
parsing business logic rendering time Some of this time spent
waiting on other systems! (hopefully not too much)
time
time (╯°□°)╯︵ ┻━┻
Our application • Connects to ~6 internal APIs • ...most
of which are slow • Hardly any state of its own • Relatively simple business logic
parsing rendering time call API call API call API call
API business logic business logic business logic business logic
parsing business logic rendering time call API call API call
API call API
parsing business logic rendering time call API call API call
API call API ~500ms (mean)
parsing business logic rendering time call API call API call
API call API ~500ms (mean) (mostly just waiting! zzzzz.....)
parsing business logic rendering time call API call API call
API call API ~ 125ms
from threading import Thread! ! ! class ThreadQueue:! def __init__(self):!
self._tasks = {}! self._results = {}! ! def run(self, name, fn, *args, **kwargs):! thread = Thread(target=self._perform,! args=[name, fn, args, kwargs])! self._tasks[name] = thread! thread.start()! ! def get(self, name):! self._tasks[name].join()! return self._results[name]! ! def _perform(self, name, fn, args, kwargs):! self._results[name] = fn(*args, **kwargs)!
from threading import Thread! ! ! class ThreadQueue:! def __init__(self):!
self._tasks = {}! self._results = {}! ! def run(self, name, fn, *args, **kwargs):! thread = Thread(target=self._perform,! args=[name, fn, args, kwargs])! self._tasks[name] = thread! thread.start()! ! def get(self, name):! self._tasks[name].join()! return self._results[name]! ! def _perform(self, name, fn, args, kwargs):! self._results[name] = fn(*args, **kwargs)!
from threading import Thread! ! ! class ThreadQueue:! def __init__(self):!
self._tasks = {}! self._results = {}! ! def run(self, name, fn, *args, **kwargs):! thread = Thread(target=self._perform,! args=[name, fn, args, kwargs])! self._tasks[name] = thread! thread.start()! ! def get(self, name):! self._tasks[name].join()! return self._results[name]! ! def _perform(self, name, fn, args, kwargs):! self._results[name] = fn(*args, **kwargs)!
from threadqueue import ThreadQueue! ! tq = ThreadQueue()! ! tq.run('notifications',
get_user_notifications)! tq.run('billing', get_billing_status)! tq.run('privileges', get_user_privileges)! ! # ...things happen...! # ...! ! if tq.get('privileges')['can_create_projects']:! create_project(...)!
from threadqueue import ThreadQueue! ! tq = ThreadQueue()! ! tq.run('notifications',
get_user_notifications)! tq.run('billing', get_billing_status)! tq.run('privileges', get_user_privileges)! ! # ...things happen...! # ...! ! if tq.get('privileges')['can_create_projects']:! create_project(...)! returns! immediately
from threadqueue import ThreadQueue! ! tq = ThreadQueue()! ! tq.run('notifications',
get_user_notifications)! tq.run('billing', get_billing_status)! tq.run('privileges', get_user_privileges)! ! # ...things happen...! # ...! ! if tq.get('privileges')['can_create_projects']:! create_project(...)! returns! immediately blocks if! results! pending
What we learned • Apps that use many external services
can spend a lot of time blocked on I/O • One way to minimize the waiting time is to do all your waiting at once • There's great support for all sorts of nice concurrency models nowadays, but often a Thread is all you need
@kevinmcconnell Questions? Thanks!
None