nacjac 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 509b091528735dcee49218578a4ee36a2683029c
4
+ data.tar.gz: d7c78cc8c067e4029f85cee8fd90531f692b712d
5
+ SHA512:
6
+ metadata.gz: dba319b9d2ed06d6d0da57485100543c59159a94ef740e008baef64c93e99e8ff9f844a23bd9d4edc95b1753348e52ec0209d25a292e0cad60ff5baf3781e80c
7
+ data.tar.gz: eb6876f0e50fe491e7521c8de6950907779485c5e680df645e57a9652af6c61c700dc4701b906ef97ba3b0bb57b3373e059312c4efcb68485330ad0f24893845
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ *.swp
2
+ *.gem
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ gem 'celluloid'
2
+ gem 'faraday'
data/Gemfile.lock ADDED
@@ -0,0 +1,17 @@
1
+ GEM
2
+ specs:
3
+ celluloid (0.16.0)
4
+ timers (~> 4.0.0)
5
+ faraday (0.9.1)
6
+ multipart-post (>= 1.2, < 3)
7
+ hitimes (1.2.2)
8
+ multipart-post (2.0.0)
9
+ timers (4.0.1)
10
+ hitimes
11
+
12
+ PLATFORMS
13
+ ruby
14
+
15
+ DEPENDENCIES
16
+ celluloid
17
+ faraday
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Edwin Tunggawan
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,25 @@
1
+ # Nacjac
2
+
3
+ CLI gem to measure web response time.
4
+
5
+ ## Installation
6
+
7
+ ```
8
+ $ gem install nacjac
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ The following line will spawn 2 threads to request http:///www.google.com for 10 seconds.
14
+
15
+ ```
16
+ nacjac http://www.google.com 2 10
17
+ ```
18
+
19
+ ## License
20
+
21
+ MIT License
22
+
23
+ ## Author
24
+
25
+ [Edwin Tunggawan](http://github.com/sdsdkkk)
data/bin/nacjac ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift "#{File.expand_path(File.dirname(__FILE__))}/../lib"
4
+
5
+ require 'rubygems'
6
+ require 'bundler/setup'
7
+ require 'nacjac'
8
+
9
+ if ARGV.count < 3
10
+ puts "Usage:"
11
+ puts " nacjac <target_url> <num_threads> <duration>"
12
+ else
13
+ cannon = Nacjac::Cannon.new(ARGV[0], ARGV[1].to_i, ARGV[2].to_i)
14
+ cannon.blast
15
+ cannon.report
16
+ end
@@ -0,0 +1,37 @@
1
+ module Nacjac
2
+ class Cannon
3
+ def initialize(target_url, thread_num, duration)
4
+ @target_url = target_url
5
+ @thread_num = thread_num
6
+ @duration = duration
7
+ @request_times = []
8
+ end
9
+
10
+ def blast
11
+ end_time = Time.now + @duration
12
+ while (Time.now < end_time)
13
+ @request_times << shoot
14
+ end
15
+ end
16
+
17
+ def report
18
+ @request_times.flatten!
19
+ total = @request_times.count
20
+ failed = total - @request_times.compact.count
21
+ total_time = @request_times.compact.inject(0){|a, b| a + b}
22
+ puts "Total Requests : #{total}"
23
+ puts "Failed Requests : #{failed}"
24
+ puts "Average Time : #{total_time/total}"
25
+ end
26
+
27
+ private
28
+ def shoot
29
+ futures = []
30
+ (1..@thread_num).each do |t|
31
+ @projectile = Projectile.new(@target_url)
32
+ futures << @projectile.future.launch
33
+ end
34
+ futures.map(&:value)
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,25 @@
1
+ require 'celluloid'
2
+ require 'faraday'
3
+
4
+ module Nacjac
5
+ class Projectile
6
+ include Celluloid
7
+
8
+ def initialize(target_url)
9
+ @target_url = target_url
10
+ @conn = Faraday.new(:url => 'http://sushi.com') do |faraday|
11
+ faraday.request :url_encoded
12
+ faraday.adapter Faraday.default_adapter
13
+ end
14
+ end
15
+
16
+ def launch
17
+ start_time = Time.now
18
+ response = @conn.get @target_url
19
+ end_time = Time.now
20
+ end_time - start_time
21
+ rescue
22
+ nil
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,3 @@
1
+ module Nacjac
2
+ VERSION = "0.0.1"
3
+ end
data/lib/nacjac.rb ADDED
@@ -0,0 +1,3 @@
1
+ require 'nacjac/version'
2
+ require 'nacjac/projectile'
3
+ require 'nacjac/cannon'
data/nacjac.gemspec ADDED
@@ -0,0 +1,18 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+
4
+ require 'nacjac/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "nacjac"
8
+ gem.version = Nacjac::VERSION
9
+ gem.authors = ["Edwin Tunggawan"]
10
+ gem.email = ["vcc.edwint@gmail.com"]
11
+ gem.description = "Measuring web response time"
12
+ gem.summary = "Send requests to a web page and measure the average response time"
13
+ gem.homepage = "https://github.com/sdsdkkk/nacjac"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = ["nacjac"]
17
+ gem.require_paths = ["lib", "lib/nacjac"]
18
+ end
metadata ADDED
@@ -0,0 +1,56 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nacjac
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Edwin Tunggawan
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-08-28 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Measuring web response time
14
+ email:
15
+ - vcc.edwint@gmail.com
16
+ executables:
17
+ - nacjac
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - ".gitignore"
22
+ - Gemfile
23
+ - Gemfile.lock
24
+ - LICENSE
25
+ - README.md
26
+ - bin/nacjac
27
+ - lib/nacjac.rb
28
+ - lib/nacjac/cannon.rb
29
+ - lib/nacjac/projectile.rb
30
+ - lib/nacjac/version.rb
31
+ - nacjac.gemspec
32
+ homepage: https://github.com/sdsdkkk/nacjac
33
+ licenses: []
34
+ metadata: {}
35
+ post_install_message:
36
+ rdoc_options: []
37
+ require_paths:
38
+ - lib
39
+ - lib/nacjac
40
+ required_ruby_version: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ required_rubygems_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ requirements: []
51
+ rubyforge_project:
52
+ rubygems_version: 2.2.2
53
+ signing_key:
54
+ specification_version: 4
55
+ summary: Send requests to a web page and measure the average response time
56
+ test_files: []