https://www.visualstudio.com/en-us/docs/test/performance-testing/_img/performance-testing/ic838830.png
# config/application.rb
# require "rails"
# Pick the frameworks you want:
require "active_model/railtie"
# require "active_job/railtie"
require "active_record/railtie"
# require "action_controller/railtie"
# require "action_mailer/railtie"
# require "action_view/railtie"
# require "action_cable/engine"
# require "sprockets/railtie"
# require "rails/test_unit/railtie"
rails new awesome_ruby_app --api
class ApplicationController < JSONAPI::ResourceControllerMetal
include Knock::Authenticable
before_action :authenticate_user
def head(type, options = {}) end # ...
end
gem "jsonapi-resources"
Started GET "/mail-logs" for ::1 at 2017-03-17 18:50:46 +0100
Processing by MailLogsController#index as API_JSON
MailLog Load (0.4ms)
SELECT "mail_logs".* FROM "mail_logs"
ORDER BY "mail_logs"."number"
DESC LIMIT $1 OFFSET $2 [["LIMIT", 20], ["OFFSET", 0]]
(0.3ms) SELECT COUNT(*) FROM "mail_logs"
Completed 200 OK in 7ms (Views: 0.0ms)
Requests per second: 250.07 [#/sec] (mean)
Time per request: 3.999 [ms] (mean)
Time per request: 3.999 [ms] (mean, across all concurrent requests)
Percentage of the requests served within a certain time (ms)
50% 4
66% 4
75% 4
80% 4
90% 4
95% 5
98% 5
99% 6
100% 39 (longest request)
# frozen_string_literal: true
require 'logger'
require 'sinatra'
require 'sequel'
require 'sinatra/jsonapi'
require 'sinja/sequel/helpers'
DB = Sequel.connect('postgres://localhost/cl-api_development')
DB.extension(:freeze_datasets)
DB.extension(:pagination)
DB.optimize_model_load = true
DB.loggers << Logger.new($stderr) if Sinatra::Base.development?
Sequel::Model.plugin :tactical_eager_loading
class MailLog < Sequel::Model
many_to_one :category
many_to_one :company
end
class Category < Sequel::Model
one_to_many :mail_log
end
class Company < Sequel::Model
one_to_many :mail_log
end
Sequel::Model.finalize_associations
Sequel::Model.freeze
class BaseSerializer
include JSONAPI::Serializer
end
class MailLogSerializer < BaseSerializer
attributes :number, :in_or_out, :document_date_on, :received_on, :external_number, :comment, :value_net, :value_vat
has_one :category
has_one :company
end
class CategorySerializer < BaseSerializer
attributes :name
has_many :mail_logs
end
class CompanySerializer < BaseSerializer
attributes :name, :icon
has_many :mail_logs
end
class MailLogs < Sinatra::Application
register Sinatra::JSONAPI
resource 'mail-logs' do
index do
MailLog.dataset
end
end
end
freeze_jsonapi
Requests per second: 746.18 [#/sec] (mean)
Time per request: 1.340 [ms] (mean)
Time per request: 1.340 [ms] (mean, across all concurrent requests)
Transfer rate: 2731.85 [Kbytes/sec] received
Percentage of the requests served within a certain time (ms)
50% 1
66% 1
75% 1
80% 1
90% 2
95% 2
98% 2
99% 2
100% 5 (longest request)
Michał Czyż
@cs3b