All Projects → Talkdesk → warm-blanket

Talkdesk / warm-blanket

Licence: LGPL-3.0, GPL-3.0 licenses found Licenses found LGPL-3.0 COPYING.LESSER GPL-3.0 COPYING
Ruby gem for warming up web services on boot

Programming Languages

ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to warm-blanket

Offline geocoder
Offline Geocoder
Stars: ✭ 64 (+6300%)
Mutual labels:  gem, jruby
Ruby Install
Installs Ruby, JRuby, Rubinius, TruffleRuby or MRuby
Stars: ✭ 1,651 (+165000%)
Mutual labels:  jruby, truffleruby
Rvm
Ruby enVironment Manager (RVM)
Stars: ✭ 4,700 (+469900%)
Mutual labels:  jruby, truffleruby
Unimidi
Realtime MIDI IO for Ruby
Stars: ✭ 229 (+22800%)
Mutual labels:  gem, jruby
lockup
Lockup Gem
Stars: ✭ 111 (+11000%)
Mutual labels:  gem
acts as user
A gem which handles multiple types of users on a rails app
Stars: ✭ 24 (+2300%)
Mutual labels:  gem
pixitar
🧝 Pixitar is an avatar generation library written in Ruby.
Stars: ✭ 20 (+1900%)
Mutual labels:  gem
JRubyArt
JRubyArt a ruby implementation of processing
Stars: ✭ 87 (+8600%)
Mutual labels:  jruby
socket.io-rails
Rails asset pipeline wrapper for socket.io
Stars: ✭ 57 (+5600%)
Mutual labels:  gem
nagios check
Ruby Nagios Check Integration
Stars: ✭ 13 (+1200%)
Mutual labels:  gem
madness
Instant Markdown Server
Stars: ✭ 54 (+5300%)
Mutual labels:  gem
grape-jwt-authentication
A reusable Grape JWT authentication concern
Stars: ✭ 31 (+3000%)
Mutual labels:  gem
git-reclone
reclone your git repo
Stars: ✭ 11 (+1000%)
Mutual labels:  gem
flyyer-ruby
Ruby helpers to create https://cdn.flyyer.io URLs | Og:Image as a Service
Stars: ✭ 13 (+1200%)
Mutual labels:  gem
fcmpush
Firebase Cloud Messaging API wrapper for Ruby, suppot HTTP v1 API including access_token auto refresh feature.
Stars: ✭ 44 (+4300%)
Mutual labels:  gem
google holiday calendar
Get holidays via Google Calendar.
Stars: ✭ 21 (+2000%)
Mutual labels:  gem
acts as inheritable
Inheritable functionality for ActiveRecord models.
Stars: ✭ 24 (+2300%)
Mutual labels:  gem
hawkfx
Hawkular explorer written in (J)Ruby with a JavaFX frontend.
Stars: ✭ 14 (+1300%)
Mutual labels:  jruby
dhash-vips
vips-powered ruby gem to measure images similarity, implementing dHash and IDHash algorithms
Stars: ✭ 75 (+7400%)
Mutual labels:  gem
RandomProxyRuby
Tiny Library for get random proxy (free).
Stars: ✭ 16 (+1500%)
Mutual labels:  gem

WarmBlanket

WarmBlanket is a Ruby gem for warming up web services on boot. Its main target are JRuby-powered web services or even TruffleRuby based services, although it is not specific to those runtimes in any way.

How the magic happens

Why do we need to warm up web services?

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.

This is a known challenge for most JVMs, and the same applies to JRuby applications, which also run on the JVM.

A widely-documented solution to this problem is to perform a warm-up step when starting a service:

What does WarmBlanket do?

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.

How does WarmBlanket work?

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.

As it simulates requests, the JVM is warmed up and thus when real requests come in, no performance degradation is observed.

Limitations/caveats

We strongly recommend that any services using WarmBlanket, if deployed on Heroku, use 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.

On kubernetes, you can make use of readiness probes to delay service startup while warm-blanket is working.

Important for TruffleRuby as well!

TruffleRuby can be run either on a standalone mode, or with a JVM. In either configuration, like JRuby, it needs to warm up until it gets to peak performance, so WarmBlanket is great there too!

How can I make use of it?

To make use of WarmBlanket, you’ll need to follow the next sections, which will guide you through installing, configuring and enabling the gem.

1. Installation

To install using Bundler, add the following to your Gemfile:

gem 'warm-blanket', '~> 1.0'

WarmBlanket uses semantic versioning.

2. Configuration settings

This gem can be configured via the following environment variables:

  • PORT: Local webserver port (automatically set on Heroku)

  • WARMBLANKET_ENABLED: Enable warm blanket (defaults to false; true or 1 enables)

  • WARMBLANKET_WARMUP_THREADS: Number of warm up threads to use (defaults to 2)

  • WARMBLANKET_WARMUP_TIME_SECONDS: Time, in seconds, during which to warm up the service (defaults to 150)

Configuring endpoints to be called

Configure endpoints to be called as follows (on a config/warm_blanket.rb:

Example GET requests
require 'warm-blanket'

WarmBlanket.configure do |config|
  common_headers = {
    'X-Api-Key': ENV.fetch('API_KEYS').split(',').first,
  }

  config.endpoints = [
    {get: '/foo', headers: common_headers},
    {get: '/', headers: common_headers},
  ]
end

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 ;)

Example POST request with body
# Notice that you need to both:
# * set the Content-Type manually (if needed)
# * JSON-encode the body  (if needed)

WarmBlanket.configure do |config|
  common_headers = {
    'X-Api-Key': ENV.fetch('API_KEY').split(',').first,
    'Content-Type': 'application/json',
  }

  post_body = MultiJson.dump(
    account_id: 'dummy_account',
    user_id: 'dummy_user_id',
  )

  config.endpoints = [
    {post: '/some_endoint', headers: common_headers, body: post_body},
  ]
end

3. Trigger warmup

Add the following to the end of your config.ru file:

WarmBlanket.trigger_warmup

Development

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.

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.

Contributors

Open-sourced with ❤️ by Talkdesk!

Maintained by Ivo Anjo and the Talkdesk Engineering team.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/Talkdesk/warm-blanket.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].