473,245 Members | 1,725 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,245 software developers and data experts.

How many threads to create?

Hi am creating a email application that needs to mail out a very large
amount of emails. I have created a multithreaded c# application that using
message queuing. I have created a threadpool of 5 threads and each thread
checks the queue, receives the message and sends an email. How do I
determine the right amount of threads to create?

Thanks,

S
Nov 15 '05 #1
6 3273
The most suitable number of threads for a SPAM engine is exactly 357... ;)

"SamIAm" <sa****@rubbachicken.com> wrote in message
news:ey**************@tk2msftngp13.phx.gbl...
Hi am creating a email application that needs to mail out a very large
amount of emails. I have created a multithreaded c# application that using
message queuing. I have created a threadpool of 5 threads and each thread
checks the queue, receives the message and sends an email. How do I
determine the right amount of threads to create?

Thanks,

S

Nov 15 '05 #2
42 :D

I use for my mailing purposes Glock easy mail pro. Not spam , but for
testing mailers etc and so on.
"Malkocoglu" <a@b.com> wrote in message
news:ep*************@TK2MSFTNGP10.phx.gbl...
The most suitable number of threads for a SPAM engine is exactly 357... ;)
"SamIAm" <sa****@rubbachicken.com> wrote in message
news:ey**************@tk2msftngp13.phx.gbl...
Hi am creating a email application that needs to mail out a very large
amount of emails. I have created a multithreaded c# application that using message queuing. I have created a threadpool of 5 threads and each thread checks the queue, receives the message and sends an email. How do I
determine the right amount of threads to create?

Thanks,

S


Nov 15 '05 #3
Ha-ha

Nope thankfully its not spam! It is part of a new application we are
launching and has the potential to have 4 000 000+ members who need to
receive a weekly email.

S

"Malkocoglu" <a@b.com> wrote in message
news:ep*************@TK2MSFTNGP10.phx.gbl...
The most suitable number of threads for a SPAM engine is exactly 357... ;)
"SamIAm" <sa****@rubbachicken.com> wrote in message
news:ey**************@tk2msftngp13.phx.gbl...
Hi am creating a email application that needs to mail out a very large
amount of emails. I have created a multithreaded c# application that using message queuing. I have created a threadpool of 5 threads and each thread checks the queue, receives the message and sends an email. How do I
determine the right amount of threads to create?

Thanks,

S


Nov 15 '05 #4
Thanks for all the replies.

Here is some sample code I have. Feel free to take a look and make any
comments:
The Form:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Messaging;
using System.Threading;

using CardFinder;

namespace TestHandler
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.GroupBox grpSendMails;
private System.Windows.Forms.TextBox txtMailCount;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Button btnReceiveMail;
private System.Windows.Forms.Button btnSendMail;
private System.Windows.Forms.TextBox txtTo;
private System.Windows.Forms.GroupBox grpReceive;
private System.Windows.Forms.TextBox txtThreadCount;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;

public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();

