~ubuntu-branches/ubuntu/natty/pytables/natty-updates

« back to all changes in this revision

Viewing changes to doc/html/x5576.html

  • Committer: Bazaar Package Importer
  • Author(s): Alexandre Fayolle
  • Date: 2006-06-28 10:45:03 UTC
  • mfrom: (1.1.2 upstream) (2.1.1 etch)
  • Revision ID: james.westby@ubuntu.com-20060628104503-qsoprcycf84lql5h
Tags: 1.3.2-2
  * Fixed call to pyversions in debian/rules which failed on recent versions 
    of pyversions
  * Fixed clean rule in debian/rules which left the stamp files behind
  * Acknowledge NMU
  * Added Alexandre Fayolle to uploaders

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd">
 
2
<HTML
 
3
><HEAD
 
4
><TITLE
 
5
>Getting the most from the node LRU cache</TITLE
 
6
><META
 
7
NAME="GENERATOR"
 
8
CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK
 
9
REL="HOME"
 
10
TITLE="PyTables User's Guide"
 
11
HREF="index.html"><LINK
 
12
REL="UP"
 
13
TITLE="Optimization tips"
 
14
HREF="c5270.html"><LINK
 
15
REL="PREVIOUS"
 
16
TITLE="Using Psyco"
 
17
HREF="x5552.html"><LINK
 
18
REL="NEXT"
 
19
TITLE="Selecting an User Entry Point (UEP) in your
 
20
            tree"
 
21
HREF="x5654.html"></HEAD
 
22
><BODY
 
23
CLASS="sect1"
 
24
BGCOLOR="#FFFFFF"
 
25
TEXT="#000000"
 
26
LINK="#0000FF"
 
27
VLINK="#840084"
 
28
ALINK="#0000FF"
 
29
><DIV
 
30
CLASS="NAVHEADER"
 
31
><TABLE
 
32
SUMMARY="Header navigation table"
 
33
WIDTH="100%"
 
34
BORDER="0"
 
35
CELLPADDING="0"
 
36
CELLSPACING="0"
 
37
><TR
 
38
><TH
 
39
COLSPAN="3"
 
40
ALIGN="center"
 
41
><SPAN
 
42
CLASS="markup"
 
43
>PyTables</SPAN
 
44
> User's Guide: Hierarchical datasets in Python - Release 1.3.2</TH
 
45
></TR
 
46
><TR
 
47
><TD
 
48
WIDTH="10%"
 
49
ALIGN="left"
 
50
VALIGN="bottom"
 
51
><A
 
52
HREF="x5552.html"
 
53
ACCESSKEY="P"
 
54
>Prev</A
 
55
></TD
 
56
><TD
 
57
WIDTH="80%"
 
58
ALIGN="center"
 
59
VALIGN="bottom"
 
60
>Chapter 5. Optimization tips</TD
 
61
><TD
 
62
WIDTH="10%"
 
63
ALIGN="right"
 
64
VALIGN="bottom"
 
65
><A
 
66
HREF="x5654.html"
 
67
ACCESSKEY="N"
 
68
>Next</A
 
69
></TD
 
70
></TR
 
71
></TABLE
 
72
><HR
 
73
ALIGN="LEFT"
 
74
WIDTH="100%"></DIV
 
75
><DIV
 
76
CLASS="sect1"
 
77
><H1
 
78
CLASS="sect1"
 
79
><A
 
80
NAME="section5.6"
 
81
>5.6. Getting the most from the node LRU cache</A
 
82
></H1
 
83
><P
 
84
>Starting from PyTables 1.2 on, it has been introduced a new
 
85
            LRU cache that prevents from loading all the nodes of the
 
86
            <SPAN
 
87
CLASS="emphasis"
 
88
><I
 
89
CLASS="emphasis"
 
90
>object tree</I
 
91
></SPAN
 
92
> in memory. This cache is responsible of
 
93
            loading just up to a certain amount of nodes and discard the
 
94
            least recent used ones when there is a need to load new
 
95
            ones. This represents a big advantage over the old schema,
 
96
            specially in terms of memory usage (as there is no need to
 
97
            load <SPAN
 
98
CLASS="emphasis"
 
99
><I
 
100
CLASS="emphasis"
 
101
>every</I
 
102
></SPAN
 
103
> node in memory), but it also adds very
 
104
            convenient optimizations for working interactively like, for
 
105
            example, speeding-up the opening times of files with lots of
 
106
            nodes, allowing to open almost any kind of file in typically
 
107
            less than one tenth of second (compare this with the more
 
108
            than 10 seconds for files with more than 10000 nodes in
 
109
            PyTables pre-1.2 era). See [<SPAN
 
110
CLASS="citation"
 
111
></SPAN
 
112
>] for more info on the
 
113
            advantages (and also drawbacks) of this approach.
 
114
          </P
 
115
><P
 
116
>One thing that deserves some discussion is the election of
 
117
            the parameter that sets the maximum amount of nodes to be
 
118
            held in memory at any time. As PyTables is meant to be
 
119
            deployed in machines that have potentially low memory, the
 
120
            default for it is quite conservative (you can look at its
 
121
            actual value in the <SAMP
 
122
CLASS="computeroutput"
 
123
>NODE_CACHE_SIZE</SAMP
 
124
> parameter
 
125
            in module <SAMP
 
126
CLASS="computeroutput"
 
127
>tables/constants.py</SAMP
 
128
>). However, if you
 
129
            usually have to deal with files that have much more nodes
 
130
            than the maximum default, and you have a lot of free memory
 
131
            in your system, then you may want to experiment which is the
 
132
            appropriate value of <SAMP
 
133
CLASS="computeroutput"
 
134
>NODE_CACHE_SIZE</SAMP
 
135
> that fits
 
136
            better your needs.
 
137
          </P
 
138
><P
 
139
>As an example, look at the next code:
 
140
          </P
 
141
><PRE
 
142
CLASS="screen"
 
143
>&#13;      def browse_tables(filename):
 
144
            fileh = openFile(filename,'a')
 
145
            group = fileh.root.newgroup
 
146
            for j in range(10):
 
147
            for tt in fileh.walkNodes(group, "Table"):
 
148
            title = tt.attrs.TITLE
 
149
            for row in tt:
 
150
            pass
 
151
            fileh.close()
 
152
          </PRE
 
153
><P
 
154
>We will be running the code above against a couple of files
 
155
            having a <SAMP
 
156
CLASS="computeroutput"
 
157
>/newgroup</SAMP
 
158
> containing 100 tables and
 
159
            1000 tables respectively. We will run this small benchmark
 
160
            for different values of the LRU cache size, namely 256 and
 
161
            1024. You can see the results in <A
 
162
HREF="x5576.html#LRUTblComparison"
 
163
>table�5.1</A
 
164
>.
 
165
          </P
 
166
><DIV
 
167
CLASS="table"
 
168
><A
 
169
NAME="LRUTblComparison"
 
170
></A
 
171
><P
 
172
><B
 
173
>Table 5.1. Retrieving speed and memory consumption
 
174
              dependency of the number of nodes in LRU cache.
 
175
            </B
 
176
></P
 
177
><TABLE
 
178
BORDER="1"
 
179
CLASS="CALSTABLE"
 
180
><COL
 
181
WIDTH="1*"
 
182
ALIGN="left"
 
183
TITLE="c1"><COL
 
184
WIDTH="1*"
 
185
ALIGN="left"
 
186
TITLE="c2"><COL
 
187
WIDTH="1*"
 
188
ALIGN="right"
 
189
TITLE="c3"><COL
 
190
WIDTH="1*"
 
191
ALIGN="right"
 
192
TITLE="c4"><COL
 
