Skip to content

Commit a91b229

Browse files
committed
Update the example demo, too
1 parent 01b057a commit a91b229

File tree

1 file changed

+48
-4
lines changed

1 file changed

+48
-4
lines changed

examples/atomspace/persist-buffer.scm

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,16 @@
1818
; The WriteBufferProxy uses a time-delay mechanism to write out a portion
1919
; of the buffer over time. It uses an exponential decay strategy, so that
2020
; 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
2323
; of them will be actually written out.
24+
;
25+
; ---------------------------------------------------------------------
2426

2527
(use-modules (opencog) (opencog persist))
2628
(use-modules (opencog persist-rocks))
2729

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
2931
; parameter is optional, and can be skipped.
3032
(ProxyParameters
3133
(WriteBufferProxy "write buffer")
@@ -45,7 +47,9 @@
4547
; the (barrier) command. For example:
4648
(barrier)
4749

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.)
4953
(display (monitor-storage (WriteBufferProxy "write buffer")))
5054

5155
; There are also perf stats for the base server:
@@ -63,5 +67,45 @@
6367
; before returning.
6468
(cog-close (WriteBufferProxy "write buffer"))
6569

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+
66110
; That's All, Folks!
67111
; ---------------------------------------------------------------------

0 commit comments

Comments
 (0)