warm-blanket 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.adoc +177 -0
- data/lib/warm-blanket.rb +8 -0
- data/lib/warm_blanket/version.rb +1 -1
- data/warm-blanket.gemspec +18 -8
- metadata +33 -28
- data/.gitignore +0 -13
- data/.rspec +0 -2
- data/.ruby-version +0 -1
- data/Gemfile +0 -4
- data/README.md +0 -139
- data/Rakefile +0 -6
- data/bin/console +0 -7
- data/bin/pry +0 -17
- data/bin/rspec +0 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c34c8f98ad1c6798dfab5b361dbc24fa3e8468bc00eef78eeb4b51e32ef08335
|
4
|
+
data.tar.gz: 23b4584b0cd46976242d2c2f2561f33649a6d60bba145fcc3464b7eb64f03853
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 87ed21e179d729c8a3b62517e44cd03852de0d72fad14859b70c927aff51be254bd4930c6d100126d0da330a10acc0f74b560e916489781275454dd54a9f6951
|
7
|
+
data.tar.gz: f9ad77c550d317af8035ad9a83d362fdcce7089e5f7be7405b5200d9b61deac6b944e73b0fe3c3664e96b90e88696692a6e3e9254e20a196153f0105fdcde5b6
|
data/README.adoc
ADDED
@@ -0,0 +1,177 @@
|
|
1
|
+
= WarmBlanket
|
2
|
+
:toc:
|
3
|
+
:toc-placement: macro
|
4
|
+
:toclevels: 3
|
5
|
+
:toc-title:
|
6
|
+
|
7
|
+
WarmBlanket is a Ruby gem for warming up web services on boot. Its main
|
8
|
+
target are JRuby-powered web services or even TruffleRuby based services,
|
9
|
+
although it is not specific to those runtimes in any way.
|
10
|
+
|
11
|
+
toc::[]
|
12
|
+
|
13
|
+
== How the magic happens
|
14
|
+
|
15
|
+
=== Why do we need to warm up web services?
|
16
|
+
|
17
|
+
When the Java Virtual Machine (JVM) starts, it starts by interpreting
|
18
|
+
Java bytecode. As it starts to detect code that runs often, it
|
19
|
+
just-in-time compiles that code into native machine code, improving
|
20
|
+
performance.
|
21
|
+
|
22
|
+
This is a known challenge for most JVMs, and the same applies to JRuby
|
23
|
+
applications, which also run on the JVM.
|
24
|
+
|
25
|
+
A widely-documented solution to this problem is to perform a warm-up
|
26
|
+
step when starting a service:
|
27
|
+
|
28
|
+
* https://landing.google.com/sre/book/chapters/load-balancing-datacenter.html#unpredictable-performance-factors-JMs7i7trCj
|
29
|
+
* http://www.brendangregg.com/blog/2016-09-28/java-warmup.html
|
30
|
+
* https://devcenter.heroku.com/articles/warming-up-a-java-process
|
31
|
+
|
32
|
+
=== What does WarmBlanket do?
|
33
|
+
|
34
|
+
WarmBlanket warms services by performing repeated web requests for a
|
35
|
+
configurable number of seconds. After that time, it closes shop and
|
36
|
+
you'll never hear about it until the next service restart or deploy.
|
37
|
+
|
38
|
+
=== How does WarmBlanket work?
|
39
|
+
|
40
|
+
WarmBlanket spawns a configurable number of background threads that run
|
41
|
+
inside the service process, and then uses an http client to perform
|
42
|
+
local requests to the web server, simulating load.
|
43
|
+
|
44
|
+
As it simulates requests, the JVM is warmed up and thus when real
|
45
|
+
requests come in, no performance degradation is observed.
|
46
|
+
|
47
|
+
=== Limitations/caveats
|
48
|
+
|
49
|
+
We strongly recommend that any services using WarmBlanket, if deployed
|
50
|
+
on Heroku, use https://devcenter.heroku.com/articles/preboot[Preboot].
|
51
|
+
Preboot allows a service instance to be warmed up for 3 minutes before
|
52
|
+
Heroku starts sending live traffic its way, which is preferable to doing
|
53
|
+
it live.
|
54
|
+
|
55
|
+
On kubernetes, you can make use of
|
56
|
+
https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-probes/[readiness
|
57
|
+
probes] to delay service startup while warm-blanket is working.
|
58
|
+
|
59
|
+
=== Important for TruffleRuby as well!
|
60
|
+
|
61
|
+
TruffleRuby can be run either on a standalone mode, or with a JVM.
|
62
|
+
In either configuration, like JRuby, it needs to warm up until it
|
63
|
+
gets to peak performance, so WarmBlanket is great there too!
|
64
|
+
|
65
|
+
== How can I make use of it?
|
66
|
+
|
67
|
+
To make use of WarmBlanket, you'll need to follow the next sections,
|
68
|
+
which will guide you through installing, configuring and enabling the
|
69
|
+
gem.
|
70
|
+
|
71
|
+
=== {counter:using}. Installation
|
72
|
+
|
73
|
+
To install using Bundler, add the following to your `Gemfile`:
|
74
|
+
|
75
|
+
[source,ruby]
|
76
|
+
----
|
77
|
+
gem 'warm-blanket', '~> 1.0'
|
78
|
+
----
|
79
|
+
|
80
|
+
WarmBlanket uses http://semver.org/[semantic versioning].
|
81
|
+
|
82
|
+
=== {counter:using}. Configuration settings
|
83
|
+
|
84
|
+
This gem can be configured via the following environment variables:
|
85
|
+
|
86
|
+
* `PORT`: Local webserver port (automatically set on Heroku)
|
87
|
+
* `WARMBLANKET_ENABLED`: Enable warm blanket (defaults to `false`;
|
88
|
+
`true` or `1` enables)
|
89
|
+
* `WARMBLANKET_WARMUP_THREADS`: Number of warm up threads to use
|
90
|
+
(defaults to `2`)
|
91
|
+
* `WARMBLANKET_WARMUP_TIME_SECONDS`: Time, in seconds, during which to
|
92
|
+
warm up the service (defaults to `150`)
|
93
|
+
|
94
|
+
==== Configuring endpoints to be called
|
95
|
+
|
96
|
+
Configure endpoints to be called as follows (on a
|
97
|
+
`config/warm_blanket.rb`:
|
98
|
+
|
99
|
+
[source,ruby]
|
100
|
+
._Example GET requests_
|
101
|
+
----
|
102
|
+
require 'warm-blanket'
|
103
|
+
|
104
|
+
WarmBlanket.configure do |config|
|
105
|
+
common_headers = {
|
106
|
+
'X-Api-Key': ENV.fetch('API_KEYS').split(',').first,
|
107
|
+
}
|
108
|
+
|
109
|
+
config.endpoints = [
|
110
|
+
{get: '/foo', headers: common_headers},
|
111
|
+
{get: '/', headers: common_headers},
|
112
|
+
]
|
113
|
+
end
|
114
|
+
----
|
115
|
+
|
116
|
+
Other HTTP verbs are supported (and you can pass in a `body` key if
|
117
|
+
needed), but be careful about side effects from such verbs. And if
|
118
|
+
there's no side effect from a `POST` or `PUT`, do consider if it
|
119
|
+
shouldn't be a `GET` instead ;)
|
120
|
+
|
121
|
+
[source,ruby]
|
122
|
+
._Example POST request with body_
|
123
|
+
----
|
124
|
+
# Notice that you need to both:
|
125
|
+
# * set the Content-Type manually (if needed)
|
126
|
+
# * JSON-encode the body (if needed)
|
127
|
+
|
128
|
+
WarmBlanket.configure do |config|
|
129
|
+
common_headers = {
|
130
|
+
'X-Api-Key': ENV.fetch('API_KEY').split(',').first,
|
131
|
+
'Content-Type': 'application/json',
|
132
|
+
}
|
133
|
+
|
134
|
+
post_body = MultiJson.dump(
|
135
|
+
account_id: 'dummy_account',
|
136
|
+
user_id: 'dummy_user_id',
|
137
|
+
)
|
138
|
+
|
139
|
+
config.endpoints = [
|
140
|
+
{post: '/some_endoint', headers: common_headers, body: post_body},
|
141
|
+
]
|
142
|
+
end
|
143
|
+
----
|
144
|
+
|
145
|
+
=== {counter:using}. Trigger warmup
|
146
|
+
|
147
|
+
Add the following to the end of your `config.ru` file:
|
148
|
+
|
149
|
+
[source,ruby]
|
150
|
+
----
|
151
|
+
WarmBlanket.trigger_warmup
|
152
|
+
----
|
153
|
+
|
154
|
+
== Development
|
155
|
+
|
156
|
+
After checking out the repo, run `bundle install` to install
|
157
|
+
dependencies. Then, run `rake spec` to run the tests. You can also run
|
158
|
+
`bin/console` for an interactive prompt that will allow you to
|
159
|
+
experiment.
|
160
|
+
|
161
|
+
To install this gem onto your local machine, run
|
162
|
+
`bundle exec rake install`. To release a new version, update the version
|
163
|
+
number in `version.rb`, and then run `bundle exec rake release`, which
|
164
|
+
will create a git tag for the version, push git commits and tags, and
|
165
|
+
push the `.gem` file to https://rubygems.org[rubygems.org].
|
166
|
+
|
167
|
+
== Contributors
|
168
|
+
|
169
|
+
Open-sourced with ❤️ by Talkdesk!
|
170
|
+
|
171
|
+
Maintained by https://github.com/ivoanjo/[Ivo Anjo] and the
|
172
|
+
http://github.com/Talkdesk/[Talkdesk Engineering] team.
|
173
|
+
|
174
|
+
== Contributing
|
175
|
+
|
176
|
+
Bug reports and pull requests are welcome on GitHub at
|
177
|
+
https://github.com/Talkdesk/warm-blanket.
|
data/lib/warm-blanket.rb
CHANGED
@@ -25,6 +25,14 @@ require 'logging'
|
|
25
25
|
module WarmBlanket
|
26
26
|
extend Dry::Configurable
|
27
27
|
|
28
|
+
# Compatibility with Ruby 2.3 / JRuby 9.1: Modern versions of dry-configurable emit deprecation warnings for the way
|
29
|
+
# we're passing in defaults, but older versions of the gem don't work on the older Ruby/JRuby versions.
|
30
|
+
# See https://github.com/dry-rb/dry-configurable/blob/main/CHANGELOG.md#0130-2021-09-12 .
|
31
|
+
# This can be dropped when we drop support for Ruby 2.3/JRuby 9.1
|
32
|
+
if Dry::Configurable.respond_to?(:warn_on_setting_positional_default)
|
33
|
+
Dry::Configurable.warn_on_setting_positional_default(false)
|
34
|
+
end
|
35
|
+
|
28
36
|
# Endpoints to be called for warmup, see README
|
29
37
|
setting :endpoints, [], reader: true
|
30
38
|
|
data/lib/warm_blanket/version.rb
CHANGED
data/warm-blanket.gemspec
CHANGED
@@ -14,19 +14,29 @@ Gem::Specification.new do |spec|
|
|
14
14
|
spec.description = 'Ruby gem for warming up web services on boot'
|
15
15
|
spec.homepage = 'https://github.com/Talkdesk/warm-blanket'
|
16
16
|
|
17
|
-
spec.files =
|
17
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
18
|
+
`git ls-files -z`.split("\x0")
|
19
|
+
.reject { |f| f.match(%r{\A(?:test|spec|features|[.]github|examples)/}) }
|
20
|
+
.reject { |f|
|
21
|
+
["gems.rb", ".ruby-version", ".gitignore", ".rspec",
|
22
|
+
"Rakefile", "bin/pry", "bin/rspec", "bin/console"].include?(f)
|
23
|
+
}
|
24
|
+
end
|
18
25
|
spec.require_paths = ['lib']
|
19
26
|
|
20
|
-
spec.
|
21
|
-
|
22
|
-
spec.add_development_dependency '
|
27
|
+
spec.required_ruby_version = ">= 2.3.0"
|
28
|
+
|
29
|
+
spec.add_development_dependency 'bundler', '~> 2.3'
|
30
|
+
spec.add_development_dependency 'rspec', '~> 3.11'
|
31
|
+
spec.add_development_dependency 'webmock', '~> 3.18'
|
23
32
|
spec.add_development_dependency 'timecop', '~> 0.9'
|
24
|
-
spec.add_development_dependency 'rake', '~>
|
33
|
+
spec.add_development_dependency 'rake', '~> 13.0'
|
25
34
|
spec.add_development_dependency 'pry'
|
26
35
|
spec.add_development_dependency 'pry-byebug' unless RUBY_PLATFORM == 'java'
|
27
36
|
spec.add_development_dependency 'pry-debugger-jruby' if RUBY_PLATFORM == 'java'
|
37
|
+
spec.add_development_dependency 'webrick', '~> 1.7.0'
|
28
38
|
|
29
|
-
spec.add_dependency 'faraday', '~> 0.9
|
30
|
-
spec.add_dependency 'dry-configurable', '~> 0.
|
31
|
-
spec.add_dependency 'logging', '~> 2.
|
39
|
+
spec.add_dependency 'faraday', '~> 1.0' # Kept at 1.0 because it still supports Ruby 2.3 (JRuby 9.1)
|
40
|
+
spec.add_dependency 'dry-configurable', '~> 0.8' # Kept at 0.8 because it still supports Ruby 2.3 (JRuby 9.1)
|
41
|
+
spec.add_dependency 'logging', '~> 2.3'
|
32
42
|
end
|
metadata
CHANGED
@@ -1,21 +1,21 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: warm-blanket
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Talkdesk Engineering
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-10-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|
15
15
|
requirements:
|
16
16
|
- - "~>"
|
17
17
|
- !ruby/object:Gem::Version
|
18
|
-
version: '
|
18
|
+
version: '2.3'
|
19
19
|
name: bundler
|
20
20
|
prerelease: false
|
21
21
|
type: :development
|
@@ -23,13 +23,13 @@ dependencies:
|
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '2.3'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
requirement: !ruby/object:Gem::Requirement
|
29
29
|
requirements:
|
30
30
|
- - "~>"
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: '3.
|
32
|
+
version: '3.11'
|
33
33
|
name: rspec
|
34
34
|
prerelease: false
|
35
35
|
type: :development
|
@@ -37,13 +37,13 @@ dependencies:
|
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '3.
|
40
|
+
version: '3.11'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
requirement: !ruby/object:Gem::Requirement
|
43
43
|
requirements:
|
44
44
|
- - "~>"
|
45
45
|
- !ruby/object:Gem::Version
|
46
|
-
version: '3.
|
46
|
+
version: '3.18'
|
47
47
|
name: webmock
|
48
48
|
prerelease: false
|
49
49
|
type: :development
|
@@ -51,7 +51,7 @@ dependencies:
|
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '3.
|
54
|
+
version: '3.18'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
requirement: !ruby/object:Gem::Requirement
|
57
57
|
requirements:
|
@@ -71,7 +71,7 @@ dependencies:
|
|
71
71
|
requirements:
|
72
72
|
- - "~>"
|
73
73
|
- !ruby/object:Gem::Version
|
74
|
-
version: '
|
74
|
+
version: '13.0'
|
75
75
|
name: rake
|
76
76
|
prerelease: false
|
77
77
|
type: :development
|
@@ -79,7 +79,7 @@ dependencies:
|
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '
|
82
|
+
version: '13.0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
requirement: !ruby/object:Gem::Requirement
|
85
85
|
requirements:
|
@@ -113,7 +113,21 @@ dependencies:
|
|
113
113
|
requirements:
|
114
114
|
- - "~>"
|
115
115
|
- !ruby/object:Gem::Version
|
116
|
-
version:
|
116
|
+
version: 1.7.0
|
117
|
+
name: webrick
|
118
|
+
prerelease: false
|
119
|
+
type: :development
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 1.7.0
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
requirement: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - "~>"
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '1.0'
|
117
131
|
name: faraday
|
118
132
|
prerelease: false
|
119
133
|
type: :runtime
|
@@ -121,13 +135,13 @@ dependencies:
|
|
121
135
|
requirements:
|
122
136
|
- - "~>"
|
123
137
|
- !ruby/object:Gem::Version
|
124
|
-
version: '0
|
138
|
+
version: '1.0'
|
125
139
|
- !ruby/object:Gem::Dependency
|
126
140
|
requirement: !ruby/object:Gem::Requirement
|
127
141
|
requirements:
|
128
142
|
- - "~>"
|
129
143
|
- !ruby/object:Gem::Version
|
130
|
-
version: '0.
|
144
|
+
version: '0.8'
|
131
145
|
name: dry-configurable
|
132
146
|
prerelease: false
|
133
147
|
type: :runtime
|
@@ -135,13 +149,13 @@ dependencies:
|
|
135
149
|
requirements:
|
136
150
|
- - "~>"
|
137
151
|
- !ruby/object:Gem::Version
|
138
|
-
version: '0.
|
152
|
+
version: '0.8'
|
139
153
|
- !ruby/object:Gem::Dependency
|
140
154
|
requirement: !ruby/object:Gem::Requirement
|
141
155
|
requirements:
|
142
156
|
- - "~>"
|
143
157
|
- !ruby/object:Gem::Version
|
144
|
-
version: '2.
|
158
|
+
version: '2.3'
|
145
159
|
name: logging
|
146
160
|
prerelease: false
|
147
161
|
type: :runtime
|
@@ -149,7 +163,7 @@ dependencies:
|
|
149
163
|
requirements:
|
150
164
|
- - "~>"
|
151
165
|
- !ruby/object:Gem::Version
|
152
|
-
version: '2.
|
166
|
+
version: '2.3'
|
153
167
|
description: Ruby gem for warming up web services on boot
|
154
168
|
email:
|
155
169
|
- tech@talkdesk.com
|
@@ -157,17 +171,9 @@ executables: []
|
|
157
171
|
extensions: []
|
158
172
|
extra_rdoc_files: []
|
159
173
|
files:
|
160
|
-
- ".gitignore"
|
161
|
-
- ".rspec"
|
162
|
-
- ".ruby-version"
|
163
174
|
- COPYING
|
164
175
|
- COPYING.LESSER
|
165
|
-
-
|
166
|
-
- README.md
|
167
|
-
- Rakefile
|
168
|
-
- bin/console
|
169
|
-
- bin/pry
|
170
|
-
- bin/rspec
|
176
|
+
- README.adoc
|
171
177
|
- lib/warm-blanket.rb
|
172
178
|
- lib/warm_blanket/orchestrator.rb
|
173
179
|
- lib/warm_blanket/requester.rb
|
@@ -186,15 +192,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
186
192
|
requirements:
|
187
193
|
- - ">="
|
188
194
|
- !ruby/object:Gem::Version
|
189
|
-
version:
|
195
|
+
version: 2.3.0
|
190
196
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
191
197
|
requirements:
|
192
198
|
- - ">="
|
193
199
|
- !ruby/object:Gem::Version
|
194
200
|
version: '0'
|
195
201
|
requirements: []
|
196
|
-
|
197
|
-
rubygems_version: 2.6.11
|
202
|
+
rubygems_version: 3.2.29
|
198
203
|
signing_key:
|
199
204
|
specification_version: 4
|
200
205
|
summary: Ruby gem for warming up web services on boot
|
data/.gitignore
DELETED
data/.rspec
DELETED
data/.ruby-version
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
jruby-9.1.12.0
|
data/Gemfile
DELETED
data/README.md
DELETED
@@ -1,139 +0,0 @@
|
|
1
|
-
# WarmBlanket
|
2
|
-
|
3
|
-
WarmBlanket is a Ruby gem for warming up web services on boot. Its main target are JRuby web services, although it is not JRuby-specific in any way.
|
4
|
-
|
5
|
-
* [WarmBlanket](#warmblanket)
|
6
|
-
* [How the magic happens](#how-the-magic-happens)
|
7
|
-
* [Why do we need to warm up web services?](#why-do-we-need-to-warm-up-web-services)
|
8
|
-
* [What does WarmBlanket do?](#what-does-warmblanket-do)
|
9
|
-
* [How does WarmBlanket work?](#how-does-warmblanket-work)
|
10
|
-
* [Limitations/caveats](#limitationscaveats)
|
11
|
-
* [How can I make use of it?](#how-can-i-make-use-of-it)
|
12
|
-
* [1. Installation](#1-installation)
|
13
|
-
* [2. Configuration settings](#2-configuration-settings)
|
14
|
-
* [Configuring endpoints to be called](#configuring-endpoints-to-be-called)
|
15
|
-
* [3. Trigger warmup](#3-trigger-warmup)
|
16
|
-
* [Development](#development)
|
17
|
-
* [Contributing](#contributing)
|
18
|
-
|
19
|
-
<sub><sup>ToC created with [gh-md-toc](https://github.com/ekalinin/github-markdown-toc)</sup></sub>
|
20
|
-
|
21
|
-
# How the magic happens
|
22
|
-
|
23
|
-
## Why do we need to warm up web services?
|
24
|
-
|
25
|
-
When the Java Virtual Machine (JVM) starts, it starts by interpreting Java bytecode. As it starts to detect code that runs often, it just-in-time compiles that code into native machine code, improving performance.
|
26
|
-
|
27
|
-
This is a known challenge for most JVMs, and the same applies to JRuby applications, which also run on the JVM.
|
28
|
-
|
29
|
-
A widely-documented solution to this problem is to perform a warm-up step when starting a service:
|
30
|
-
|
31
|
-
* <https://landing.google.com/sre/book/chapters/load-balancing-datacenter.html#unpredictable-performance-factors-JMs7i7trCj>
|
32
|
-
* <http://www.brendangregg.com/blog/2016-09-28/java-warmup.html>
|
33
|
-
* <https://devcenter.heroku.com/articles/warming-up-a-java-process>
|
34
|
-
|
35
|
-
## What does WarmBlanket do?
|
36
|
-
|
37
|
-
WarmBlanket warms services by performing repeated web requests for a configurable number of seconds. After that time, it closes shop and you'll never hear about it until the next service restart or deploy.
|
38
|
-
|
39
|
-
## How does WarmBlanket work?
|
40
|
-
|
41
|
-
WarmBlanket spawns a configurable number of background threads that run inside the service process, and then uses an http client to perform local requests to the web server, simulating load.
|
42
|
-
|
43
|
-
As it simulates requests, the JVM is warmed up and thus when real requests come in, no performance degradation is observed.
|
44
|
-
|
45
|
-
## Limitations/caveats
|
46
|
-
|
47
|
-
We strongly recommend that any services using WarmBlanket, if deployed on Heroku, use [Preboot](https://devcenter.heroku.com/articles/preboot). Preboot allows a service instance to be warmed up for 3 minutes before Heroku starts sending live traffic its way, which is preferable to doing it live.
|
48
|
-
|
49
|
-
# How can I make use of it?
|
50
|
-
|
51
|
-
To make use of WarmBlanket, you'll need to follow the next sections, which will guide you through installing, configuring and enabling the gem.
|
52
|
-
|
53
|
-
## 1. Installation
|
54
|
-
|
55
|
-
To install using Bundler, add the following to your `Gemfile`:
|
56
|
-
|
57
|
-
```ruby
|
58
|
-
gem 'warm-blanket', '~> 1.0'
|
59
|
-
```
|
60
|
-
|
61
|
-
WarmBlanket uses [semantic versioning](http://semver.org/).
|
62
|
-
|
63
|
-
## 2. Configuration settings
|
64
|
-
|
65
|
-
This gem can be configured via the following environment variables:
|
66
|
-
|
67
|
-
* `PORT`: Local webserver port (automatically set on Heroku)
|
68
|
-
* `WARMBLANKET_ENABLED`: Enable warm blanket (defaults to `false`; `true` or `1` enables)
|
69
|
-
* `WARMBLANKET_WARMUP_THREADS`: Number of warm up threads to use (defaults to `2`)
|
70
|
-
* `WARMBLANKET_WARMUP_TIME_SECONDS`: Time, in seconds, during which to warm up the service (defaults to `150`)
|
71
|
-
|
72
|
-
### Configuring endpoints to be called
|
73
|
-
|
74
|
-
Configure endpoints to be called as follows (on a `config/warm_blanket.rb`:
|
75
|
-
|
76
|
-
```ruby
|
77
|
-
require 'warm-blanket'
|
78
|
-
|
79
|
-
WarmBlanket.configure do |config|
|
80
|
-
common_headers = {
|
81
|
-
'X-Api-Key': ENV.fetch('API_KEYS').split(',').first,
|
82
|
-
}
|
83
|
-
|
84
|
-
config.endpoints = [
|
85
|
-
{get: '/foo', headers: common_headers},
|
86
|
-
{get: '/', headers: common_headers},
|
87
|
-
]
|
88
|
-
end
|
89
|
-
```
|
90
|
-
|
91
|
-
Other HTTP verbs are supported (and you can pass in a `body` key if needed), but be careful about side effects from such verbs. And if there's no side effect from a `POST` or `PUT`, do consider if it shouldn't be a `GET` instead ;)
|
92
|
-
|
93
|
-
```ruby
|
94
|
-
# Example POST request with body
|
95
|
-
#
|
96
|
-
# Notice that you need to both:
|
97
|
-
# * set the Content-Type manually (if needed)
|
98
|
-
# * JSON-encode the body (if needed)
|
99
|
-
|
100
|
-
WarmBlanket.configure do |config|
|
101
|
-
common_headers = {
|
102
|
-
'X-Api-Key': ENV.fetch('API_KEY').split(',').first,
|
103
|
-
'Content-Type': 'application/json',
|
104
|
-
}
|
105
|
-
|
106
|
-
post_body = MultiJson.dump(
|
107
|
-
account_id: 'dummy_account',
|
108
|
-
user_id: 'dummy_user_id',
|
109
|
-
)
|
110
|
-
|
111
|
-
config.endpoints = [
|
112
|
-
{post: '/some_endoint', headers: common_headers, body: post_body},
|
113
|
-
]
|
114
|
-
end
|
115
|
-
```
|
116
|
-
|
117
|
-
## 3. Trigger warmup
|
118
|
-
|
119
|
-
Add the following to the end of your `config.ru` file:
|
120
|
-
|
121
|
-
```ruby
|
122
|
-
WarmBlanket.trigger_warmup
|
123
|
-
```
|
124
|
-
|
125
|
-
# Development
|
126
|
-
|
127
|
-
After checking out the repo, run `bundle install` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
128
|
-
|
129
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
130
|
-
|
131
|
-
# Contributors
|
132
|
-
|
133
|
-
Open-sourced with :heart: by Talkdesk!
|
134
|
-
|
135
|
-
Maintained by [Ivo Anjo](https://github.com/ivoanjo/) and the [Talkdesk Engineering](http://github.com/Talkdesk/) team.
|
136
|
-
|
137
|
-
# Contributing
|
138
|
-
|
139
|
-
Bug reports and pull requests are welcome on GitHub at <https://github.com/Talkdesk/warm-blanket>.
|
data/Rakefile
DELETED
data/bin/console
DELETED
data/bin/pry
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# frozen_string_literal: true
|
3
|
-
#
|
4
|
-
# This file was generated by Bundler.
|
5
|
-
#
|
6
|
-
# The application 'pry' is installed as part of a gem, and
|
7
|
-
# this file is here to facilitate running it.
|
8
|
-
#
|
9
|
-
|
10
|
-
require 'pathname'
|
11
|
-
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile',
|
12
|
-
Pathname.new(__FILE__).realpath)
|
13
|
-
|
14
|
-
require 'rubygems'
|
15
|
-
require 'bundler/setup'
|
16
|
-
|
17
|
-
load Gem.bin_path('pry', 'pry')
|
data/bin/rspec
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# frozen_string_literal: true
|
3
|
-
#
|
4
|
-
# This file was generated by Bundler.
|
5
|
-
#
|
6
|
-
# The application 'rspec' is installed as part of a gem, and
|
7
|
-
# this file is here to facilitate running it.
|
8
|
-
#
|
9
|
-
|
10
|
-
require 'pathname'
|
11
|
-
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile',
|
12
|
-
Pathname.new(__FILE__).realpath)
|
13
|
-
|
14
|
-
require 'rubygems'
|
15
|
-
require 'bundler/setup'
|
16
|
-
|
17
|
-
load Gem.bin_path('rspec-core', 'rspec')
|