//
// TODO: Add any constructor code after InitializeComponent call
//
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.btnReceiveMail = new System.Windows.Forms.Button();
this.grpSendMails = new System.Windows.Forms.GroupBox();
this.label1 = new System.Windows.Forms.Label();
this.txtMailCount = new System.Windows.Forms.TextBox();
this.btnSendMail = new System.Windows.Forms.Button();
this.txtTo = new System.Windows.Forms.TextBox();
this.grpReceive = new System.Windows.Forms.GroupBox();
this.txtThreadCount = new System.Windows.Forms.TextBox();
this.grpSendMails.SuspendLayout();
this.grpReceive.SuspendLayout();
this.SuspendLayout();
//
// btnReceiveMail
//
this.btnReceiveMail.Location = new System.Drawing.Point(248, 48);
this.btnReceiveMail.Name = "btnReceiveMail";
this.btnReceiveMail.TabIndex = 1;
this.btnReceiveMail.Text = "Recieve";
this.btnReceiveMail.Click += new
System.EventHandler(this.btnReceiveMail_Click);
//
// grpSendMails
//
this.grpSendMails.Controls.AddRange(new System.Windows.Forms.Control[] {
this.txtTo,
this.label1,
this.txtMailCount,
this.btnSendMail});
this.grpSendMails.Location = new System.Drawing.Point(16, 16);
this.grpSendMails.Name = "grpSendMails";
this.grpSendMails.Size = new System.Drawing.Size(384, 112);
this.grpSendMails.TabIndex = 2;
this.grpSendMails.TabStop = false;
this.grpSendMails.Text = "Send Mails";
//
// label1
//
this.label1.Location = new System.Drawing.Point(32, 64);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(80, 24);
this.label1.TabIndex = 3;
this.label1.Text = "No of mails:";
//
// txtMailCount
//
this.txtMailCount.Location = new System.Drawing.Point(120, 64);
this.txtMailCount.Name = "txtMailCount";
this.txtMailCount.Size = new System.Drawing.Size(112, 20);
this.txtMailCount.TabIndex = 2;
this.txtMailCount.Text = "100000";
//
// btnSendMail
//
this.btnSendMail.Location = new System.Drawing.Point(240, 64);
this.btnSendMail.Name = "btnSendMail";
this.btnSendMail.TabIndex = 1;
this.btnSendMail.Text = "Send";
this.btnSendMail.Click += new
System.EventHandler(this.btnSendMail_Click);
//
// txtTo
//
this.txtTo.Location = new System.Drawing.Point(120, 32);
this.txtTo.Name = "txtTo";
this.txtTo.Size = new System.Drawing.Size(112, 20);
this.txtTo.TabIndex = 4;
this.txtTo.Text = "sa****@rubbachicken.com";
//
// grpReceive
//
this.grpReceive.Controls.AddRange(new System.Windows.Forms.Control[] {
this.txtThreadCount,
this.btnReceiveMail});
this.grpReceive.Location = new System.Drawing.Point(16, 136);
this.grpReceive.Name = "grpReceive";
this.grpReceive.Size = new System.Drawing.Size(384, 128);
this.grpReceive.TabIndex = 3;
this.grpReceive.TabStop = false;
this.grpReceive.Text = "Receive Mails";
//
// txtThreadCount
//
this.txtThreadCount.Location = new System.Drawing.Point(136, 48);
this.txtThreadCount.Name = "txtThreadCount";
this.txtThreadCount.TabIndex = 2;
this.txtThreadCount.Text = "5";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(416, 317);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.grpReceive,
this.grpSendMails});
this.Name = "Form1";
this.Text = "Form1";
this.grpSendMails.ResumeLayout(false);
this.grpReceive.ResumeLayout(false);
this.ResumeLayout(false);

}
#endregion

/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}

/// <summary>
/// Creates test emails
/// </summary>
private void btnSendMail_Click(object sender, System.EventArgs e)
{
// Create a new mailer instance
Mailer mailer = new Mailer();
try
{
// Create x number of test messages in the queue
mailer.SendMail(txtTo.Text.Trim(),
Convert.ToInt32(txtMailCount.Text.Trim()));
MessageBox.Show("Done");
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}

/// <summary>
/// Starts threads to create emails from the messages in the queue
/// </summary>
private void btnReceiveMail_Click(object sender, System.EventArgs e)
{
// How many threads
int THREAD_COUNT = Convert.ToInt32(txtThreadCount.Text.Trim());
int loop;
Mailer mailer = new Mailer();
Thread[] ThreadArray = new Thread[THREAD_COUNT];
// Loop through and create listener threads that process the messages in
the queue
for(loop = 0; loop < THREAD_COUNT; loop++)
{
ThreadArray[loop] = new Thread(new ThreadStart(mailer.Listen));
ThreadArray[loop].Start();
}
}
}
}

The Mailer Class:
using System;
using System.Messaging;
using System.Threading;
using System.Web.Mail;