193
WIDTH="1*"
 
194
ALIGN="right"
 
195
TITLE="c5"><COL
 
196
WIDTH="1*"
 
197
ALIGN="right"
 
198
TITLE="c6"><COL
 
199
WIDTH="1*"
 
200
ALIGN="right"
 
201
TITLE="c7"><COL
 
202
WIDTH="1*"
 
203
ALIGN="right"
 
204
TITLE="c8"><COL
 
205
WIDTH="1*"
 
206
ALIGN="right"
 
207
TITLE="c9"><COL
 
208
WIDTH="1*"
 
209
ALIGN="right"
 
210
TITLE="c10"><THEAD
 
211
><TR
 
212
><TH
 
213
COLSPAN="2"
 
214
ALIGN="left"
 
215
>&nbsp;</TH
 
216
><TH
 
217
COLSPAN="4"
 
218
ALIGN="center"
 
219
>100 nodes</TH
 
220
><TH
 
221
COLSPAN="4"
 
222
ALIGN="center"
 
223
>1000 nodes</TH
 
224
></TR
 
225
><TR
 
226
><TH
 
227
COLSPAN="2"
 
228
ALIGN="left"
 
229
>&nbsp;</TH
 
230
><TH
 
231
COLSPAN="2"
 
232
ALIGN="center"
 
233
>Memory (MB)</TH
 
234
><TH
 
235
COLSPAN="2"
 
236
ALIGN="center"
 
237
>Time (ms)</TH
 
238
><TH
 
239
COLSPAN="2"
 
240
ALIGN="center"
 
241
>Memory (MB)</TH
 
242
><TH
 
243
COLSPAN="2"
 
244
ALIGN="center"
 
245
>Time (ms)</TH
 
246
></TR
 
247
><TR
 
248
><TH
 
249
ALIGN="left"
 
250
>Node is coming from...</TH
 
251
><TH
 
252
ALIGN="left"
 
253
>Cache size</TH
 
254
><TH
 
255
ALIGN="right"
 
256
>256</TH
 
257
><TH
 
258
ALIGN="right"
 
259
>1024</TH
 
260
><TH
 
261
ALIGN="right"
 
262
>256</TH
 
263
><TH
 
264
ALIGN="right"
 
265
>1024</TH
 
266
><TH
 
267
ALIGN="right"
 
268
>256</TH
 
269
><TH
 
270
ALIGN="right"
 
271
>1024</TH
 
272
><TH
 
273
ALIGN="right"
 
274
>256</TH
 
275
><TH
 
276
ALIGN="right"
 
277
>1024</TH
 
278
></TR
 
279
></THEAD
 
280
><TBODY
 
281
><TR
 
282
><TD
 
283
ALIGN="left"
 
284
>From disk</TD
 
285
><TD
 
286
ALIGN="left"
 
287
>&nbsp;</TD
 
288
><TD
 
289
ALIGN="right"
 
290
>14</TD
 
291
><TD
 
292
ALIGN="right"
 
293
>14</TD
 
294
><TD
 
295
ALIGN="right"
 
296
>1.24</TD
 
297
><TD
 
298
ALIGN="right"
 
299
>1.24</TD
 
300
><TD
 
301
ALIGN="right"
 
302
>51</TD
 
303
><TD
 
304
ALIGN="right"
 
305
>66</TD
 
306
><TD
 
307
ALIGN="right"
 
308
>1.33</TD
 
309
><TD
 
310
ALIGN="right"
 
311
>1.31</TD
 
312
></TR
 
313
><TR
 
314
><TD
 
315
ALIGN="left"
 
316
>From cache</TD
 
317
><TD
 
318
ALIGN="left"
 
319
>&nbsp;</TD
 
320
><TD
 
321
ALIGN="right"
 
322
>14</TD
 
323
><TD
 
324
ALIGN="right"
 
325
>14</TD
 
326
><TD
 
327
ALIGN="right"
 
