473,909 Members | 4,177 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3338
The most suitable number of threads for a SPAM engine is exactly 357... ;)

"SamIAm" <sa****@rubbach icken.com> wrote in message
news:ey******** ******@tk2msftn gp13.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******** *****@TK2MSFTNG P10.phx.gbl...
The most suitable number of threads for a SPAM engine is exactly 357... ;)
"SamIAm" <sa****@rubbach icken.com> wrote in message
news:ey******** ******@tk2msftn gp13.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******** *****@TK2MSFTNG P10.phx.gbl...
The most suitable number of threads for a SPAM engine is exactly 357... ;)
"SamIAm" <sa****@rubbach icken.com> wrote in message
news:ey******** ******@tk2msftn gp13.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.Collecti ons;
using System.Componen tModel;
using System.Windows. Forms;
using System.Data;
using System.Messagin g;
using System.Threadin g;

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.Componen tModel.Containe r components = null;

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

//
// TODO: Add any constructor code after InitializeCompo nent call
//
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Disp ose();
}
}
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 InitializeCompo nent()
{
this.btnReceive Mail = new System.Windows. Forms.Button();
this.grpSendMai ls = new System.Windows. Forms.GroupBox( );
this.label1 = new System.Windows. Forms.Label();
this.txtMailCou nt = new System.Windows. Forms.TextBox() ;
this.btnSendMai l = new System.Windows. Forms.Button();
this.txtTo = new System.Windows. Forms.TextBox() ;
this.grpReceive = new System.Windows. Forms.GroupBox( );
this.txtThreadC ount = new System.Windows. Forms.TextBox() ;
this.grpSendMai ls.SuspendLayou t();
this.grpReceive .SuspendLayout( );
this.SuspendLay out();
//
// btnReceiveMail
//
this.btnReceive Mail.Location = new System.Drawing. Point(248, 48);
this.btnReceive Mail.Name = "btnReceiveMail ";
this.btnReceive Mail.TabIndex = 1;
this.btnReceive Mail.Text = "Recieve";
this.btnReceive Mail.Click += new
System.EventHan dler(this.btnRe ceiveMail_Click );
//
// grpSendMails
//
this.grpSendMai ls.Controls.Add Range(new System.Windows. Forms.Control[] {
this.txtTo,
this.label1,
this.txtMailCou nt,
this.btnSendMai l});
this.grpSendMai ls.Location = new System.Drawing. Point(16, 16);
this.grpSendMai ls.Name = "grpSendMai ls";
this.grpSendMai ls.Size = new System.Drawing. Size(384, 112);
this.grpSendMai ls.TabIndex = 2;
this.grpSendMai ls.TabStop = false;
this.grpSendMai ls.Text = "Send Mails";
//
// label1
//
this.label1.Loc ation = new System.Drawing. Point(32, 64);
this.label1.Nam e = "label1";
this.label1.Siz e = new System.Drawing. Size(80, 24);
this.label1.Tab Index = 3;
this.label1.Tex t = "No of mails:";
//
// txtMailCount
//
this.txtMailCou nt.Location = new System.Drawing. Point(120, 64);
this.txtMailCou nt.Name = "txtMailCou nt";
this.txtMailCou nt.Size = new System.Drawing. Size(112, 20);
this.txtMailCou nt.TabIndex = 2;
this.txtMailCou nt.Text = "100000";
//
// btnSendMail
//
this.btnSendMai l.Location = new System.Drawing. Point(240, 64);
this.btnSendMai l.Name = "btnSendMai l";
this.btnSendMai l.TabIndex = 1;
this.btnSendMai l.Text = "Send";
this.btnSendMai l.Click += new
System.EventHan dler(this.btnSe ndMail_Click);
//
// txtTo
//
this.txtTo.Loca tion = new System.Drawing. Point(120, 32);
this.txtTo.Name = "txtTo";
this.txtTo.Size = new System.Drawing. Size(112, 20);
this.txtTo.TabI ndex = 4;
this.txtTo.Text = "sa****@rubbach icken.com";
//
// grpReceive
//
this.grpReceive .Controls.AddRa nge(new System.Windows. Forms.Control[] {
this.txtThreadC ount,
this.btnReceive Mail});
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.txtThreadC ount.Location = new System.Drawing. Point(136, 48);
this.txtThreadC ount.Name = "txtThreadCount ";
this.txtThreadC ount.TabIndex = 2;
this.txtThreadC ount.Text = "5";
//
// Form1
//
this.AutoScaleB aseSize = new System.Drawing. Size(5, 13);
this.ClientSize = new System.Drawing. Size(416, 317);
this.Controls.A ddRange(new System.Windows. Forms.Control[] {
this.grpReceive ,
this.grpSendMai ls});
this.Name = "Form1";
this.Text = "Form1";
this.grpSendMai ls.ResumeLayout (false);
this.grpReceive .ResumeLayout(f alse);
this.ResumeLayo ut(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_Cli ck(object sender, System.EventArg s e)
{
// Create a new mailer instance
Mailer mailer = new Mailer();
try
{
// Create x number of test messages in the queue
mailer.SendMail (txtTo.Text.Tri m(),
Convert.ToInt32 (txtMailCount.T ext.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.EventArg s 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(mai ler.Listen));
ThreadArray[loop].Start();
}
}
}
}

The Mailer Class:
using System;
using System.Messagin g;
using System.Threadin g;
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">Em ail 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$\Card FinderMails");
// 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$\Card FinderMails");
CardFinderQueue .Formatter = new XmlMessageForma tter(new Type[]
{typeof(CardFin der.MailMessage )});
Message qmsg = null;
while (true)
{
try
{
System.Threadin g.Thread.Sleep( 100);

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

string email = msg.Email;
SmtpMail.Send(" so*****@myco.co m", email, "CardFinder Test",
"<html><body><h 1>Test</h1></body></html>");
}
// Not sure what the following is for :-)
catch(ThreadInt erruptedExcepti on 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****@rubbach icken.com> wrote in message
news:ey******** ******@tk2msftn gp13.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****@rubbach icken.com> wrote in message
news:up******** ******@tk2msftn gp13.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******** *****@TK2MSFTNG P10.phx.gbl...
The most suitable number of threads for a SPAM engine is exactly 357...

;)

"SamIAm" <sa****@rubbach icken.com> wrote in message
news:ey******** ******@tk2msftn gp13.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**********@y ahoo.com> wrote in message
news:%2******** ********@TK2MSF TNGP11.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****@rubbach icken.com> wrote in message
news:up******** ******@tk2msftn gp13.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******** *****@TK2MSFTNG P10.phx.gbl...
The most suitable number of threads for a SPAM engine is exactly 357...
;)

"SamIAm" <sa****@rubbach icken.com> wrote in message
news:ey******** ******@tk2msftn gp13.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
3080
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 about 2 mins each (on a 2.8 Ghz Xeon and the server range from 2 to 8 processors) (give or take about 15 secs). I have 8 sets of calculations to do (in another app I have 121) all the same calc just different data. But the rest of the processing...
6
3213
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 list within a single object, which is then placed on a stack(This cuts down thread creation and deletions roughly by a factor of 4). I create up to 12 threads, which then process a single object off of the stack. I use a loop with a boolean...
9
2405
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 threads, and assigning the task to completed threads in a loop. Thanks
3
5981
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 ThreadPool thread. And that is exactly what MS VIsual Studio shows. But when I run Processexplorer or Taskmanager I see 2 additional threads, after a while another 2 additional threads. With the 3 threads at start time we have totally 7 threads.
11
1463
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 accessed in order to retrieve information. From within the “Application_Start” (Global.asax), I create as many threads as servers we have available. The idea is that each thread will query each server and update a flag in the public array. When a...
4
16426
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 threads must abort, but to my great surprise, running threads do not stop when application.exit is called. So I (or the users) have to stop threads using Ctrl-Alt-Del. Is there a way to stop ALL threads with a single instruction, without having to...
6
5407
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 smaller number of threads that do a larger amount of work over a given time period here is an oversimplified example application 1 has 4 threads
4
2266
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 start five threads and process five files at a time. Is this a good idea? I picked the number five at random... I was thinking that I might check the number of processors and start a multiple of that, but then I remembered KISS and it seemed that...
167
8420
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 object should run in its own thread, it should implement this mix-in class. Does this sound like plausible design decision? I'm surprised that C++ doesn't have such functionality, say in its STL. This absence of a thread/object relationship in...
0
9877
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11346
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
11046
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10538
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9725
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7248
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6138
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4336
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3357
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.