litestack 0.4.1 → 0.4.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.standard.yml +3 -0
- data/BENCHMARKS.md +23 -7
- data/CHANGELOG.md +35 -0
- data/Gemfile +1 -7
- data/README.md +124 -6
- data/ROADMAP.md +45 -0
- data/Rakefile +3 -1
- data/WHYLITESTACK.md +1 -1
- data/assets/litecache_metrics.png +0 -0
- data/assets/litedb_metrics.png +0 -0
- data/assets/litemetric_logo_teal.png +0 -0
- data/assets/litesearch_logo_teal.png +0 -0
- data/bench/bench.rb +17 -10
- data/bench/bench_cache_rails.rb +45 -14
- data/bench/bench_cache_raw.rb +44 -28
- data/bench/bench_jobs_rails.rb +18 -12
- data/bench/bench_jobs_raw.rb +17 -10
- data/bench/bench_queue.rb +4 -6
- data/bench/rails_job.rb +5 -7
- data/bench/skjob.rb +4 -4
- data/bench/uljob.rb +6 -6
- data/bin/liteboard +2 -1
- data/lib/action_cable/subscription_adapter/litecable.rb +5 -8
- data/lib/active_job/queue_adapters/litejob_adapter.rb +6 -8
- data/lib/active_record/connection_adapters/litedb_adapter.rb +72 -84
- data/lib/active_support/cache/litecache.rb +61 -41
- data/lib/generators/litestack/install/install_generator.rb +3 -3
- data/lib/generators/litestack/install/templates/cable.yml +0 -3
- data/lib/generators/litestack/install/templates/database.yml +7 -1
- data/lib/litestack/liteboard/liteboard.rb +269 -149
- data/lib/litestack/litecable.rb +41 -37
- data/lib/litestack/litecable.sql.yml +22 -11
- data/lib/litestack/litecache.rb +118 -93
- data/lib/litestack/litecache.sql.yml +83 -22
- data/lib/litestack/litecache.yml +1 -1
- data/lib/litestack/litedb.rb +35 -40
- data/lib/litestack/litejob.rb +30 -29
- data/lib/litestack/litejobqueue.rb +63 -65
- data/lib/litestack/litemetric.rb +80 -92
- data/lib/litestack/litemetric.sql.yml +244 -234
- data/lib/litestack/litemetric_collector.sql.yml +38 -41
- data/lib/litestack/litequeue.rb +39 -41
- data/lib/litestack/litequeue.sql.yml +39 -31
- data/lib/litestack/litescheduler.rb +24 -18
- data/lib/litestack/litesearch/index.rb +93 -63
- data/lib/litestack/litesearch/model.rb +66 -65
- data/lib/litestack/litesearch/schema.rb +53 -56
- data/lib/litestack/litesearch/schema_adapters/backed_adapter.rb +46 -50
- data/lib/litestack/litesearch/schema_adapters/basic_adapter.rb +44 -35
- data/lib/litestack/litesearch/schema_adapters/contentless_adapter.rb +3 -6
- data/lib/litestack/litesearch/schema_adapters/standalone_adapter.rb +7 -9
- data/lib/litestack/litesearch/schema_adapters.rb +4 -9
- data/lib/litestack/litesearch.rb +6 -9
- data/lib/litestack/litesupport.rb +78 -87
- data/lib/litestack/railtie.rb +1 -1
- data/lib/litestack/version.rb +2 -2
- data/lib/litestack.rb +6 -4
- data/lib/railties/rails/commands/dbconsole.rb +16 -20
- data/lib/sequel/adapters/litedb.rb +16 -21
- data/lib/sequel/adapters/shared/litedb.rb +168 -168
- data/scripts/build_metrics.rb +91 -0
- data/scripts/test_cable.rb +30 -0
- data/scripts/test_job_retry.rb +33 -0
- data/scripts/test_metrics.rb +60 -0
- data/template.rb +2 -2
- metadata +115 -7
@@ -3,23 +3,21 @@ require "active_support/core_ext/enumerable"
|
|
3
3
|
require "active_support/core_ext/array/extract_options"
|
4
4
|
require "active_support/core_ext/numeric/time"
|
5
5
|
require "active_support/cache"
|
6
|
-
require_relative
|
7
|
-
|
6
|
+
require_relative "../../litestack/litecache"
|
8
7
|
|
9
8
|
module ActiveSupport
|
10
9
|
module Cache
|
11
10
|
class Litecache < Store
|
11
|
+
#prepend Strategy::LocalCache
|
12
12
|
|
13
|
-
prepend Strategy::LocalCache
|
14
|
-
|
15
13
|
def self.supports_cache_versioning?
|
16
14
|
true
|
17
15
|
end
|
18
16
|
|
19
|
-
def initialize(options={})
|
17
|
+
def initialize(options = {})
|
20
18
|
super
|
21
19
|
@options[:return_full_record] = true
|
22
|
-
|
20
|
+
@cache = ::Litecache.new(@options) # reachout to the outer litecache class
|
23
21
|
end
|
24
22
|
|
25
23
|
def increment(key, amount = 1, options = nil)
|
@@ -27,39 +25,44 @@ module ActiveSupport
|
|
27
25
|
options = merged_options(options)
|
28
26
|
# todo: fix me
|
29
27
|
# this is currently a hack to avoid dealing with Rails cache encoding and decoding
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
28
|
+
# and it can result in a race condition as it stands
|
29
|
+
# @cache.transaction(:immediate) do
|
30
|
+
# currently transactions are not compatible with acquiring connections
|
31
|
+
# this needs fixing by storing the connection to the context once acquired
|
32
|
+
if (value = read(key, options))
|
33
|
+
value = value.to_i + amount
|
34
|
+
write(key, value, options)
|
35
|
+
else
|
36
|
+
write(key, amount, options)
|
37
|
+
end
|
38
|
+
# end
|
36
39
|
end
|
37
40
|
|
38
41
|
def decrement(key, amount = 1, options = nil)
|
39
42
|
options = merged_options(options)
|
40
|
-
increment(key, -1 * amount, options
|
43
|
+
increment(key, -1 * amount, options)
|
41
44
|
end
|
42
|
-
|
45
|
+
|
43
46
|
def prune(limit = nil, time = nil)
|
44
47
|
@cache.prune(limit)
|
45
48
|
end
|
46
49
|
|
47
50
|
def cleanup(limit = nil, time = nil)
|
48
51
|
@cache.prune(limit)
|
49
|
-
end
|
52
|
+
end
|
50
53
|
|
51
|
-
def clear(options
|
52
|
-
|
54
|
+
def clear(options=nil)
|
55
|
+
@cache.clear
|
53
56
|
end
|
54
|
-
|
57
|
+
|
55
58
|
def count
|
56
59
|
@cache.count
|
57
60
|
end
|
58
|
-
|
61
|
+
|
59
62
|
def size
|
60
63
|
@cache.size
|
61
64
|
end
|
62
|
-
|
65
|
+
|
63
66
|
def max_size
|
64
67
|
@cache.max_size
|
65
68
|
end
|
@@ -70,33 +73,50 @@ module ActiveSupport
|
|
70
73
|
|
71
74
|
private
|
72
75
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
76
|
+
# Read an entry from the cache.
|
77
|
+
def read_entry(key, **options)
|
78
|
+
deserialize_entry(@cache.get(key))
|
79
|
+
end
|
77
80
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
+
def read_multi_entries(names, **options)
|
82
|
+
results = {}
|
83
|
+
return results if names == []
|
84
|
+
rs = @cache.get_multi(*names.flatten)
|
85
|
+
rs.each_pair{|k, v| results[k] = deserialize_entry(v).value }
|
86
|
+
results
|
87
|
+
end
|
88
|
+
|
89
|
+
# Write an entry to the cache.
|
90
|
+
def write_entry(key, entry, **options)
|
91
|
+
write_serialized_entry(key, serialize_entry(entry, **options), **options)
|
92
|
+
end
|
93
|
+
|
94
|
+
def write_multi_entries(entries, **options)
|
95
|
+
return if entries.empty?
|
96
|
+
entries.each_pair {|k,v| entries[k] = serialize_entry(v, **options)}
|
97
|
+
expires_in = options[:expires_in].to_i
|
98
|
+
if options[:race_condition_ttl] && expires_in > 0 && !options[:raw]
|
99
|
+
expires_in += 5.minutes
|
81
100
|
end
|
101
|
+
@cache.set_multi(entries, expires_in)
|
102
|
+
end
|
82
103
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
end
|
88
|
-
if options[:unless_exist]
|
89
|
-
@cache.set_unless_exists(key, payload, expires_in)
|
90
|
-
else
|
91
|
-
@cache.set(key, payload, expires_in)
|
92
|
-
end
|
104
|
+
def write_serialized_entry(key, payload, **options)
|
105
|
+
expires_in = options[:expires_in].to_i
|
106
|
+
if options[:race_condition_ttl] && expires_in > 0 && !options[:raw]
|
107
|
+
expires_in += 5.minutes
|
93
108
|
end
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
109
|
+
if options[:unless_exist]
|
110
|
+
@cache.set_unless_exists(key, payload, expires_in)
|
111
|
+
else
|
112
|
+
@cache.set(key, payload, expires_in)
|
98
113
|
end
|
114
|
+
end
|
99
115
|
|
116
|
+
# Delete an entry from the cache.
|
117
|
+
def delete_entry(key, **options)
|
118
|
+
@cache.delete(key)
|
119
|
+
end
|
100
120
|
end
|
101
121
|
end
|
102
122
|
end
|
@@ -27,9 +27,9 @@ class Litestack::InstallGenerator < Rails::Generators::Base
|
|
27
27
|
def modify_gitignore
|
28
28
|
append_file ".gitignore", <<~TEXT
|
29
29
|
|
30
|
-
|
31
|
-
|
32
|
-
|
30
|
+
# Ignore default Litestack SQLite databases.
|
31
|
+
/db/**/*.sqlite3
|
32
|
+
/db/**/*.sqlite3-*
|
33
33
|
TEXT
|
34
34
|
end
|
35
35
|
end
|
@@ -7,6 +7,9 @@
|
|
7
7
|
# `Litesupport.root.join("data.sqlite3")` stores
|
8
8
|
# application data in the path `./db/#{Rails.env}/data.sqlite3`
|
9
9
|
#
|
10
|
+
# `Litesupport.root(env).join(path)` stores
|
11
|
+
# application data in the path `./db/#{env}/#{path}`
|
12
|
+
#
|
10
13
|
# idle_timeout should be set to zero, to avoid recycling sqlite connections
|
11
14
|
# and losing the page cache
|
12
15
|
#
|
@@ -14,16 +17,17 @@ default: &default
|
|
14
17
|
adapter: litedb
|
15
18
|
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
|
16
19
|
idle_timeout: 0
|
17
|
-
database: <%= Litesupport.root.join("data.sqlite3") %>
|
18
20
|
|
19
21
|
development:
|
20
22
|
<<: *default
|
23
|
+
database: <%= Litesupport.root("development").join("data.sqlite3") %>
|
21
24
|
|
22
25
|
# Warning: The database defined as "test" will be erased and
|
23
26
|
# re-generated from your development database when you run "rake".
|
24
27
|
# Do not set this db to the same as development or production.
|
25
28
|
test:
|
26
29
|
<<: *default
|
30
|
+
database: <%= Litesupport.root("test").join("data.sqlite3") %>
|
27
31
|
|
28
32
|
# Warning: Make sure your production database path is on a persistent
|
29
33
|
# volume, otherwise your application data could be deleted between deploys.
|
@@ -32,3 +36,5 @@ test:
|
|
32
36
|
# `LITESTACK_DATA_PATH` environment variable.
|
33
37
|
production:
|
34
38
|
<<: *default
|
39
|
+
database: <%= Litesupport.root("production").join("data.sqlite3") %>
|
40
|
+
|