Simultaneously URL call, is it possible?

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.

···

--
Posted via http://www.ruby-forum.com/.

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

Bret

···

On Thu, Jul 24, 2008 at 3:09 PM, Toki Toki <toki84@gmail.com> wrote:

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.
--
Posted via http://www.ruby-forum.com/\.

--
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), Bret's Recommendations

matu wrote:

Toki Toki wrote:

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/&#39;\))}
end

Thanks for the answer.

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

Thanks.

···

--
Posted via http://www.ruby-forum.com/\.

Bret Pettichord wrote:

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?

···

--
Posted via http://www.ruby-forum.com/\.

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:

%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

···

El Jueves, 24 de Julio de 2008, Toki Toki escribió:

--
Iñaki Baz Castillo

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

Bret

···

On Thu, Jul 24, 2008 at 4:04 PM, Toki Toki <toki84@gmail.com> wrote:

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?

--
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), Bret's Recommendations

Iñaki Baz Castillo wrote:

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:

> %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/&#39;\))}
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/&#39;\))}
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...

···

El Jueves, 24 de Julio de 2008, Toki Toki escribió:

--
Posted via http://www.ruby-forum.com/\.

S2 wrote:

Toki Toki wrote:

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

Yes.

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...

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/&#39;\))
   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.

···

--
Posted via http://www.ruby-forum.com/\.

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

···

On Fri, Jul 25, 2008 at 1:25 PM, Toki Toki <toki84@gmail.com> wrote:

> require 'net/http'
> require 'uri'
> 10.times do
> Thread.new do
> Net::HTTP.get_response(URI.parse('http://www.google.com/&#39;&lt;http://www.google.com/'&gt;
))
> 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.

--
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), Bret's Recommendations

matu wrote:

Toki Toki wrote:

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.

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/&#39;\))}
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/&#39;\))}
end
sleep(10000)

···

--
Posted via http://www.ruby-forum.com/\.

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/

···

On Jul 25, 2008, at 1:02 PM, Bret Pettichord wrote:

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.

--
we can deny everything, except that we have the possibility of being better. simply reflect on that.
h.h. the 14th dalai lama

Bret Pettichord wrote:

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/&#39;\))}
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?

···

On Fri, Jul 25, 2008 at 1:25 PM, Toki Toki <toki84@gmail.com> wrote:

--
Posted via http://www.ruby-forum.com/\.

matu wrote:

Toki Toki wrote:

Ok, this would work well?

did you try? WFM.

Of course, but I don't know if on the google servers I've send 10
request or only 1, I'll try monday...

···

--
Posted via http://www.ruby-forum.com/\.

Ara Howard wrote:

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.

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.

···

On Jul 25, 2008, at 1:02 PM, Bret Pettichord wrote:

--
Posted via http://www.ruby-forum.com/\.

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/

···

On Jul 25, 2008, at 2:19 PM, Toki Toki wrote:

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

--
we can deny everything, except that we have the possibility of being better. simply reflect on that.
h.h. the 14th dalai lama

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

···

2008/7/25 Toki Toki <toki84@gmail.com>:

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

...

Ara Howard wrote:

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...

···

--
Posted via http://www.ruby-forum.com/\.

Pit Capitain wrote:

···

2008/7/25 Toki Toki <toki84@gmail.com>:

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

...

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...
--
Posted via http://www.ruby-forum.com/\.