forked from hakimel/reveal.js
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathperformance.html
339 lines (300 loc) · 13.9 KB
/
performance.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>How to optimize performance</title>
<meta name="description" content="Tips for advanced development">
<meta name="author" content="Raphael Collet">
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, minimal-ui">
<link rel="stylesheet" href="css/reveal.css">
<link rel="stylesheet" href="css/theme/odoo.css" id="theme">
<!-- Code syntax highlighting -->
<link rel="stylesheet" href="lib/css/zenburn.css">
<!-- Printing and PDF exports -->
<script>
var link = document.createElement( 'link' );
link.rel = 'stylesheet';
link.type = 'text/css';
link.href = window.location.search.match( /print-pdf/gi ) ? 'css/print/pdf.css' : 'css/print/paper.css';
document.getElementsByTagName( 'head' )[0].appendChild( link );
</script>
<!--[if lt IE 9]>
<script src="lib/js/html5shiv.js"></script>
<![endif]-->
</head>
<body>
<div class="reveal">
<!-- Any section element inside of this container is displayed as a slide -->
<div class="slides">
<section class="title">
<h1>How to optimize performance</h1>
<h3>Raphael Collet</h3>
</section>
<section data-background="Snail_on_railing.jpg">
</section>
<section class="chapter">
<h1>Tips for deployment</h1>
</section>
<section class="nested">
<section>
<h2>High performance Odoo</h2>
<p>See Olivier Dony's last year presentation:
<a href="http://www.slideshare.net/openobject/performance2014-35689113">http://www.slideshare.net/openobject/performance2014-35689113</a></p>
<blockquote>
Odoo can handle large data and transaction volumes
out of the box!
</blockquote>
</section>
<section>
<h2>Performance issues</h2>
<p>can easily be fixed with</p>
<ul>
<li>the right <strong>tools</strong> and</li>
<li>the right <strong>facts</strong>.</li>
</ul>
</section>
</section>
<section class="nested">
<section>
<h2>Facts</h2>
<p>PostgreSQL</p>
<ul>
<li>is the real workhorse of your Odoo server;</li>
<li>powers large cloud services;</li>
<li>can handle terabytes of data efficiently;</li>
<li>should be fine-tuned to use your hardware.</li>
</ul>
<p>Hardware sizing</p>
<ul>
<li>Appropriate load testing is a
<strong>must</strong> before going live!</li>
</ul>
</section>
</section>
<section class="nested">
<section>
<h2>Deployment architecture</h2>
<p>Single server, multi-process (workers)</p>
<ul>
<li>Rule of thumb: #workers = 2 * #cores + 1</li>
</ul>
<p>Multi-server, multi-process (workers)</p>
<ul>
<li>Use a load balancer to redirect requests to servers.</li>
<li>The filestore (attachments) must be shared.</li>
</ul>
</section>
<section>
<h2>PostgreSQL deployment</h2>
<p>Recent versions (9.2, 9.3) have excellent performance.</p>
<p>Tune it: memory, etc (see documentation)</p>
<p>Avoid deploying on a VM.</p>
</section>
</section>
<section class="nested">
<section>
<h2>Monitor and measure</h2>
<ul>
<li>System load</li>
<li>Disk I/O</li>
<li>Transactions per second</li>
<li>Database size</li>
</ul>
</section>
<section>
<h2>PostgreSQL Analysis</h2>
<p>Check tools (pg_badger) and tables for statistics:</p>
<ul>
<li>transactions</li>
<li>heavy locks</li>
<li>use stats for tables</li>
<li>I/O stats for tables</li>
</ul>
</section>
</section>
<section class="chapter">
<h1>Tips for developers</h1>
</section>
<section class="nested">
<section>
<h2>Code complexity</h2>
<p>Linear O(n) is good.</p>
<pre><code class="python" data-trim>
result = []
for record in self:
result.append(...)
</code></pre>
<p>Quadratic O(n²) does not scale when n becomes large.</p>
<pre><code class="python" data-trim>
result = []
for record in self:
for moves in record.picking_id.move_ids:
result.append(...)
</code></pre>
</section>
<section>
<h2>Code complexity</h2>
<ul>
<li>Avoid complexity higher than linear when possible.</li>
<li>Calling a method with linear complexity in a loop
makes it quadratic.</li>
<li>Work with batches:
<ul>
<li>The model API works with batches (recordsets).</li>
<li>Fields are computed in batches.</li>
<li>Reading records prefetches in batches.</li>
</ul>
</li>
</ul>
</section>
</section>
<section class="nested">
<section>
<h2>The record cache</h2>
<ul>
<li>Stores field values for records.
<pre><code class="python" data-trim>
record._cache['name']
record.env.cache[field][record.id]
</code></pre>
</li>
<li>Every environment has its <em>own</em> cache.</li>
<li>Cache <em>prefetching</em> when accessing a field for
the first time:
<ul>
<li>prefetches records browsed in the same environment;</li>
<li>prefetches fields from the same table.</li>
</ul>
</li>
</ul>
</section>
<section>
<h2>Bad prefetching</h2>
<p>"Prefetch records browsed in the same environment."</p>
<pre><code class="python" data-trim>
# some query... -> model, id
query = "..."
params = ...
self._cr.execute(query, params)
# process results record by record
for (model, id) in self._cr.fetchall():
record = self.env[model].browse(id)
if record.partner_id ...:
...
</code></pre>
<p>This loop issues O(n) queries.</p>
</section>
<section>
<h2>Good prefetching</h2>
<p>Browse all records <em>before</em> accessing their fields.</p>
<pre><code class="python" data-trim>
# some query... -> model, id
...
# retrieve records first
record_list = []
for (model, id) in self._cr.fetchall():
record = self.env[model].browse(id)
record_list.append(record)
# process records
for record in record_list:
if record.partner_id ...:
...
</code></pre>
<p>The second loop issues O(1) queries.</p>
</section>
</section>
<section class="nested">
<section>
<h2>Domains and Searches</h2>
<p>Cross-model conditions do not use JOIN by default.</p>
<pre><code class="python" data-trim>
domain = [('picking_id.move_ids.partner_id', '!=', False)]
records = self.search(domain)
</code></pre>
<p>This does something like:</p>
<pre><code class="python" data-trim>
moves = Move.search([('partner_id', '!=', False)])
pickings = Picking.search([('move_ids', 'in', moves.ids)])
records = self.searcg([('picking_id', 'in', pickings.ids)])
</code></pre>
<p>Issue: "moves" and "pickings" may be huge!</p>
</section>
<section>
<h2>Domains and Searches</h2>
<p>Use "auto_join" to enable the use of JOIN.</p>
<pre><code class="python" data-trim>
class Picking(models.Model):
...
move_ids = fields.One2many('stock.move', 'picking_id',
string="Moves", auto_join=True)
</code></pre>
<p>The impact may be important when such conditions
appear in <em>record rules</em> (security filter.)</p>
</section>
</section>
<section class="nested">
<section>
<h2>Profiling</h2>
<ul>
<li>Log and check SQL queries sent to the database:
<pre><code data-trim>
./odoo.py ... --log-sql
</code></pre>
With that, we found cases where cache prefetching
was not working as expected.
</li>
<li>line_profiler (pypi): costly, but useful for <em>local</em>
optimization.</li>
<li>plop (Python Low-Overhead Profiler) + FlameGraph
(<a href="load-registry-sale.svg">example</a>)
</li>
</ul>
</section>
</section>
<section class="title">
<h1><span>Thank you</span></h1>
<h3>Raphael Collet (rco@odoo.com)</h3>
<div style="width: 32%; display: inline-block; vertical-align: text-top; font-size: 60%">
<b>Odoo</b><br/>
sales@odoo.com<br/>
www.odoo.com
</div>
<div style="width: 32%; display: inline-block; vertical-align: text-top; font-size: 60%">
<b>R&D and Services office</b><br/>
Chaussée de Namur 40</br>
B-1367 Grand-Rosière
</div>
<div style="width: 32%; display: inline-block; vertical-align: text-top; font-size: 60%">
<b>Sales office</b><br/>
Avenue Van Nieuwenhuyse 5</br>
B-1160 Brussels
</div>
</section>
</div>
</div>
<script src="lib/js/head.min.js"></script>
<script src="js/reveal.js"></script>
<script>
// Full list of configuration options available at:
// https://github.com/hakimel/reveal.js#configuration
Reveal.initialize({
controls: true,
progress: true,
history: true,
center: false,
transition: 'slide', // none/fade/slide/convex/concave/zoom
// Optional reveal.js plugins
dependencies: [
{ src: 'lib/js/classList.js', condition: function() { return !document.body.classList; } },
{ src: 'plugin/markdown/marked.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
{ src: 'plugin/markdown/markdown.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
{ src: 'plugin/highlight/highlight.js', async: true, condition: function() { return !!document.querySelector( 'pre code' ); }, callback: function() { hljs.initHighlightingOnLoad(); } },
{ src: 'plugin/zoom-js/zoom.js', async: true },
{ src: 'plugin/notes/notes.js', async: true }
]
});
</script>
</body>
</html>