Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
PDX Python lightning talk
Search
Kevin McConnell
March 27, 2014
Programming
160
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
信頼性について考えてみる(SRE NEXT 2026 miniLT)
hayama17
0
200
吝嗇家のためのAI活用 / AI development for miser - ChatGPT + Issue Driven Development
tooppoo
0
190
関数型プログラミングのメリットって何だろう?
wanko_it
0
180
AI時代、エンジニアはどう育つのか -未経験エンジニアの成長を間近で見て考えたこと-
thasu0123
0
140
どこまでゆるくて許されるのか
tk3fftk
0
520
AI時代の仕事技芸論〜ソフトウェア開発で「遊ぶように働く」職人的熟達のすすめ(スクフェス仙台 2026バージョン)
kuranuki
0
680
AI駆動開発を妨げる技術的負債の解消アプローチ / ai-refactoring-approach
minodriven
17
9.2k
自作OSでスライド発表する
uyuki234
1
3.9k
【SRE NEXT 2026 Lunch Session】一人目専任SREの立ち上げを加速する ― AIと進めたオンボーディングで2分を0.04秒にした話
pkshadeck
PRO
0
2.9k
Built Our Own Background Agent at LayerX #aidevex_findy
layerx
PRO
7
2.7k
Go言語とトイモデルで学ぶTransformerの気持ち / fukuokago23-transformer
monochromegane
0
140
SLOをサービス品質の共通言語にするために 取り組んできたこと
wakana0222
0
540
Featured
See All Featured
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
27k
The Pragmatic Product Professional
lauravandoore
37
7.4k
Chasing Engaging Ingredients in Design
codingconduct
0
240
The Curse of the Amulet
leimatthew05
2
13k
Effective software design: The role of men in debugging patriarchy in IT @ Voxxed Days AMS
baasie
0
450
Conquering PDFs: document understanding beyond plain text
inesmontani
PRO
4
2.9k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
16
2k
Discover your Explorer Soul
emna__ayadi
2
1.2k
Music & Morning Musume
bryan
47
7.3k
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
11
970
Reality Check: Gamification 10 Years Later
codingconduct
0
2.2k
The Organizational Zoo: Understanding Human Behavior Agility Through Metaphoric Constructive Conversations (based on the works of Arthur Shelley, Ph.D)
kimpetersen
PRO
0
390
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