ruby sinatra web 开发框架

本文介绍了一个使用Sinatra框架开发的简单Ruby Web应用程序,并通过性能测试展示了其处理请求的能力。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

-bash-3.2$ vi hi.rb
require 'rubygems'
require 'sinatra'


get '/hi' do
  "Hello World!"
end
~



-bash-3.2$ ruby hi.rb 

== Sinatra/1.3.1 has taken the stage on 4567 for development with backup from Thin
>> Thin web server (v1.3.1 codename Triple Espresso)
>> Maximum connections set to 1024

>> Listening on 0.0.0.0:4567, CTRL+C to stop




-bash-3.2$ ruby hi.rb 
== Sinatra/1.3.1 has taken the stage on 4567 for development with backup from Thin
>> Thin web server (v1.3.1 codename Triple Espresso)
>> Maximum connections set to 1024
>> Listening on 0.0.0.0:4567, CTRL+C to stop
202.38.128.168 - - [23/Dec/2011 13:19:55] "GET / HTTP/1.1" 404 440 0.0008
202.38.128.168 - - [23/Dec/2011 13:19:56] "GET /__sinatra__/404.png HTTP/1.1" 200 23305 0.0020
202.38.128.168 - - [23/Dec/2011 13:19:59] "GET /favicon.ico HTTP/1.1" 404 451 0.0007
202.38.128.168 - - [23/Dec/2011 13:47:41] "GET / HTTP/1.1" 404 440 0.0013
202.38.128.168 - - [23/Dec/2011 13:47:41] "GET /favicon.ico HTTP/1.1" 404 451 0.0006
202.38.128.168 - - [23/Dec/2011 13:47:50] "GET /hi HTTP/1.1" 200 12 0.0005
202.38.128.168 - - [23/Dec/2011 13:47:55] "GET /favicon.ico HTTP/1.1" 404 451 0.0006



性能测试


# ab -n 1000 http://localhost:4567/hi
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/


Benchmarking localhost (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Completed 1000 requests
Finished 1000 requests




Server Software:        thin
Server Hostname:        localhost
Server Port:            4567


Document Path:          /hi
Document Length:        12 bytes


Concurrency Level:      1
Time taken for tests:   3.139 seconds
Complete requests:      1000
Failed requests:        0
Write errors:           0
Total transferred:      216000 bytes
HTML transferred:       12000 bytes
Requests per second:    318.58 [#/sec] (mean)
Time per request:       3.139 [ms] (mean)
Time per request:       3.139 [ms] (mean, across all concurrent requests)
Transfer rate:          67.20 [Kbytes/sec] received


Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.0      0       0
Processing:     1    3  38.3      1    1068
Waiting:        1    3  38.3      1    1068
Total:          1    3  38.3      1    1068


Percentage of the requests served within a certain time (ms)
  50%      1
  66%      1
  75%      1
  80%      1
  90%      1
  95%      1
  98%      1
  99%     26
 100%   1068 (longest request)
[root@prfserver01 ~]# ab --help




--------------------------------------------------------------------------

opennebula sunstone 使用这个框架开发的
性能测试

-bash-3.2$ ab -n 100 http://localhost:9869/
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/


Benchmarking localhost (be patient).....done




Server Software:        thin
Server Hostname:        localhost
Server Port:            9869


Document Path:          /
Document Length:        1518 bytes


Concurrency Level:      1
Time taken for tests:   0.131 seconds
Complete requests:      100
Failed requests:        0
Write errors:           0
Total transferred:      172400 bytes
HTML transferred:       151800 bytes
Requests per second:    764.06 [#/sec] (mean)
Time per request:       1.309 [ms] (mean)
Time per request:       1.309 [ms] (mean, across all concurrent requests)
Transfer rate:          1286.37 [Kbytes/sec] received


Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.0      0       0
Processing:     1    1   3.8      1      39
Waiting:        1    1   3.8      1      39
Total:          1    1   3.8      1      39


Percentage of the requests served within a certain time (ms)
  50%      1
  66%      1
  75%      1
  80%      1
  90%      1
  95%      1
  98%      4
  99%     39
 100%     39 (longest request)



================================================
Sinatra is a DSL for quickly creating web applications in Ruby with minimal effort:

DSL : domain specific language

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值