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
「なぜそう決めたのか」を残し続ける仕組み ― Notion AI カスタムエージェント × Slack連携による設計判断の自動記録 - NIKKEI Tech Talk #47
niftycorp
PRO
0
230
Language Server 使ってる? 〜VSCode と Zed の場合〜 / Are you using a Language Server? ~For VS Code and Zed~
handlename
0
810
Observability in Practice:Grafana 與 Edge Device SRE 的那些事
blueswen
0
180
キャリア迷子上等 ─ "ない道"は自分で作ればいい
16bitidol
3
2.3k
JavaDoc 再入門
nagise
1
420
LLM本来の能力を解き放つサンドボックス技術とAI民主化への適用
yukukotani
3
4.6k
OSもどきOS
arkw
0
590
A2UI という光を覗いてみる
satohjohn
1
160
Agentic UI
manfredsteyer
PRO
0
200
The ROI of Quarkus for Spring Boot Applications
hollycummins
0
140
エンジニア向け会社紹介/Findy Company Profile
findyinc
6
350k
ECSアプリログをFireLensでコスト削減しようとしたけど諦めた話 in Fargate×Node.js
akihisaikeda
2
4.2k
Featured
See All Featured
What's in a price? How to price your products and services
michaelherold
247
13k
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.7k
Designing for Performance
lara
611
70k
Amusing Abliteration
ianozsvald
1
210
Exploring the relationship between traditional SERPs and Gen AI search
raygrieselhuber
PRO
2
4k
Docker and Python
trallard
47
3.9k
Paper Plane
katiecoart
PRO
1
52k
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
140
Everyday Curiosity
cassininazir
0
240
How to build a perfect <img>
jonoalderson
1
5.7k
The Organizational Zoo: Understanding Human Behavior Agility Through Metaphoric Constructive Conversations (based on the works of Arthur Shelley, Ph.D)
kimpetersen
PRO
0
370
Avoiding the “Bad Training, Faster” Trap in the Age of AI
tmiket
0
180
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