Skip to content

Ruby LSAPI

In order to maximize the performance of a Rails application, we developed our own Ruby interface module using our LiteSpeed APIprotocol, also known as LSAPI. LSAPI is a highly optimized IPC protocol between OpenLiteSpeed web server and a standalone process aimed at yielding the best possible performance.

Requirements

  • OpenLiteSpeed version 1.4.41+

Set up Environment

Install Ruby Packages

If you haven't already, please install the Ruby package:

yum install ruby ruby-devel rubygems
git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
apt install rbenv libreadline-dev ruby-dev -y
rbenv install 2.5.0
rbenv global 2.5.0

Install Rack and Ruby LSAPI

The easiest and fastest way to run Ruby apps with LSAPI is to install ruby-lsapi.

gem install rack -v 1.6.11
gem install ruby-lsapi

Set up Context

This example assumes you are using the default document root /ruby/. Navigate to Web Admin > Virtual Hosts > Context > Add, and set the following values:

  • Type = App Server
  • URI = /ruby/
  • Location = /usr/local/lsws/Example/html/ruby/
  • Binary Path = /usr/bin/ruby
  • Application Type = rails

Verification

To verify your setup is correct, create a ruby directory under your document root. Create a config.ru file with the following content:

app = proc do |env|
    message = "It works!\n"
    version = "Ruby %s\n" % RUBY_VERSION
    response = [message, version].join("\n")
    [200, {"Content-Type" => "text/plain"}, [response]]
end
run app

Visit http://Your_Server_IP:Port/ruby/ in your browser and you should see:

It works!
Ruby x.x.x

Set up Rails with Ruby

Install

gem install rails
apt install node.js

Create Project

We will create this project under the Example directory, but you can create it wherever you want to.

rails new demo

Rails Settings

vi demo/config/routes.rb

Input this line before end. Be sure to change /rails to your own context name.

get "/rails", to: "rails/welcome#index"

Change owner

chown -R nobody:nogroup demo

Set up Context

This example assumes you are using the default document root + /rails/. Navigate to Web Admin > Virtual Hosts > Context > Add, and set the following values:

  • Type = App Server
  • URI = /rails/
  • Location = /usr/local/lsws/Example/demo/
  • Binary Path = /usr/bin/ruby
  • Application Type = rails

Verify Rails

Visit http://Your_Server_IP:Port/rails/ in your browser and you should see the admin page, which says Yay! You're on Rails!.

Optional Settings

Custom Binary Path

If you want to change the ruby path, you may update the Context and set Binary Path = /usr/ruby.

Custom Startup File Name

If you want to change the default ruby file name from config.ru to example.ru, you may update the Context and set Startup File = example.ru.