namespace CardFinder
{
/// <summary>
/// Summary description for Mailer.
/// </summary>
public class Mailer
{

public Mailer()
{
}
public void SendMail(string Email)
{
SendMail(Email, 1);
}

/// <summary>
/// Creates messages in the queue
/// </summary>
/// <param name="Email">Email to send to</param>
/// <param name="MailCount">No of messages to create</param>
public void SendMail(string Email, int MailCount)
{
// Get the queue
MessageQueue CardFinderQueue = new
MessageQueue(@".\Private$\CardFinderMails");
// Create messages
for(int loop = 0;loop < MailCount;loop++)
{
MailMessage msg = new MailMessage();
msg.Email = Email;
CardFinderQueue.Send(msg, "Email Test");
}
}

/// <summary>
/// Processes the queue
/// </summary>
public void Listen()
{
// Get the queue
MessageQueue CardFinderQueue = new
MessageQueue(@".\Private$\CardFinderMails");
CardFinderQueue.Formatter = new XmlMessageFormatter(new Type[]
{typeof(CardFinder.MailMessage)});
Message qmsg = null;
while (true)
{
try
{
System.Threading.Thread.Sleep(100);

qmsg = CardFinderQueue.Receive(new TimeSpan(0,0,0,1));
MailMessage msg = (MailMessage)qmsg.Body;

string email = msg.Email;
SmtpMail.Send("so*****@myco.com", email, "CardFinder Test",
"<html><body><h1>Test</h1></body></html>");
}
// Not sure what the following is for :-)
catch(ThreadInterruptedException threadEx)
{
qmsg.Dispose();
CardFinderQueue.Dispose();
break;
}
catch(Exception Ex)
{
}
}
}
}
}

The MailMessage Class:
using System;

namespace CardFinder
{
/// <summary>
/// Summary description for MailMessage.
/// </summary>
public class MailMessage
{
private string _email;

public string Email
{
get
{
return _email;
}
set
{
_email = value;
}
}
}
}
Thanks

S
"SamIAm" <sa****@rubbachicken.com> wrote in message
news:ey**************@tk2msftngp13.phx.gbl...
Hi am creating a email application that needs to mail out a very large
amount of emails. I have created a multithreaded c# application that using
message queuing. I have created a threadpool of 5 threads and each thread
checks the queue, receives the message and sends an email. How do I
determine the right amount of threads to create?

Thanks,

S

Nov 15 '05 #5
The right number is going to depend on the amount of bandwidth you have
available, and how fast you want to send out messages. It's very likely that
with 5 threads, you should be able to saturate a single network interface
with 100Mbs, or at least reach near peak bandwith for you OS/Hardware
configuration. You should probably concentrate more on how you're going to
send out 4,000,000 email messages without disrupting connectivity to the
rest of the world on the network where the spaminator is located, or
gettting blacklisted by ISPs. (sorry, sending out 4,000,000 messages is spam
even if they ask for it)

FYI, 4,000,000 evenly distributed over a 10 hour peroid is about 110 per
second. If each message where say 500 bytes, that's ~ 440,000 bits per
second. or 1/2 the bandwith of a T1. It's also likely that your weekly
newsletter if going to be in html and have images, so pro-rate appropriately
for the 500 bytes. If you assumed 5K, then you're talking days to send
4,000,000 messages without several big pipes. The slickest threadpool in the
world isn't going to help.

"SamIAm" <sa****@rubbachicken.com> wrote in message
news:up**************@tk2msftngp13.phx.gbl...
Ha-ha

Nope thankfully its not spam! It is part of a new application we are
launching and has the potential to have 4 000 000+ members who need to
receive a weekly email.

S

"Malkocoglu" <a@b.com> wrote in message
news:ep*************@TK2MSFTNGP10.phx.gbl...
The most suitable number of threads for a SPAM engine is exactly 357...

;)

"SamIAm" <sa****@rubbachicken.com> wrote in message
news:ey**************@tk2msftngp13.phx.gbl...
Hi am creating a email application that needs to mail out a very large
amount of emails. I have created a multithreaded c# application that using message queuing. I have created a threadpool of 5 threads and each thread checks the queue, receives the message and sends an email. How do I
determine the right amount of threads to create?

Thanks,

S



Nov 15 '05 #6
Yes, I quickly recommend sending a LINK to your website where the newsletter
is actually hosted. Either that or you should hire an external entity to do
your mailing for you. By doing so, you'll already have their experience of
solving the various problems pointed out by Jacob.

--
Justin Rogers
DigiTec Web Consultants, LLC.

"Jacob Gladish" <ja**********@yahoo.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
The right number is going to depend on the amount of bandwidth you have
available, and how fast you want to send out messages. It's very likely that with 5 threads, you should be able to saturate a single network interface
with 100Mbs, or at least reach near peak bandwith for you OS/Hardware
configuration. You should probably concentrate more on how you're going to
send out 4,000,000 email messages without disrupting connectivity to the
rest of the world on the network where the spaminator is located, or
gettting blacklisted by ISPs. (sorry, sending out 4,000,000 messages is spam even if they ask for it)

FYI, 4,000,000 evenly distributed over a 10 hour peroid is about 110 per
second. If each message where say 500 bytes, that's ~ 440,000 bits per
second. or 1/2 the bandwith of a T1. It's also likely that your weekly
newsletter if going to be in html and have images, so pro-rate appropriately for the 500 bytes. If you assumed 5K, then you're talking days to send
4,000,000 messages without several big pipes. The slickest threadpool in the world isn't going to help.

"SamIAm" <sa****@rubbachicken.com> wrote in message
news:up**************@tk2msftngp13.phx.gbl...
Ha-ha

Nope thankfully its not spam! It is part of a new application we are
launching and has the potential to have 4 000 000+ members who need to
receive a weekly email.

S

"Malkocoglu" <a@b.com> wrote in message
news:ep*************@TK2MSFTNGP10.phx.gbl...
The most suitable number of threads for a SPAM engine is exactly 357...
;)

"SamIAm" <sa****@rubbachicken.com> wrote in message
news:ey**************@tk2msftngp13.phx.gbl...
> Hi am creating a email application that needs to mail out a very

large > amount of emails. I have created a multithreaded c# application that

using
> message queuing. I have created a threadpool of 5 threads and each

thread
> checks the queue, receives the message and sends an email. How do I
> determine the right amount of threads to create?
>
> Thanks,
>
> S
>



Nov 15 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: MikeE | last post by:
Hi all, What's the best way to queue up and wait for number of threads to complete. This problem was trivial in VC++ 6 but I'm finding it rather hard to solve in VB.NET. My calculations run...
6
by: m | last post by:
Hello, I have an application that processes thousands of files each day. The filenames and various related file information is retrieved, related filenames are associate and placed in a linked...
9
by: Tpool | last post by:
hi, How to create the more than 25 threads in threadpool. i tried more than 25 threads in web request, but it shows an error. how can i have my threads to some 25 or more ,check the status of the...
3
by: mjheitland | last post by:
Hi, I like to know how many threads are used by a Threading.Timer object. When I create a Threading.Timer object calling a short running method every 5 seconds I expected to have one additional...
11
by: mareal | last post by:
I am trying to write a basic load balancer (in our web service) solution. The purpose of this load balancer is to keep an array updated with server status. We have several servers that can be...
4
by: MSDousti | last post by:
Hi I have written a VB .NET app, which uses several threads. I thought that when the user closes the main window (when MainForm.closed event occures, and I call application.exit) all running...
6
by: Alexander Walker | last post by:
Hello Is it inefficient to create an application that has many threads that individually may do a small amount of work over a given period of time as opposed to an application that has a...
4
by: tdahsu | last post by:
All, I'd appreciate any help. I've got a list of files in a directory, and I'd like to iterate through that list and process each one. Rather than do that serially, I was thinking I should...
167
by: darren | last post by:
Hi I have to write a multi-threaded program. I decided to take an OO approach to it. I had the idea to wrap up all of the thread functions in a mix-in class called Threadable. Then when an...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.