summaryrefslogtreecommitdiff
path: root/caching-tests
diff options
context:
space:
mode:
Diffstat (limited to 'caching-tests')
-rw-r--r--caching-tests/bench.lua25
-rw-r--r--caching-tests/bench.ur16
-rw-r--r--caching-tests/bench.urp6
-rw-r--r--caching-tests/bench.urs2
-rw-r--r--caching-tests/some-results.txt198
-rw-r--r--caching-tests/test.ur111
-rw-r--r--caching-tests/test.urp9
-rw-r--r--caching-tests/test.urs8
8 files changed, 375 insertions, 0 deletions
diff --git a/caching-tests/bench.lua b/caching-tests/bench.lua
new file mode 100644
index 00000000..6799ca87
--- /dev/null
+++ b/caching-tests/bench.lua
@@ -0,0 +1,25 @@
+math.randomseed(os.time())
+
+p = 0.25
+n = 2000
+
+function init(args)
+ if args[1] then
+ p = tonumber(args[1])
+ end
+ if args[2] then
+ n = tonumber(args[2])
+ end
+end
+
+function request()
+ path = "/Bench/"
+ if math.random() < p then
+ path = path .. "flush"
+ else
+ path = path .. "check"
+ end
+ id = math.random(n)
+ path = path .. "/" .. id
+ return wrk.format(nil, path)
+end
diff --git a/caching-tests/bench.ur b/caching-tests/bench.ur
new file mode 100644
index 00000000..2661bd0e
--- /dev/null
+++ b/caching-tests/bench.ur
@@ -0,0 +1,16 @@
+table tab : {Id : int, Val : int} PRIMARY KEY Id
+
+fun check id =
+ res <- oneOrNoRows (SELECT tab.Val FROM tab WHERE tab.Id = {[id]});
+ return <xml><body>
+ Value at {[id]} is
+ {case res of
+ None => <xml>unknown</xml>
+ | Some row => <xml>{[row.Tab.Val]}</xml>}.
+ </body></xml>
+
+fun flush id =
+ dml (UPDATE tab SET Val = Val + 1 WHERE Id = {[id]});
+ return <xml><body>
+ Incremented value at {[id]} (if it exists).
+ </body></xml>
diff --git a/caching-tests/bench.urp b/caching-tests/bench.urp
new file mode 100644
index 00000000..2155221e
--- /dev/null
+++ b/caching-tests/bench.urp
@@ -0,0 +1,6 @@
+database host=localhost
+sql bench.sql
+safeGet Bench/flush
+minHeap 4096
+
+bench
diff --git a/caching-tests/bench.urs b/caching-tests/bench.urs
new file mode 100644
index 00000000..5f3d2ee8
--- /dev/null
+++ b/caching-tests/bench.urs
@@ -0,0 +1,2 @@
+val check : int -> transaction page
+val flush : int -> transaction page
diff --git a/caching-tests/some-results.txt b/caching-tests/some-results.txt
new file mode 100644
index 00000000..2b314a50
--- /dev/null
+++ b/caching-tests/some-results.txt
@@ -0,0 +1,198 @@
+~/Dev/UrWeb/caching-tests
+$ urweb bench
+~/Dev/UrWeb/caching-tests
+$ ./bench.exe -q &
+[1] 24466
+~/Dev/UrWeb/caching-tests
+$ Initializing
+Initializing
+Initializing
+wrk -d 2 http://localhost:8080/Bench/ -s bench.lua -- 0.5
+Running 2s test @ http://localhost:8080/Bench/
+ 2 threads and 10 connections
+ Thread Stats Avg Stdev Max +/- Stdev
+ Latency 1.41ms 320.22us 2.86ms 68.44%
+ Req/Sec 3.32k 696.42 4.25k 78.05%
+ 13526 requests in 2.10s, 4.81MB read
+Requests/sec: 6439.96
+Transfer/sec: 2.29MB
+~/Dev/UrWeb/caching-tests
+$ wrk http://localhost:8080/Bench/ -s bench.lua -- 0.1 100000
+Running 10s test @ http://localhost:8080/Bench/
+ 2 threads and 10 connections
+ Thread Stats Avg Stdev Max +/- Stdev
+ Latency 1.08ms 250.98us 2.64ms 66.33%
+ Req/Sec 4.34k 704.72 6.84k 81.09%
+ 86850 requests in 10.10s, 30.70MB read
+Requests/sec: 8598.75
+Transfer/sec: 3.04MB
+~/Dev/UrWeb/caching-tests
+$ fg
+./bench.exe -q
+ C-c C-cExiting....
+~/Dev/UrWeb/caching-tests
+$ ./bench.exe -q -t 2 &
+[1] 24514
+~/Dev/UrWeb/caching-tests
+$ Initializing
+Initializing
+Initializing
+Initializing
+
+~/Dev/UrWeb/caching-tests
+$ wrk http://localhost:8080/Bench/ -s bench.lua -- 0.1 100000
+Running 10s test @ http://localhost:8080/Bench/
+ 2 threads and 10 connections
+ Thread Stats Avg Stdev Max +/- Stdev
+ Latency 370.59us 90.83us 2.14ms 71.69%
+ Req/Sec 11.34k 1.19k 16.34k 72.64%
+ 226734 requests in 10.10s, 80.15MB read
+Requests/sec: 22449.54
+Transfer/sec: 7.94MB
+~/Dev/UrWeb/caching-tests
+$ fg
+./bench.exe -q -t 2
+ C-c C-cExiting....
+~/Dev/UrWeb/caching-tests
+$ urweb bench -sqlcache
+~/Dev/UrWeb/caching-tests
+$ ./bench.exe -q &
+[1] 24548
+~/Dev/UrWeb/caching-tests
+$ Initializing
+Initializing
+Initializing
+
+~/Dev/UrWeb/caching-tests
+$ wrk http://localhost:8080/Bench/ -s bench.lua -- 0.1 100000
+Running 10s test @ http://localhost:8080/Bench/
+ 2 threads and 10 connections
+ Thread Stats Avg Stdev Max +/- Stdev
+ Latency 0.98ms 322.48us 4.68ms 71.58%
+ Req/Sec 4.71k 706.11 7.06k 69.31%
+ 94654 requests in 10.10s, 33.46MB read
+Requests/sec: 9371.66
+Transfer/sec: 3.31MB
+~/Dev/UrWeb/caching-tests
+$ wrk http://localhost:8080/Bench/ -s bench.lua -- 0.1 100000
+Running 10s test @ http://localhost:8080/Bench/
+ 2 threads and 10 connections
+ Thread Stats Avg Stdev Max +/- Stdev
+ Latency 0.86ms 354.48us 7.31ms 71.15%
+ Req/Sec 5.21k 740.74 7.83k 68.81%
+ 104823 requests in 10.10s, 37.06MB read
+Requests/sec: 10378.81
+Transfer/sec: 3.67MB
+~/Dev/UrWeb/caching-tests
+$ wrk http://localhost:8080/Bench/ -s bench.lua -- 0.1 100000
+Running 10s test @ http://localhost:8080/Bench/
+ 2 threads and 10 connections
+ Thread Stats Avg Stdev Max +/- Stdev
+ Latency 703.16us 339.13us 2.82ms 68.28%
+ Req/Sec 6.10k 0.96k 10.43k 83.08%
+ 121961 requests in 10.10s, 43.12MB read
+Requests/sec: 12074.21
+Transfer/sec: 4.27MB
+~/Dev/UrWeb/caching-tests
+$ wrk http://localhost:8080/Bench/ -s bench.lua -- 0.1 100000
+Running 10s test @ http://localhost:8080/Bench/
+ 2 threads and 10 connections
+ Thread Stats Avg Stdev Max +/- Stdev
+ Latency 637.87us 348.05us 2.81ms 68.34%
+ Req/Sec 6.63k 1.12k 10.99k 73.76%
+ 133289 requests in 10.10s, 47.12MB read
+Requests/sec: 13197.03
+Transfer/sec: 4.67MB
+~/Dev/UrWeb/caching-tests
+$ fg
+./bench.exe -q
+ C-c C-cExiting....
+~/Dev/UrWeb/caching-tests
+$ ./bench.exe -q -t 2 &
+[1] 24616
+~/Dev/UrWeb/caching-tests
+$ Initializing
+Initializing
+Initializing
+Initializing
+
+~/Dev/UrWeb/caching-tests
+$ wrk http://localhost:8080/Bench/ -s bench.lua -- 0.1 100000
+Running 10s test @ http://localhost:8080/Bench/
+ 2 threads and 10 connections
+ Thread Stats Avg Stdev Max +/- Stdev
+ Latency 0.98ms 436.87us 8.57ms 73.73%
+ Req/Sec 4.69k 1.05k 7.41k 62.87%
+ 94186 requests in 10.10s, 33.30MB read
+Requests/sec: 9325.40
+Transfer/sec: 3.30MB
+~/Dev/UrWeb/caching-tests
+$ wrk http://localhost:8080/Bench/ -s bench.lua -- 0.1 100000
+Running 10s test @ http://localhost:8080/Bench/
+ 2 threads and 10 connections
+ Thread Stats Avg Stdev Max +/- Stdev
+ Latency 679.74us 357.72us 7.69ms 72.78%
+ Req/Sec 6.36k 1.23k 9.83k 70.65%
+ 127238 requests in 10.10s, 44.98MB read
+Requests/sec: 12598.06
+Transfer/sec: 4.45MB
+~/Dev/UrWeb/caching-tests
+$ wrk http://localhost:8080/Bench/ -s bench.lua -- 0.1 100000
+Running 10s test @ http://localhost:8080/Bench/
+ 2 threads and 10 connections
+ Thread Stats Avg Stdev Max +/- Stdev
+ Latency 598.29us 351.32us 3.00ms 69.43%
+ Req/Sec 6.86k 1.01k 11.33k 75.50%
+ 136554 requests in 10.00s, 48.28MB read
+Requests/sec: 13655.22
+Transfer/sec: 4.83MB
+~/Dev/UrWeb/caching-tests
+$ wrk http://localhost:8080/Bench/ -s bench.lua -- 0.1 100000
+Running 10s test @ http://localhost:8080/Bench/
+ 2 threads and 10 connections
+ Thread Stats Avg Stdev Max +/- Stdev
+ Latency 521.06us 331.23us 3.73ms 68.90%
+ Req/Sec 7.49k 1.20k 12.64k 85.07%
+ 149875 requests in 10.10s, 52.98MB read
+Requests/sec: 14839.52
+Transfer/sec: 5.25MB
+~/Dev/UrWeb/caching-tests
+$ wrk http://localhost:8080/Bench/ -s bench.lua -- 0.1 100000
+Running 10s test @ http://localhost:8080/Bench/
+ 2 threads and 10 connections
+ Thread Stats Avg Stdev Max +/- Stdev
+ Latency 504.89us 347.06us 5.62ms 69.33%
+ Req/Sec 7.64k 0.94k 11.95k 69.80%
+ 153398 requests in 10.10s, 54.23MB read
+Requests/sec: 15189.01
+Transfer/sec: 5.37MB
+~/Dev/UrWeb/caching-tests
+$ wrk http://localhost:8080/Bench/ -s bench.lua -- 0.1 100000
+Running 10s test @ http://localhost:8080/Bench/
+ 2 threads and 10 connections
+ Thread Stats Avg Stdev Max +/- Stdev
+ Latency 454.99us 315.26us 2.87ms 68.79%
+ Req/Sec 8.24k 1.20k 12.83k 80.10%
+ 164779 requests in 10.10s, 58.25MB read
+Requests/sec: 16314.84
+Transfer/sec: 5.77MB
+~/Dev/UrWeb/caching-tests
+$ wrk http://localhost:8080/Bench/ -s bench.lua -- 0.1 100000
+Running 10s test @ http://localhost:8080/Bench/
+ 2 threads and 10 connections
+ Thread Stats Avg Stdev Max +/- Stdev
+ Latency 466.26us 326.63us 2.86ms 68.52%
+ Req/Sec 8.07k 1.04k 13.56k 74.13%
+ 161404 requests in 10.10s, 57.06MB read
+Requests/sec: 15981.72
+Transfer/sec: 5.65MB
+~/Dev/UrWeb/caching-tests
+$ wrk http://localhost:8080/Bench/ -s bench.lua -- 0.1 100000
+Running 10s test @ http://localhost:8080/Bench/
+ 2 threads and 10 connections
+ Thread Stats Avg Stdev Max +/- Stdev
+ Latency 458.75us 319.02us 3.11ms 68.07%
+ Req/Sec 8.15k 768.18 11.30k 69.80%
+ 163930 requests in 10.10s, 57.95MB read
+Requests/sec: 16231.27
+Transfer/sec: 5.74MB
diff --git a/caching-tests/test.ur b/caching-tests/test.ur
new file mode 100644
index 00000000..e0dab927
--- /dev/null
+++ b/caching-tests/test.ur
@@ -0,0 +1,111 @@
+table tab : {Id : int, Val : int, Foo : int} PRIMARY KEY Id
+
+fun cache id =
+ res <- oneOrNoRows (SELECT A.Val FROM (tab AS A JOIN tab AS B ON A.Id = B.Id)
+ WHERE B.Id = {[id]});
+ return <xml><body>
+ cache
+ {case res of
+ None => <xml>?</xml>
+ | Some row => <xml>{[row.A.Val]}</xml>}
+ </body></xml>
+
+(* fun cacheAlt id = *)
+(* res <- oneOrNoRows (SELECT Q.Id *)
+(* FROM (SELECT Tab.Id AS Id FROM tab WHERE Tab.Id = {[id]}) *)
+(* AS Q); *)
+(* return <xml><body> *)
+(* cacheAlt *)
+(* {case res of *)
+(* None => <xml>?</xml> *)
+(* | Some row => <xml>{[row.Q.Id]}</xml>} *)
+(* </body></xml> *)
+
+(* fun sillyRecursive {Id = id : int, FooBar = fooBar} = *)
+(* if fooBar <= 0 *)
+(* then 0 *)
+(* else 1 + sillyRecursive {Id = id, FooBar = fooBar - 1} *)
+
+(* fun cacheR (r : {Id : int, FooBar : int}) = *)
+(* res <- oneOrNoRows (SELECT tab.Val *)
+(* FROM tab *)
+(* WHERE tab.Id = {[r.Id]}); *)
+(* return <xml><body> *)
+(* cacheR {[r.FooBar]} *)
+(* {case res of *)
+(* None => <xml>?</xml> *)
+(* | Some row => <xml>{[row.Tab.Val]}</xml>} *)
+(* </body></xml> *)
+
+(* fun cache2 id v = *)
+(* res <- oneOrNoRows (SELECT tab.Val *)
+(* FROM tab *)
+(* WHERE tab.Id = {[id]} AND tab.Val = {[v]}); *)
+(* return <xml><body> *)
+(* Reading {[id]}. *)
+(* {case res of *)
+(* None => <xml>Nope, that's not it.</xml> *)
+(* | Some _ => <xml>Hooray! You guessed it!</xml>} *)
+(* </body></xml> *)
+
+(* fun cache2 id1 id2 = *)
+(* res1 <- oneOrNoRows (SELECT tab.Val *)
+(* FROM tab *)
+(* WHERE tab.Id = {[id1]}); *)
+(* res2 <- oneOrNoRows (SELECT tab.Val *)
+(* FROM tab *)
+(* WHERE tab.Id = {[id2]}); *)
+(* return <xml><body> *)
+(* Reading {[id1]} and {[id2]}. *)
+(* {case (res1, res2) of *)
+(* (Some _, Some _) => <xml>Both are there.</xml> *)
+(* | _ => <xml>One of them is missing.</xml>} *)
+(* </body></xml> *)
+
+fun flush id =
+ dml (UPDATE tab
+ SET Val = Val * (Id + 2) / Val - 3
+ WHERE Id = {[id]} OR Id = {[id - 1]} OR Id = {[id + 1]});
+ return <xml><body>
+ Changed {[id]}!
+ </body></xml>
+
+(* fun flash id = *)
+(* dml (UPDATE tab *)
+(* SET Foo = Val *)
+(* WHERE Id = {[id]} OR Id = {[id - 1]} OR Id = {[id + 1]}); *)
+(* return <xml><body> *)
+(* Maybe changed {[id]}? *)
+(* </body></xml> *)
+
+(* fun floosh id = *)
+(* dml (UPDATE tab *)
+(* SET Id = {[id + 1]} *)
+(* WHERE Id = {[id]} OR Id = {[id - 1]} OR Id = {[id + 1]}); *)
+(* return <xml><body> *)
+(* Shifted {[id]}! *)
+(* </body></xml> *)
+
+(* val flush17 = *)
+(* dml (UPDATE tab *)
+(* SET Val = Val * (Id + 2) / Val - 3 *)
+(* WHERE Id = 17); *)
+(* return <xml><body> *)
+(* Changed specifically 17! *)
+(* </body></xml> *)
+
+(* fun flush id = *)
+(* res <- oneOrNoRows (SELECT tab.Val *)
+(* FROM tab *)
+(* WHERE tab.Id = {[id]}); *)
+(* (case res of *)
+(* None => dml (INSERT INTO tab (Id, Val) *)
+(* VALUES ({[id]}, 0)) *)
+(* | Some row => dml (UPDATE tab *)
+(* SET Val = {[row.Tab.Val + 1]} *)
+(* WHERE Id = {[id]} OR Id = {[id + 1]})); *)
+(* return <xml><body> *)
+(* {case res of *)
+(* None => <xml>Initialized {[id]}!</xml> *)
+(* | Some row => <xml>Incremented {[id]}!</xml>} *)
+(* </body></xml> *)
diff --git a/caching-tests/test.urp b/caching-tests/test.urp
new file mode 100644
index 00000000..2cb9e711
--- /dev/null
+++ b/caching-tests/test.urp
@@ -0,0 +1,9 @@
+database host=localhost
+sql test.sql
+safeGet Test/flush
+# safeGet Test/flash
+# safeGet Test/floosh
+# safeGet Test/flush17
+minHeap 4096
+
+test
diff --git a/caching-tests/test.urs b/caching-tests/test.urs
new file mode 100644
index 00000000..d6e8dd2e
--- /dev/null
+++ b/caching-tests/test.urs
@@ -0,0 +1,8 @@
+val cache : int -> transaction page
+(* val cacheAlt : int -> transaction page *)
+(* val cacheR : {Id : int, FooBar : int} -> transaction page *)
+(* val cache2 : int -> int -> transaction page *)
+val flush : int -> transaction page
+(* val flash : int -> transaction page *)
+(* val floosh : int -> transaction page *)
+(* val flush17 : transaction page *)