Simultaneously URL call, is it possible?

T

Toki Toki

Hi to all!

I need to test a functionality of an application before to go in
production environment, unfortunately it isn't a ruby application, I
thought to use a script that will call a url 5 times simultaneously or
at least systematically, let's say every 10 seconds, is it possible with
ruby? Maybe using watir (but I don't think it can do simultaneus call)?
Any hint?

Thanks.

Best regards.
 
B

Bret Pettichord

[Note: parts of this message were removed to make it a legal post.]

Watir can support multiple, concurrent calls. Create separate Watir::IE.new
in each thread.

Bret



Hi to all!

I need to test a functionality of an application before to go in
production environment, unfortunately it isn't a ruby application, I
thought to use a script that will call a url 5 times simultaneously or
at least systematically, let's say every 10 seconds, is it possible with
ruby? Maybe using watir (but I don't think it can do simultaneus call)?
Any hint?

Thanks.

Best regards.


--
Bret Pettichord
CTO, WatirCraft LLC, http://www.watircraft.com
Lead Developer, Watir, http://wtr.rubyforge.org
Blog (Essays), http://www.io.com/~wazmo/blog
MiniBlog (Links), http://feeds.feedburner.com/bretshotlist
 
T

Toki Toki

matu said:
Toki said:
I need to test a functionality of an application before to go in
production environment, unfortunately it isn't a ruby application, I
thought to use a script that will call a url 5 times simultaneously or
at least systematically, let's say every 10 seconds, is it possible with
ruby? Maybe using watir (but I don't think it can do simultaneus call)?
Any hint?

Yes. You could spawn threads and call the url from those.
%w[uri net/http].each{|l|require l}
10.times do
Thread.new
{Net::HTTP.get_response(URI.parse('http://www.google.com/'))}
end

Thanks for the answer.

It's not clear the first line of your code, could you explain it?

Thanks.
 
T

Toki Toki

Bret said:
Watir can support multiple, concurrent calls. Create separate
Watir::IE.new
in each thread.

Bret

Thanks, I didn't know that watir support concurrent calls. If I create
multiple Watir::IE.new then they will use the same IE process?
 
I

Iñaki Baz Castillo

El Jueves, 24 de Julio de 2008, Toki Toki escribi=C3=B3:
It's not clear the first line of your code, could you explain it?

%w[uri net/http].each{|l|require l}


%w[aaa bbb ccc] is an Array:

irb> %w[aaa bbb ccc]=20
["aaa", "bbb", "ccc"]

so it's a "each" method of an Array so:

require "uri"
require "net/http"

Well, I think is too much freak XD


=2D-=20
I=C3=B1aki Baz Castillo
 
B

Bret Pettichord

[Note: parts of this message were removed to make it a legal post.]

Thanks, I didn't know that watir support concurrent calls. If I create
multiple Watir::IE.new then they will use the same IE process?

Yes. But you can use Watir::IE.new_process instead and then each one will be
in a separate process.

Bret



--
Bret Pettichord
CTO, WatirCraft LLC, http://www.watircraft.com
Lead Developer, Watir, http://wtr.rubyforge.org
Blog (Essays), http://www.io.com/~wazmo/blog
MiniBlog (Links), http://feeds.feedburner.com/bretshotlist
 
T

Toki Toki

Iñaki Baz Castillo said:
El Jueves, 24 de Julio de 2008, Toki Toki escribió:
It's not clear the first line of your code, could you explain it?

%w[uri net/http].each{|l|require l}


%w[aaa bbb ccc] is an Array:

irb> %w[aaa bbb ccc]
["aaa", "bbb", "ccc"]

so it's a "each" method of an Array so:

require "uri"
require "net/http"

Well, I think is too much freak XD

Ok, so this:

%w[uri net/http].each{|l|require l}
10.times do
Thread.new
{Net::HTTP.get_response(URI.parse('http://www.google.com/'))}
end

is equal to this:

require 'net/http'
require 'uri'
10.times do
Thread.new
{Net::HTTP.get_response(URI.parse('http://www.google.com/'))}
end

Good, I've never used require with array.

But if I run the code above I get an error: url_call.rb:4: odd number
list for Hash

I think it's because of the curly braces that are viewed like an hash,
right? I don't know how Thread works in Ruby, but it seems that the
statements in the curly braces need to be on the same line as Thread.new
otherwise it give the error above...
 
T

Toki Toki

S2 said:
Thread.new gets a block, so you could as well write the code above as:

require 'net/http'
require 'uri'
10.times do
Thread.new do
Net::HTTP.get_response(URI.parse('http://www.google.com/'))
end
end

maybe this is a bit more clear to you?

Thanks, I saw that the first curly brace need to be on the same line of
Thread.new.

I've tested the code above, but it seems that it doesn't work like I
thought because on the web server and application server logs I saw only
one request when I run the code (of course with the correct address),
maybe my statement isn't clear: I need to call a URL multiple time, like
if I press F5 on the browser...I've found a way using Watir example, but
without it would be better so I can use the script on any platform.

Thanks.

Best regards.
 
B

Bret Pettichord

[Note: parts of this message were removed to make it a legal post.]

Thanks, I saw that the first curly brace need to be on the same line of
Thread.new.

I've tested the code above, but it seems that it doesn't work like I
thought because on the web server and application server logs I saw only
one request when I run the code (of course with the correct address),
maybe my statement isn't clear: I need to call a URL multiple time, like
if I press F5 on the browser...I've found a way using Watir example, but
without it would be better so I can use the script on any platform.
I think this needs a call to Thread#join after all the the threads have been
created. Otherwise the script will exit before the threads have executed.

Bret



--
Bret Pettichord
CTO, WatirCraft LLC, http://www.watircraft.com
Lead Developer, Watir, http://wtr.rubyforge.org
Blog (Essays), http://www.io.com/~wazmo/blog
MiniBlog (Links), http://feeds.feedburner.com/bretshotlist
 
T

Toki Toki

Bret said:
I think this needs a call to Thread#join after all the the threads have
been
created. Otherwise the script will exit before the threads have
executed.

Bret

Something like this:

require 'net/http'
require 'uri'

threads = []
10.times do
threads << Thread.new
{Net::HTTP.get_response(URI.parse('http://www.google.com/'))}
end
threads.each {|x| x.join}

But if the original script exit before the threads have executed why I
see a request and not 0 request?
 
T

Toki Toki

Ara said:
why make it hard?


# gem install threadify

require 'rubygems'
require 'open-uri'
require 'threadify'

results =
%w( http://google.com http://yahoo.com http://
foo.bar.com ).threadify do |uri|
open(uri){|fd| fd.read}
end


a @ http://codeforpeople.com/

Thanks for the help.

It seems that I've some problem with the gem threadify or rubygems...I i
run the code that you've poste I get the error:
ruby threadify.rb
/threadify.rb:6: undefined method `threadify' for #<Array:0x38ce1c0>
(NoMethodError)
from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in
`gem_original_require'
from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in
`require'
from threadify.rb:3
Exit code: 1

This is the require in irb:

irb(main):001:0> require 'rubygems'
=> false
irb(main):002:0> require 'threadify'
=> true

I've try to run the threadify sample
(http://www.ruby-forum.com/topic/159362) still no way...

How can I solve this problem?

Thanks.
 
A

ara.t.howard

It seems that I've some problem with the gem threadify or
rubygems...I i
run the code that you've poste I get the error:

./threadify.rb:6: undefined method `threadify' for #<Array:0x38ce1c0>
(NoMethodError)
from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in
`gem_original_require'
from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in
`require'
from threadify.rb:3

This is the require in irb:

irb(main):001:0> require 'rubygems'
=> false
irb(main):002:0> require 'threadify'
=> true



cfp:~ > cat a.rb
require 'rubygems'
require 'open-uri'
require 'threadify'

uris = %w( http://google.com http://yahoo.com )

results =
%w( http://google.com http://yahoo.com ).threadify do |uri|
open(uri){|fd| fd.read}
end

puts results.map{|result| result[0, 42]}







cfp:~ > ruby a.rb
<html><head><meta http-equiv="content-type
<html>
<head>
<title>Yahoo!</title>
<meta






a @ http://codeforpeople.com/
 
T

Toki Toki

matu said:
It works if you run it from irb. If you call it from a script just call
Thread.join like Bret sad, or insert a sleep(10000) at the en of the
script.

Ok, this would work well?

require 'net/http'
require 'uri'

threads = []
10.times do
threads << Thread.new
{Net::HTTP.get_response(URI.parse('http://www.google.com/'))}
end
threads.each {|x| x.join}

Or your original script with the sleep:

require 'net/http'
require 'uri'
10.times do
Thread.new
{Net::HTTP.get_response(URI.parse('http://www.google.com/'))}
end
sleep(10000)
 
T

Toki Toki

Ara said:
cfp:~ > cat a.rb
require 'rubygems'
require 'open-uri'
require 'threadify'

uris = %w( http://google.com http://yahoo.com )

results =
%w( http://google.com http://yahoo.com ).threadify do |uri|
open(uri){|fd| fd.read}
end

puts results.map{|result| result[0, 42]}

cfp:~ > ruby a.rb
<html><head><meta http-equiv="content-type
<html>
<head>
<title>Yahoo!</title>
<meta

a @ http://codeforpeople.com/

Thnaks for the help, but I keep getting the same error, it seems like
threadify isn't recognized or installed well...
 
P

Pit Capitain

2008/7/25 Toki Toki said:
It seems that I've some problem with the gem threadify or rubygems...I i
run the code that you've poste I get the error:

...

You shouldn't give the test script the same name as the file you want
to require. Rename "threadify.rb" to something like
"threadify-test.rb" and it should work.

Regards,
Pit
 
T

Toki Toki

Pit said:
You shouldn't give the test script the same name as the file you want
to require. Rename "threadify.rb" to something like
"threadify-test.rb" and it should work.

Regards,
Pit

Thanks, but I keep getting the same error even changing the name of the
script...I have this error only if I require an "external" gem...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,202
Messages
2,571,057
Members
47,662
Latest member
sxarexu

Latest Threads

Top