-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
180 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
module Socky | ||
module Server | ||
class CachedJsonHash < Hash | ||
|
||
def to_json | ||
@json ||= super | ||
end | ||
|
||
def remove_cache | ||
@json = nil | ||
end | ||
|
||
end | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
require 'spec_helper' | ||
require 'performance_helper' | ||
require 'benchmark' | ||
|
||
describe 'Connecting Performance' do | ||
|
||
it "For x listeners" do | ||
[1, 10, 100].each do |count| | ||
results = [] | ||
5.times do | ||
@application = Socky::Server::Application.new('test_application', 'test_secret') | ||
@channel = "presence" | ||
results << Benchmark.realtime {count.times { add_listener }} | ||
clean_application | ||
end | ||
print_result count, results | ||
end | ||
end | ||
|
||
end | ||
|
||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
require 'spec_helper' | ||
require 'performance_helper' | ||
require 'benchmark' | ||
|
||
describe 'Sending Many Messages Performance' do | ||
|
||
it "For 1 listener and x messages" do | ||
[1, 10, 100].each do |count| | ||
results = [] | ||
5.times do | ||
@channel = "private" | ||
@application = application_with_listeners(1) | ||
results << Benchmark.realtime {send_messages(count)} | ||
clean_application | ||
end | ||
print_result count, results | ||
end | ||
end | ||
|
||
end | ||
|
||
|
||
|
||
|
||
|
25 changes: 25 additions & 0 deletions
25
spec/performance/send_message_to_many_listeners_performance.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
require 'spec_helper' | ||
require 'performance_helper' | ||
require 'benchmark' | ||
|
||
describe 'Sending Message To Many Listeners Performance' do | ||
|
||
it "For x listeners and 1 message" do | ||
[1, 10, 100].each do |count| | ||
results = [] | ||
5.times do | ||
@channel = "private" | ||
@application = application_with_listeners(count) | ||
results << Benchmark.realtime {send_messages(1)} | ||
clean_application | ||
end | ||
print_result count, results | ||
end | ||
end | ||
end | ||
|
||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
Socky::Server::Channel::Private.class_eval do | ||
protected | ||
|
||
def check_auth(connection, message) | ||
true | ||
end | ||
|
||
end | ||
|
||
|
||
def application_with_listeners count | ||
@application = Socky::Server::Application.new('test_application', 'test_secret') | ||
count.times { add_listener } | ||
add_writer | ||
@application | ||
end | ||
|
||
def add_listener | ||
websocket = mock_websocket(@application.name) | ||
env = { 'PATH_INFO' => '/websocket/' + @application.name } | ||
websocket.on_open(env) | ||
data = {'event' => 'socky:subscribe', 'channel' => "#{@channel}-channel", 'auth' => 'test_auth'} | ||
websocket.on_message(env, data) | ||
websocket | ||
end | ||
|
||
def add_writer | ||
@writer_ws = mock_websocket(@application.name) | ||
env = { 'PATH_INFO' => '/websocket/' + @application.name } | ||
@writer_ws.on_open(env) | ||
data = {'event' => 'socky:subscribe', 'channel' => "#{@channel}-channel", 'write' => 'true', 'auth' => 'test_auth'} | ||
@writer_ws.on_message(env, data) | ||
@writer_ws | ||
end | ||
|
||
def send_messages count | ||
env = { 'PATH_INFO' => '/websocket/' + @application.name } | ||
data = {'event' => 'send', 'channel' => "#{@channel}-channel", 'user_data' => "test_message"} | ||
count.times { @writer_ws.on_message(env, data) } | ||
end | ||
|
||
def clean_application | ||
@application.connections.values.each {|c| c.destroy} | ||
Socky::Server::Channel::Private.list['test_application'] = Hash.new | ||
Socky::Server::Channel::Private.list['test_application'] = Hash.new | ||
Socky::Server::Application.list.delete('test_application') | ||
end | ||
|
||
|
||
def print_result label, results | ||
avg = results.inject(0.0) { |sum, el| sum + el } / results.size | ||
puts ["#{label}:".ljust(15), avg].join | ||
end | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
require 'rspec/core' | ||
require 'rspec/core/rake_task' | ||
|
||
namespace :spec do | ||
desc "Run the performance tests" | ||
RSpec::Core::RakeTask.new("performance") do |t| | ||
t.pattern = "./spec/**/*_performance.rb" | ||
t.rspec_opts = ["-c", "-f documentation"] | ||
end | ||
end | ||
|