328
>0.53</TD
 
329
><TD
 
330
ALIGN="right"
 
331
>0.52</TD
 
332
><TD
 
333
ALIGN="right"
 
334
>65</TD
 
335
><TD
 
336
ALIGN="right"
 
337
>73</TD
 
338
><TD
 
339
ALIGN="right"
 
340
>1.35</TD
 
341
><TD
 
342
ALIGN="right"
 
343
>0.68</TD
 
344
></TR
 
345
></TBODY
 
346
></TABLE
 
347
></DIV
 
348
><P
 
349
>From the data in <A
 
350
HREF="x5576.html#LRUTblComparison"
 
351
>table�5.1</A
 
352
>,
 
353
            one can see that, when the number of objects that you are
 
354
            dealing with does fit in cache, you will get better access
 
355
            times to them. Also, incrementing the node cache size does
 
356
            effectively consumes more memory <SPAN
 
357
CLASS="emphasis"
 
358
><I
 
359
CLASS="emphasis"
 
360
>only</I
 
361
></SPAN
 
362
> if the total
 
363
            nodes exceeds the slots in cache; otherwise the memory
 
364
            consumption remains the same. It is also worth noting that
 
365
            incrementing the node cache size in the case you want to fit
 
366
            all your nodes in cache, it does not take much more memory
 
367
            than keeping too conservative. On another hand, it might
 
368
            happen that the speed-up that you can achieve by allocating
 
369
            more slots in your cache maybe is not worth the amount of
 
370
            memory used.
 
371
          </P
 
372
><P
 
373
>Anyway, if you feel that this issue is important for you,
 
374
            setup your own experiments and proceed fine-tuning the
 
375
            <SAMP
 
376
CLASS="computeroutput"
 
377
>NODE_CACHE_SIZE</SAMP
 
378
> parameter.
 
379
          </P
 
380
></DIV
 
381
><DIV
 
382
CLASS="NAVFOOTER"
 
383
><HR
 
384
ALIGN="LEFT"
 
385
WIDTH="100%"><TABLE
 
386
SUMMARY="Footer navigation table"
 
387
WIDTH="100%"
 
388
BORDER="0"
 
389
CELLPADDING="0"
 
390
CELLSPACING="0"
 
391
><TR
 
392
><TD
 
393
WIDTH="33%"
 
394
ALIGN="left"
 
395
VALIGN="top"
 
396
><A
 
397
HREF="x5552.html"
 
398
ACCESSKEY="P"
 
399
>Prev</A
 
400
></TD
 
401
><TD
 
402
WIDTH="34%"
 
403
ALIGN="center"
 
404
VALIGN="top"
 
405
><A
 
406
HREF="index.html"
 
407
ACCESSKEY="H"
 
408
>Home</A
 
409
></TD
 
410
><TD
 
411
WIDTH="33%"
 
412
ALIGN="right"
 
413
VALIGN="top"
 
414
><A
 
415
HREF="x5654.html"
 
416
ACCESSKEY="N"
 
417
>Next</A
 
418
></TD
 
419
></TR
 
420
><TR
 
421
><TD
 
422
WIDTH="33%"
 
423
ALIGN="left"
 
424
VALIGN="top"
 
425
>Using Psyco</TD
 
426
><TD
 
427
WIDTH="34%"
 
428
ALIGN="center"
 
429
VALIGN="top"
 
430
><A
 
431
HREF="c5270.html"
 
432
ACCESSKEY="U"
 
433
>Up</A
 
434
></TD
 
435
><TD
 
436
WIDTH="33%"
 
437
ALIGN="right"
 
438
VALIGN="top"
 
439
>Selecting an User Entry Point (UEP) in your
 
440
            tree</TD
 
441
></TR
 
442
></TABLE
 
443
></DIV
 
444
></BODY
 
445
></HTML
 
446
>
 
 
b'\\ No newline at end of file'