** Ignore the rest of this document. The content is pulled from an old sample and is partly out of date. It remains here for future use when completing this lesson. **
The Sample App can be tested on a local browser with Javascript enabled, and can be served with choice between the following runners:
- a pure Ruby Runner, built using
WEBrick
- a high-performance spawning/forking runner written in C, OpO (Not supported on Windows).
- a high-performance embedded Ruby runner written in C, OpO-Rub (Not supported on Windows).
Additionally, the files necessary to render the App view needs to be compiled
from their source. The source files are located in the view
directory, and they get compiled into the assets
directory.
They need to be re-compiled manually if the source-files get edited.
For development on Windows the Ruby Runner is the only choice. As far as the Controller is concerned it operates exactly the same as other runners.
The configuration file for this runner is placed in wabur
sub-directory
and is named wabur.conf
OpO provides the HTTP server and the Model storage, and is able to run the
sample app as a spawned app that uses $stdin
and $stdout
for IO.
OpO can be downloaded from OpO Downloads.
The confguration file for OpO is in the opo
sub-directory, and is named
opo.conf
. The configuration specifies that the OpO disk
storage be in the opo/data
directory. It also turns on logging for HTTP
requests and responses along with handler information from the Runner's
perspective.
Near the bottom of the conf file, the Controller spawn.rb
is mentioned
along with command line options. The -v
option turns on Controller
verbosity.
OpO-Rub provides the HTTP server and the Model storage, and is able to run the an embedded Ruby application.
OpO-Rub can be downloaded from OpO Downloads.
The configuration file for OpO-Rub is in the opo
sub-directory, and is named
embed.conf
. The configuration specifies that the OpO-Rub
disk storage be in the opo/data
directory. It also turns on logging for HTTP
requests and responses along with handler information from the Runner's
perspective.
Compiling and running the App with a runner of your choice can be easily
by using the start-sample
BASH script.
It accepts two options:
-b
— Compile view files and then execute the default Ruby Runner. (Compiling is necessary to generate and update the files required to properly render the App view.)-o
— Serve the app using the OpO runner without any compiling.
Note: Alternatively, the two options can be passed together as -bo
to
compile and execute the OpO runner back-to-back.
The Sample App has been configured on both runners to serve at
http://localhost:6363
by default and can changed in the concerned config
files.
WAB Controllers can be tested without a browser and Javascript. By using curl, HTTP requests can be sent to the runner and subsequently verify the response.
Two terminal windows are to be used in this method. While one is for displaying
the runner
trace output, the other is for calling curl
to make HTTP
requests and to receive responses. Mentally designate the two terminal
windows as runner and curl terminals.
Run the shell script start-view
with necessary options to
serve the runner of your choice.
The curl
application is used to add a record. The record is in the
article-1.json
file. Once inserted, the response body
will include the reference number of the newly created record.
> curl -w "\n" -T article-1.json http://localhost:6363/v1/v1/Article
A response similar to the following should appear in the curl terminal where the curl command was invoked.
{"rid":"20170814212950.147723000","api":2,"body":{"ref":11,"code":0}}
Note: The ref
in the body
element is the reference number of the new
record. It will be used later to get and delete that record.
Around the same time, the runner terminal will show the arrival of the PUT
request with details followed by a handler trace and then traces from the
WAB::IO::Shell
indicating what is sent to each part of the WAB setup.
The reference number from the create is used to get a record. If not available a list of records can be retrieved.
> curl -w "\n" http://localhost:6363/v1/Article
or with the record reference
> curl -w "\n" http://localhost:6363/v1/Article/11
The record can be deleted with an HTTP DELETE
request.
> curl -w "\n" -X DELETE http://localhost:6363/v1/Article/11
Using the OpO Runner, a Ruby HTTP client is not able to generate requests and
process responses quick enough to reach the limits of the Runner. Instead a C
based HTTP benchmarking tool is used. It is in the OpO download and is called
hose
.
To run the benchmarks start opod
with the opo/bench.conf
file. This
turns off the verbosity on opod
and on the sample Ruby app.
Next add a record as done previously.
There are two ways to get the JSON of the created record:
- Using the Controller with the path
http://localhost:6363/v1/Article/11
(or) - By going directly to the database with the path
http://localhost:6363/json/000000000000000b
which uses the ref in hex to identify the record. This is interesting in that it shows the overhead of the calls to the Ruby Controller.
Now that a record has been created, the benchmarks can be run.
> hose -p "json/000000000000000b" -d 1.0 -t 2 127.0.0.1:6363
> hose -p "v1/Article/11" -d 1.0 -t 2 127.0.0.1:6363
Both calls to the hose benchmarking app will use 2 threads and open 1000 connections at a time to the Runner.