|
18 | 18 | ; The WriteBufferProxy uses a time-delay mechanism to write out a portion |
19 | 19 | ; of the buffer over time. It uses an exponential decay strategy, so that |
20 | 20 | ; a portion exp(-t/T0) of the buffer is written out after t seconds. The |
21 | | -; default time constant T0 is 30 seconds; this means that most writes in |
22 | | -; a 30-second window will be buffered up, but about exp(-30/30)=exp(-1)=0.22 |
| 21 | +; default time constant T0 is 60 seconds; this means that most writes in |
| 22 | +; a 60-second window will be buffered up, but about exp(-60/60)=exp(-1)=0.22 |
23 | 23 | ; of them will be actually written out. |
| 24 | +; |
| 25 | +; --------------------------------------------------------------------- |
24 | 26 |
|
25 | 27 | (use-modules (opencog) (opencog persist)) |
26 | 28 | (use-modules (opencog persist-rocks)) |
27 | 29 |
|
28 | | -; The default write buffer size is 30 seconds; change it to 42. This |
| 30 | +; The default write buffer size is 60 seconds; change it to 42. This |
29 | 31 | ; parameter is optional, and can be skipped. |
30 | 32 | (ProxyParameters |
31 | 33 | (WriteBufferProxy "write buffer") |
|
45 | 47 | ; the (barrier) command. For example: |
46 | 48 | (barrier) |
47 | 49 |
|
48 | | -; View performance stats: |
| 50 | +; View performance stats. (But these will be zero, because 42 seconds |
| 51 | +; haven't passed by yet. The average rate is also rounded to the nearest |
| 52 | +; integer, and so will round down to zero.) |
49 | 53 | (display (monitor-storage (WriteBufferProxy "write buffer"))) |
50 | 54 |
|
51 | 55 | ; There are also perf stats for the base server: |
|
63 | 67 | ; before returning. |
64 | 68 | (cog-close (WriteBufferProxy "write buffer")) |
65 | 69 |
|
| 70 | +; --------------------------------------------------------------------- |
| 71 | +; The WriteBuffer only buffers writes. It completely ignores reads. |
| 72 | +; In most cases, one wants to both read and write. This is arranged |
| 73 | +; for by using the ReadWriteProxy, to gang together one reader and |
| 74 | +; one writer. |
| 75 | + |
| 76 | +(ProxyParameters |
| 77 | +(ReadWriteProxy "read w/write buffer") |
| 78 | +(List |
| 79 | +(RocksStorageNode "rocks:///tmp/foo.rdb") ;; target for reads |
| 80 | +(WriteBufferProxy "write buffer"))) ;; target for writes |
| 81 | + |
| 82 | +(cog-open (ReadWriteProxy "read w/write buffer")) |
| 83 | +(fetch-atom (Concept "foo")) |
| 84 | +(cog-set-value! (Concept "foo") (Predicate "fizz") (Concept "oh hi")) |
| 85 | +(store-atom (Concept "foo"))) |
| 86 | +(cog-close (ReadWriteProxy "read w/write buffer")) |
| 87 | + |
| 88 | +; One can get fancier: the reader always goes to the target to read |
| 89 | +; Atoms and Values. The CachingProxy will cache reads, avoiding a |
| 90 | +; fetch from storage, if the given Atom/Value is already in the |
| 91 | +; AtomSpace. The can be ganged up with the write-buffer, to offer |
| 92 | +; caching both ways. |
| 93 | + |
| 94 | +(ProxyParameters |
| 95 | +(CachingProxy "read cache") |
| 96 | +(RocksStorageNode "rocks:///tmp/foo.rdb")) |
| 97 | + |
| 98 | +(ProxyParameters |
| 99 | +(ReadWriteProxy "full cache") |
| 100 | +(List |
| 101 | +(CachingProxy "read cache") ;; target for reads |
| 102 | +(WriteBufferProxy "write buffer"))) ;; target for writes |
| 103 | + |
| 104 | +(cog-open (ReadWriteProxy "full cache")) |
| 105 | +(fetch-atom (Concept "foo"))) |
| 106 | +(cog-set-value! (Concept "foo") (Predicate "fizz") (Number 42)) |
| 107 | +(store-atom (Concept "foo"))) |
| 108 | +(cog-close (ReadWriteProxy "full cache")) |
| 109 | + |
66 | 110 | ; That's All, Folks! |
67 | 111 | ; --------------------------------------------------------------------- |
0 commit comments