Created
September 6, 2011 15:28
-
-
Save futurechimp/1197857 to your computer and use it in GitHub Desktop.
A better solution to the problem of sending xmpp in ruby
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
require 'rubygems' | |
require 'xmpp4r' | |
require 'sinatra' | |
# Doing XMPP connectivity like this has terrible performance: | |
# | |
# https://gist.github.com/1197232 | |
# | |
# Here's a better way. | |
# | |
# Set up two XMPP accounts: | |
# "account1@yourserver.org" and "account2@yourserver.org" | |
# Both with password "password". | |
# | |
# You can change the config to suit your setup here: | |
JABBER_SERVER = "yourserver.org" | |
ACCOUNT1 = "account1" | |
ACCOUNT2 = "account2" | |
# Start the sinatra webserver server using: | |
# | |
# ruby -rubygems xmpp4r_faster.rb | |
# | |
# Then let's hit the app with some concurrent connections. Try this at the command line: | |
# ab -c 25 -n 1000 http://localhost:4567/hi | |
jid = Jabber::JID::new("#{ACCOUNT1}@#{JABBER_SERVER}/Testing") | |
@@cl = Jabber::Client::new(jid) | |
@@cl.connect | |
@@cl.auth('password') | |
get '/hi' do | |
m = Jabber::Message::new("#{ACCOUNT2}@#{JABBER_SERVER}", "foo").set_type(:normal).set_id('1').set_subject("blah") | |
@@cl.send m | |
end | |
# Results are a lot more satisfactory this time, compared to the previous gist: | |
# ab -c 25 -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: 0 bytes | |
# | |
# Concurrency Level: 25 | |
# Time taken for tests: 1.541 seconds | |
# Complete requests: 1000 | |
# Failed requests: 0 | |
# Write errors: 0 | |
# Total transferred: 141423 bytes | |
# HTML transferred: 0 bytes | |
# Requests per second: 648.89 [#/sec] (mean) | |
# Time per request: 38.527 [ms] (mean) | |
# Time per request: 1.541 [ms] (mean, across all concurrent requests) | |
# Transfer rate: 89.62 [Kbytes/sec] received | |
# | |
# Connection Times (ms) | |
# min mean[+/-sd] median max | |
# Connect: 0 0 0.1 0 1 | |
# Processing: 16 38 15.9 33 78 | |
# Waiting: 8 28 13.9 23 68 | |
# Total: 16 38 15.8 33 79 | |
# | |
# Percentage of the requests served within a certain time (ms) | |
# 50% 33 | |
# 66% 38 | |
# 75% 52 | |
# 80% 59 | |
# 90% 62 | |
# 95% 68 | |
# 98% 75 | |
# 99% 77 | |
# 100% 79 (longest request) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment