litestack 0.4.1 → 0.4.2
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 +11 -0
- data/Gemfile +1 -7
- data/Gemfile.lock +92 -0
- data/README.md +120 -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 +10 -13
- data/bench/bench_cache_raw.rb +17 -22
- 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/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 +65 -75
- data/lib/active_support/cache/litecache.rb +38 -41
- data/lib/generators/litestack/install/install_generator.rb +3 -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 +79 -88
- data/lib/litestack/litecache.sql.yml +81 -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 +15 -15
- 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 +76 -86
- 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 +11 -15
- 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 +101 -6
@@ -0,0 +1,91 @@
|
|
1
|
+
require_relative "../lib/litestack/litemetric"
|
2
|
+
require_relative "../lib/litestack/litecache"
|
3
|
+
require_relative "../lib/litestack/litejob"
|
4
|
+
|
5
|
+
# standard:disable Style/GlobalVars
|
6
|
+
|
7
|
+
# initialize the litemetric to modify the date function
|
8
|
+
|
9
|
+
lm = Litemetric.instance
|
10
|
+
|
11
|
+
# initialize the queue to capture the options
|
12
|
+
Litejobqueue.new({
|
13
|
+
path: ":memory:",
|
14
|
+
retries: 2,
|
15
|
+
queues: [["normal", 1], ["urgent", 3], ["critical", 10]],
|
16
|
+
metrics: true,
|
17
|
+
log: nil
|
18
|
+
})
|
19
|
+
|
20
|
+
$time = Time.now.to_i #- 10800
|
21
|
+
$start_time = Time.now.to_i
|
22
|
+
|
23
|
+
class NormalJob
|
24
|
+
include Litejob
|
25
|
+
self.queue = "normal"
|
26
|
+
def perform(time)
|
27
|
+
$time = time #-= (rand * 100).to_i #10 seconds in the past
|
28
|
+
sleep 0.001
|
29
|
+
warn "performing some normal action"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
class SlowJob
|
34
|
+
include Litejob
|
35
|
+
self.queue = "normal"
|
36
|
+
|
37
|
+
def perform(time)
|
38
|
+
$time = time # (rand * 100).to_i #10 seconds in the past
|
39
|
+
sleep 0.1
|
40
|
+
warn "performing some slow action"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
class CriticalJob
|
45
|
+
include Litejob
|
46
|
+
self.queue = "critical"
|
47
|
+
|
48
|
+
def perform(time)
|
49
|
+
$time = time # (rand * 100).to_i #10 seconds in the past
|
50
|
+
sleep 0.01
|
51
|
+
warn "performing some critical action"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
class UrgentJob
|
56
|
+
include Litejob
|
57
|
+
self.queue = "urgent"
|
58
|
+
|
59
|
+
def perform(time)
|
60
|
+
$time = time # (rand * 100).to_i #10 seconds in the past
|
61
|
+
sleep 0.001
|
62
|
+
warn "performing some urgent action"
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
cache = Litecache.new({metrics: true})
|
67
|
+
|
68
|
+
def lm.current_time_slot
|
69
|
+
($time / 300) * 300
|
70
|
+
end
|
71
|
+
|
72
|
+
jobs = [SlowJob, UrgentJob, NormalJob, CriticalJob]
|
73
|
+
|
74
|
+
payload = "A" * 128
|
75
|
+
setter = proc { cache.set((rand * 1000).to_i.to_s, payload) }
|
76
|
+
getter = proc { cache.get((rand * 1300).to_i.to_s) }
|
77
|
+
cache_actions = [getter] * 5
|
78
|
+
cache_actions << setter
|
79
|
+
|
80
|
+
t = Time.now
|
81
|
+
5000.times do |i|
|
82
|
+
$time = $start_time - (rand * (3600 * 24 * 7 * 52)).to_i # up to 52 weeks in the past
|
83
|
+
jobs.sample.perform_async($time)
|
84
|
+
cache_actions.sample.call
|
85
|
+
puts "Finished #{i} events after #{Time.now - t} seconds for time_slot=#{lm.send(:current_time_slot)}" if i % 1000 == 0 && i > 0
|
86
|
+
end
|
87
|
+
puts "finished creating jobs, now summarizing"
|
88
|
+
lm.summarize
|
89
|
+
sleep
|
90
|
+
|
91
|
+
# standard:enable Style/GlobalVars
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require_relative "../lib/litestack/litecable"
|
2
|
+
|
3
|
+
# fork
|
4
|
+
|
5
|
+
lc = Litecable.new({logger: "STDOUT", metrics: true})
|
6
|
+
|
7
|
+
class Client
|
8
|
+
def initialize(channel)
|
9
|
+
@channel = channel
|
10
|
+
warn "[#{Process.pid}]:#{object_id} listening to #{@channel}"
|
11
|
+
end
|
12
|
+
|
13
|
+
def call(*args)
|
14
|
+
warn "[#{Process.pid}]:#{object_id} recieved #{args} from #{@channel}"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
channels = []
|
19
|
+
5.times { |i| channels << "channel##{i + 1}" }
|
20
|
+
|
21
|
+
20.times do
|
22
|
+
channel = channels.sample
|
23
|
+
lc.subscribe(channel, Client.new(channel))
|
24
|
+
end
|
25
|
+
|
26
|
+
100.times do |i|
|
27
|
+
lc.broadcast(channels.sample, "message##{i + 1}")
|
28
|
+
end
|
29
|
+
|
30
|
+
sleep
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require "minitest/autorun"
|
2
|
+
require "../lib/litestack/litejob"
|
3
|
+
|
4
|
+
# create a job queue (will be saved in a class variable)
|
5
|
+
Litejobqueue.new({retries: 3, retry_delay: 1, retry_delay_multiplier: 1, gc_sleep_interval: 1, dead_job_retention: 1, logger: "STDOUT"})
|
6
|
+
|
7
|
+
class MyJob
|
8
|
+
include Litejob
|
9
|
+
|
10
|
+
@@attempts = {}
|
11
|
+
|
12
|
+
def perform(name, time)
|
13
|
+
if @@attempts[name]
|
14
|
+
@@attempts[name] += 1
|
15
|
+
else
|
16
|
+
@@attempts[name] = 1
|
17
|
+
end
|
18
|
+
puts "Job: #{name}: attempt #{@@attempts[name]}"
|
19
|
+
raise "some error" if Time.now.to_i < time
|
20
|
+
puts "Job: #{name}: finished"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# this job will fail forever
|
25
|
+
MyJob.perform_async("FAILURE", Time.now.to_i + 10)
|
26
|
+
|
27
|
+
# this job will fail two times
|
28
|
+
MyJob.perform_async("EVENTUAL SUCCESS", Time.now.to_i + 2)
|
29
|
+
|
30
|
+
# this job will never fail
|
31
|
+
MyJob.perform_async("SUCCESS", Time.now.to_i)
|
32
|
+
|
33
|
+
sleep
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require "../lib/litestack"
|
2
|
+
|
3
|
+
# standard:disable Style/GlobalVars
|
4
|
+
|
5
|
+
class SomeAction
|
6
|
+
include Litemetric::Measurable
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
collect_metrics
|
10
|
+
end
|
11
|
+
|
12
|
+
def do1(param)
|
13
|
+
capture("something", param)
|
14
|
+
end
|
15
|
+
|
16
|
+
def do2(param)
|
17
|
+
capture("anotherthing", param)
|
18
|
+
end
|
19
|
+
|
20
|
+
def do3(param)
|
21
|
+
measure("differentthing", param) do
|
22
|
+
sleep 0.001
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def report
|
27
|
+
resolution = "minute"
|
28
|
+
puts topics = @litemetric.topics
|
29
|
+
topics.each do |topic|
|
30
|
+
puts topic
|
31
|
+
puts events = @litemetric.event_names(resolution, topic)
|
32
|
+
events.each do |event|
|
33
|
+
if event[0] == "differentthing"
|
34
|
+
puts keys = @litemetric.keys(resolution, topic, event[0])
|
35
|
+
keys.each do |key|
|
36
|
+
puts @litemetric.event_data(resolution, topic, event[0], key[0])
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
some_action = SomeAction.new
|
45
|
+
$time = Time.now.to_i - 10800
|
46
|
+
lm = Litemetric.instance
|
47
|
+
def lm.current_time_slot
|
48
|
+
($time / 300) * 300
|
49
|
+
end
|
50
|
+
t = Time.now
|
51
|
+
40000.times do |i|
|
52
|
+
$time += (rand * 100).to_i # extra 10 seconds
|
53
|
+
action = ["do1", "do2", "do3"].sample
|
54
|
+
some_action.send(action, "key_#{i}")
|
55
|
+
puts "Finished #{i} events after #{Time.now - t} seconds" if i % 1000 == 0 && i > 0
|
56
|
+
end
|
57
|
+
puts "finished capturing, now reporting"
|
58
|
+
# some_action.report
|
59
|
+
|
60
|
+
# standard:enable Style/GlobalVars
|
data/template.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
# Run `rails new my-app -m https://raw.githubusercontent.com/
|
1
|
+
# Run `rails new my-app -m https://raw.githubusercontent.com/oldmoe/litestack/master/template.rb`
|
2
2
|
# to create a new Rails app with Litestack pre-installed.
|
3
|
-
gem "litestack", github: "
|
3
|
+
gem "litestack", github: "litestack"
|
4
4
|
|
5
5
|
after_bundle do
|
6
6
|
generate "litestack:install"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: litestack
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mohamed Hassan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-11-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sqlite3
|
@@ -94,6 +94,90 @@ dependencies:
|
|
94
94
|
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rake
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: railties
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: minitest
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: rack
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - "~>"
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '3.0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - "~>"
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '3.0'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: simplecov
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - ">="
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0'
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - ">="
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0'
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: standard
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - ">="
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0'
|
174
|
+
type: :development
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - ">="
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '0'
|
97
181
|
description:
|
98
182
|
email:
|
99
183
|
- oldmoe@gmail.com
|
@@ -102,19 +186,26 @@ executables:
|
|
102
186
|
extensions: []
|
103
187
|
extra_rdoc_files: []
|
104
188
|
files:
|
189
|
+
- ".standard.yml"
|
105
190
|
- BENCHMARKS.md
|
106
191
|
- CHANGELOG.md
|
107
192
|
- Gemfile
|
193
|
+
- Gemfile.lock
|
108
194
|
- LICENSE.txt
|
109
195
|
- README.md
|
196
|
+
- ROADMAP.md
|
110
197
|
- Rakefile
|
111
198
|
- WHYLITESTACK.md
|
112
199
|
- assets/event_page.png
|
113
200
|
- assets/index_page.png
|
114
201
|
- assets/litecable_logo_teal.png
|
115
202
|
- assets/litecache_logo_teal.png
|
203
|
+
- assets/litecache_metrics.png
|
116
204
|
- assets/litedb_logo_teal.png
|
205
|
+
- assets/litedb_metrics.png
|
117
206
|
- assets/litejob_logo_teal.png
|
207
|
+
- assets/litemetric_logo_teal.png
|
208
|
+
- assets/litesearch_logo_teal.png
|
118
209
|
- assets/litestack_logo_teal.png
|
119
210
|
- assets/litestack_logo_teal_large.png
|
120
211
|
- assets/topic_page.png
|
@@ -176,15 +267,19 @@ files:
|
|
176
267
|
- lib/sequel/adapters/litedb.rb
|
177
268
|
- lib/sequel/adapters/shared/litedb.rb
|
178
269
|
- samples/ultrajob.yaml
|
270
|
+
- scripts/build_metrics.rb
|
271
|
+
- scripts/test_cable.rb
|
272
|
+
- scripts/test_job_retry.rb
|
273
|
+
- scripts/test_metrics.rb
|
179
274
|
- template.rb
|
180
|
-
homepage:
|
275
|
+
homepage: https://github.com/oldmoe/litestack
|
181
276
|
licenses:
|
182
277
|
- MIT
|
183
278
|
metadata:
|
184
279
|
allowed_push_host: https://rubygems.org
|
185
|
-
homepage_uri:
|
186
|
-
source_code_uri:
|
187
|
-
changelog_uri:
|
280
|
+
homepage_uri: https://github.com/oldmoe/litestack
|
281
|
+
source_code_uri: https://github.com/oldmoe/litestack
|
282
|
+
changelog_uri: https://github.com/oldmoe/litestack/CHANEGELOG.md
|
188
283
|
post_install_message:
|
189
284
|
rdoc_options: []
|
190
285
|
require_paths:
|