Created
August 8, 2010 15:39
-
-
Save asim/514162 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/usr/bin/env ruby | |
require 'net/smtp' | |
FILE = File.readlines("foo1") | |
class Email | |
def initialize | |
@smtp = Net::SMTP.new('127.0.0.1', 2025) | |
end | |
def post(from, to) | |
msgstr = <<EOF | |
From: <#{from}> | |
To: <#{to}> | |
Subject: Fooo | |
Date: #{Time.now} | |
Message-Id: <#{Time.now.to_i}.#{from}> | |
MIME-Version: 1.0 | |
Content-type: text/plain | |
#{FILE} | |
EOF | |
@smtp.start do |smtp| | |
smtp.send_message msgstr, from, to | |
end | |
end | |
end | |
def nonthreaded | |
counter = 0 | |
email = Email.new | |
while counter < 100 | |
email.post("[email protected]", "[email protected]") | |
puts counter += 1 | |
end | |
end | |
def threads | |
require 'thread' | |
q = Queue.new | |
1000.times do | |
Thread.new do | |
1.times do |i| | |
q << Email.new | |
end | |
end | |
end | |
puts "Queued" | |
f = Thread.new do | |
1000.times do |k| | |
email = q.shift | |
email.post("[email protected]", "[email protected]") | |
puts k | |
end | |
end | |
f.join | |
end | |
send(ARGV[0]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment