web_tsunami 0.0.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CHANGELOG.md +14 -0
- data/Gemfile.lock +8 -3
- data/LICENSE.txt +22 -0
- data/README.md +135 -0
- data/lib/web_tsunami/version.rb +3 -0
- data/{web_tsunami.rb → lib/web_tsunami.rb} +26 -11
- data/web_tsunami.gemspec +22 -0
- data/web_tsunami.png +0 -0
- metadata +37 -19
- data/README +0 -9
- data/example.rb +0 -28
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 5684946d08e860b309d812707e690d91f45698140d5a22b1d8fe963f85203f25
|
4
|
+
data.tar.gz: dd58e555fc6c6dc89c3e1205299fec88c3879635ea36f4e78baa49a5f00993e5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1a29b20791f56ba1e87b4168777fd9a362a6bc06c3548bd5bc1a7a2d44b4d765153fb24ca732fea99172d0a2d2ffbdbad08aec7d0063cc018fa5309e740c647f
|
7
|
+
data.tar.gz: 3991dbf3d1b3d72c2aa40f734a153a8ed40f4bfbc903afdd6f3780c4b81ef918b0ed4033ee5f3521837342987ff16cd1a5f2a5f2d5a68990039c0a2d67356189
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# Changelog of Web Tsunami
|
2
|
+
|
3
|
+
## 0.2.0 (2024-01-25)
|
4
|
+
|
5
|
+
* Add methods post, put, patch and delete
|
6
|
+
* Improve README with an advanced example
|
7
|
+
|
8
|
+
## 0.1.0 (2024-01-19)
|
9
|
+
|
10
|
+
* Fix non compatible changes of Typhoeus
|
11
|
+
|
12
|
+
## 0.0.1 (2012-07-13)
|
13
|
+
|
14
|
+
* Initial version
|
data/Gemfile.lock
CHANGED
@@ -1,12 +1,17 @@
|
|
1
1
|
GEM
|
2
2
|
remote: http://rubygems.org/
|
3
3
|
specs:
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
ethon (0.16.0)
|
5
|
+
ffi (>= 1.15.0)
|
6
|
+
ffi (1.16.3)
|
7
|
+
typhoeus (1.4.1)
|
8
|
+
ethon (>= 0.9.0)
|
7
9
|
|
8
10
|
PLATFORMS
|
9
11
|
ruby
|
10
12
|
|
11
13
|
DEPENDENCIES
|
12
14
|
typhoeus
|
15
|
+
|
16
|
+
BUNDLED WITH
|
17
|
+
2.2.22
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2024 Alexis Bernard
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,135 @@
|
|
1
|
+
<img align="right" width="120px" src="./web_tsunami.png">
|
2
|
+
|
3
|
+
# Web Tsunami
|
4
|
+
|
5
|
+
Write tailor-made scenarios for load testing web apps
|
6
|
+
|
7
|
+
## Why
|
8
|
+
|
9
|
+
Many good tools already exist for a very long time such as ApacheBench and Siege.
|
10
|
+
The goal is not to replace them.
|
11
|
+
But sometimes, load testing a web app requires to write a custom scenario.
|
12
|
+
My initial requirement was to send requests with unique parameters.
|
13
|
+
To the best of my knowledge, no tool could do this.
|
14
|
+
|
15
|
+
The goal is to focus only on the scenario without thinking about forking, threads and non blocking IOs.
|
16
|
+
Fortunately there is [Typhoeus](https://github.com/typhoeus/typhoeus) to send parallel HTTP requests.
|
17
|
+
|
18
|
+
## How
|
19
|
+
|
20
|
+
Web Tsunami is a tiny class that forks every seconds and sends as many requests as expected.
|
21
|
+
It provide the methods `get`, `post`, `put`, `patch` and `delete`.
|
22
|
+
They all accept the same arguments : `get(url, options = {}, &block)`.
|
23
|
+
The `options` is given to Typhoeus as is.
|
24
|
+
It can contain headers and the request body.
|
25
|
+
See [Typhoeus usage](https://github.com/typhoeus/typhoeus/#usage) for more details.
|
26
|
+
|
27
|
+
## Examples
|
28
|
+
|
29
|
+
Let's start with a very trivial scenario and I will show you an advanced one after :
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
require "web_tsunami"
|
33
|
+
|
34
|
+
class SearchTsunami < WebTsunami::Scenario
|
35
|
+
def run
|
36
|
+
get("http://site.example") do
|
37
|
+
# Block is executed once the response has been received
|
38
|
+
sleep(5) # Simulates the time required for a human to visit the next page
|
39
|
+
get("http://site.example/search?query=stress+test") do |response|
|
40
|
+
# Do whatever you need with the response object or ignore it
|
41
|
+
sleep(10)
|
42
|
+
get("http://site.example/search?query=stress+test&page=#{rand(100)}") do
|
43
|
+
sleep(5)
|
44
|
+
get("http://site.example/stress/test")
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
# Simulates 100 concurrent visitors every second for 10 minutes
|
52
|
+
# It's a total of 60K unique visitors for an average of 23'220 rpm.
|
53
|
+
SearchTsunami.start(concurrency: 100, duration: 60 * 10)
|
54
|
+
```
|
55
|
+
|
56
|
+
In this scenario, a visitor comes on the index page, then search for _stress test_, then go on a random page of the search result, and finally found the stress test page.
|
57
|
+
It introduces a unique parameters which is the page number.
|
58
|
+
It's nice, but it could have almost be done with Siege.
|
59
|
+
Let me show you a more advanced scenario.
|
60
|
+
|
61
|
+
```ruby
|
62
|
+
require "web_tsunami"
|
63
|
+
require "json"
|
64
|
+
|
65
|
+
class RegistrationTsunami < WebTsunami::Scenario
|
66
|
+
# Simulate a visitor coming on the index page,
|
67
|
+
# then going to the registration form,
|
68
|
+
# and finally submitting the form.
|
69
|
+
def run
|
70
|
+
get("http://site.example/") do |response|
|
71
|
+
get("http://site.example/account/new") do |response|
|
72
|
+
post("http://site.example/account", post_account_options(response)) do |response|
|
73
|
+
# Then visiting the dashboard, and so on.
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
private
|
80
|
+
|
81
|
+
def post_account_options(response)
|
82
|
+
# In order to not be blocked by the Cross-Site Request Forgery, the request must contain :
|
83
|
+
# 1. Cookie header
|
84
|
+
# 2. authenticity_token form param
|
85
|
+
{
|
86
|
+
headers: build_post_headers(response),
|
87
|
+
body: JSON.generate(
|
88
|
+
authenticity_token: extract_csrf_token(response.body),
|
89
|
+
user: {
|
90
|
+
name: name = rand.to_s[2..-1],
|
91
|
+
email: "#{name}@domain.test",
|
92
|
+
password: name,
|
93
|
+
}
|
94
|
+
),
|
95
|
+
}
|
96
|
+
end
|
97
|
+
|
98
|
+
def build_post_headers(response)
|
99
|
+
{
|
100
|
+
"Origin" => response.request&.base_url,
|
101
|
+
"Content-Type" => "application/json",
|
102
|
+
"Cookie" => response.headers["Set-Cookie"],
|
103
|
+
# To Simulate a post XmlHttpRequest from JavaScript, you should provide these headers :
|
104
|
+
# "X-CSRF-Token" => extract_csrf_token(response.body),
|
105
|
+
# "X-Requested-With" => "XMLHttpRequest"
|
106
|
+
}
|
107
|
+
end
|
108
|
+
|
109
|
+
CSRF_REGEX = /<meta name="csrf-token" content="([^"]+)"/
|
110
|
+
|
111
|
+
def extract_csrf_token(html)
|
112
|
+
html.match(CSRF_REGEX)[1]
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
# Simulates 100 concurrent visitors every second for 10 minutes
|
117
|
+
RegistrationTsunami.start(concurrency: 100, duration: 10)
|
118
|
+
```
|
119
|
+
|
120
|
+
This is more complex because it handles CSRF and every submitted forms are unique.
|
121
|
+
Indeed emails must be unique, so it's not possible to send the same data everytime.
|
122
|
+
|
123
|
+
## Output and result
|
124
|
+
|
125
|
+
Web Tsunami does not measure response time or print any result.
|
126
|
+
If you are running a load test, that means you should use an APM (application performance monitoring).
|
127
|
+
It already collects and displays all data you need such as throughput, response time and bottlenecks.
|
128
|
+
|
129
|
+
So, the only output are errors.
|
130
|
+
|
131
|
+
## License
|
132
|
+
|
133
|
+
The gem is available as open-source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
134
|
+
|
135
|
+
Rails developer? Check out [RoRvsWild](https://rorvswild.com), our Ruby on Rails application monitoring tool.
|
@@ -13,22 +13,41 @@ module WebTsunami
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def initialize(concurrency)
|
16
|
-
@sleeps = {}
|
17
16
|
@concurrency = concurrency
|
18
17
|
end
|
19
18
|
|
20
19
|
def requests
|
21
|
-
|
22
|
-
@requests
|
20
|
+
@requests ||= Typhoeus::Hydra.new
|
23
21
|
end
|
24
22
|
|
25
|
-
def get(url, &block)
|
26
|
-
|
23
|
+
def get(url, options = {}, &block)
|
24
|
+
request(:get, url, options, &block)
|
25
|
+
end
|
26
|
+
|
27
|
+
def post(url, options = {}, &block)
|
28
|
+
request(:post, url, options, &block)
|
29
|
+
end
|
30
|
+
|
31
|
+
def put(url, options = {}, &block)
|
32
|
+
request(:put, url, options, &block)
|
33
|
+
end
|
34
|
+
|
35
|
+
def patch(url, options = {}, &block)
|
36
|
+
request(:patch, url, options, &block)
|
37
|
+
end
|
38
|
+
|
39
|
+
def delete(url, options = {}, &block)
|
40
|
+
request(:delete, url, options, &block)
|
41
|
+
end
|
42
|
+
|
43
|
+
def request(method, url, options, &block)
|
44
|
+
req = Typhoeus::Request.new(url, {method: method}.merge(options))
|
45
|
+
requests.queue(req)
|
27
46
|
req.on_complete do |response|
|
28
47
|
if response.timed_out?
|
29
48
|
puts "Timeout #{url}"
|
30
49
|
elsif response.code == 0
|
31
|
-
puts "#{response.
|
50
|
+
puts "#{response.return_message} #{url}"
|
32
51
|
elsif !response.success? && response.code != 302
|
33
52
|
puts "#{response.code} #{url}"
|
34
53
|
end
|
@@ -37,7 +56,7 @@ module WebTsunami
|
|
37
56
|
end
|
38
57
|
|
39
58
|
def start
|
40
|
-
concurrency.times {
|
59
|
+
concurrency.times { run }
|
41
60
|
requests.run
|
42
61
|
end
|
43
62
|
|
@@ -45,9 +64,5 @@ module WebTsunami
|
|
45
64
|
raise NotImplementedError
|
46
65
|
end
|
47
66
|
|
48
|
-
def request_options
|
49
|
-
{}
|
50
|
-
end
|
51
|
-
|
52
67
|
end
|
53
68
|
end
|
data/web_tsunami.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require_relative "lib/web_tsunami/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "web_tsunami"
|
7
|
+
s.version = WebTsunami::VERSION
|
8
|
+
s.authors = ["Alexis Bernard"]
|
9
|
+
s.email = ["alexis@basesecrete.com"]
|
10
|
+
s.homepage = "https://github.com/BaseSecrete/web_tsunami"
|
11
|
+
s.summary = "Tailor-made load testing for web apps"
|
12
|
+
s.description = "Write realistic scenarios to test the load of a web application."
|
13
|
+
s.license = "MIT"
|
14
|
+
|
15
|
+
s.files = `git ls-files`.split("\n")
|
16
|
+
s.require_paths = ["lib"]
|
17
|
+
|
18
|
+
s.metadata["source_code_uri"] = "https://github.com/BaseSecrete/web_tsunami"
|
19
|
+
s.metadata["changelog_uri"] = "https://github.com/BaseSecrete/web_tsunami/blob/master/CHANGELOG.md"
|
20
|
+
|
21
|
+
s.add_runtime_dependency "typhoeus"
|
22
|
+
end
|
data/web_tsunami.png
ADDED
Binary file
|
metadata
CHANGED
@@ -1,50 +1,68 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: web_tsunami
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
5
|
-
prerelease:
|
4
|
+
version: 0.2.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Alexis Bernard
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
13
|
-
dependencies:
|
14
|
-
|
11
|
+
date: 2024-01-25 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: typhoeus
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description: Write realistic scenarios to test the load of a web application.
|
15
28
|
email:
|
16
|
-
- alexis@
|
29
|
+
- alexis@basesecrete.com
|
17
30
|
executables: []
|
18
31
|
extensions: []
|
19
32
|
extra_rdoc_files: []
|
20
33
|
files:
|
34
|
+
- CHANGELOG.md
|
21
35
|
- Gemfile
|
22
36
|
- Gemfile.lock
|
23
|
-
-
|
24
|
-
-
|
25
|
-
- web_tsunami.rb
|
26
|
-
|
27
|
-
|
37
|
+
- LICENSE.txt
|
38
|
+
- README.md
|
39
|
+
- lib/web_tsunami.rb
|
40
|
+
- lib/web_tsunami/version.rb
|
41
|
+
- web_tsunami.gemspec
|
42
|
+
- web_tsunami.png
|
43
|
+
homepage: https://github.com/BaseSecrete/web_tsunami
|
44
|
+
licenses:
|
45
|
+
- MIT
|
46
|
+
metadata:
|
47
|
+
source_code_uri: https://github.com/BaseSecrete/web_tsunami
|
48
|
+
changelog_uri: https://github.com/BaseSecrete/web_tsunami/blob/master/CHANGELOG.md
|
28
49
|
post_install_message:
|
29
50
|
rdoc_options: []
|
30
51
|
require_paths:
|
31
52
|
- lib
|
32
53
|
required_ruby_version: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
54
|
requirements:
|
35
|
-
- -
|
55
|
+
- - ">="
|
36
56
|
- !ruby/object:Gem::Version
|
37
57
|
version: '0'
|
38
58
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
39
|
-
none: false
|
40
59
|
requirements:
|
41
|
-
- -
|
60
|
+
- - ">="
|
42
61
|
- !ruby/object:Gem::Version
|
43
62
|
version: '0'
|
44
63
|
requirements: []
|
45
|
-
|
46
|
-
rubygems_version: 1.8.10
|
64
|
+
rubygems_version: 3.2.22
|
47
65
|
signing_key:
|
48
|
-
specification_version:
|
49
|
-
summary:
|
66
|
+
specification_version: 4
|
67
|
+
summary: Tailor-made load testing for web apps
|
50
68
|
test_files: []
|
data/README
DELETED
@@ -1,9 +0,0 @@
|
|
1
|
-
Benchmark your web application.
|
2
|
-
|
3
|
-
Why not using Apache Benchmark or any similar tool?
|
4
|
-
|
5
|
-
Because some times we need to send unique requests and AB doesn't fit for that need.
|
6
|
-
|
7
|
-
Check example.rb to see how it's working.
|
8
|
-
|
9
|
-
More documentation and gem is coming soon.
|
data/example.rb
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
$LOAD_PATH << File.dirname(__FILE__)
|
2
|
-
|
3
|
-
require 'web_tsunami'
|
4
|
-
|
5
|
-
# Triggers the following requests concurently:
|
6
|
-
# http://www.google.com
|
7
|
-
# http://www.google.com/search?q=ruby
|
8
|
-
# http://www.google.com/search?q=ruby&start=10
|
9
|
-
|
10
|
-
class GoogleTsunami < WebTsunami::Scenario
|
11
|
-
def run
|
12
|
-
get('http://www.google.com') do
|
13
|
-
puts 'http://www.google.com'
|
14
|
-
get('http://www.google.com/search?q=ruby') do
|
15
|
-
puts 'http://www.google.com/search?q=ruby'
|
16
|
-
get("http://www.google.com/search?q=ruby&start=#{rand(100)*10}") do
|
17
|
-
puts 'http://www.google.com/search?q=ruby&start=10'
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
# Set concurrency and duration in seconds and start your script.
|
25
|
-
# These numbers are voluntary low because I don't want any trouble with Google.
|
26
|
-
# But don't hesitate to set a higher concurrency and a duration of almost 5 minutes
|
27
|
-
# in order to get a reliable benchmark.
|
28
|
-
GoogleTsunami.start(concurrency: 2, duration: 10)
|