Solved

SMTP component takes too much CPU usage...

Posted on 2002-04-17
7
275 Views
Last Modified: 2011-09-20
Hi,
  In my service application, im using TNMSMTP component to send mails. But the CPU usage goes 100% when the mails are being sent..I found out that the Connect method of TNMSMTP is taking too much of the usage. Is there a way wherein I could reduce the CPU usage..
My code goes something like this

m_smtp := TNMSMTP.Create(nil);
try
//
Host , Timeout and other details are assigned to the object.
//
m_smtp.Connect;
while not dbTablename.Eof do
begin
  //Get database values into mail component parameters
  m_smtp.Sendmail;
end;
finally
  m_smtp.DisConnect;
end;

As the Connect is still active inside the loop, the CPU usage increases. Is there a way I could avoid this??

Thanx in Advance
Gerry
0
Comment
Question by:gerry020297
  • 3
  • 2
  • 2
7 Comments
 
LVL 2

Accepted Solution

by:
aubs earned 100 total points
ID: 6947206
Basically these Fastnet (TNM..)  components always seem to give people headaches!

This is why Borland moved to use Indy components in Delphi 6.

You can still download the Indy components for previous versions of Delphi from:

http://www.nevrona.com/Indy/

Regards

Aubs

PS - I know it is always annoying when you have a problem with a component and the suggestion is to just use a different component, but in the case of Fastnet vs Indy you will not regret changing!

0
 
LVL 25

Expert Comment

by:Tomas Helgi Johannsson
ID: 6947218
Hi!

Your code looks to me like a typical mailbomb.
You are sending X mails where X is the number of records in dbTablename from where the dbTablename cursor is pointing to the last record.
Move the SendMail command below the finally statement and the problem will hopefully vanish.

Regards,
Tomas Helgi
0
 
LVL 25

Expert Comment

by:Tomas Helgi Johannsson
ID: 6947236
Hi!

There is another error in your code I missed.
In the while loop you should put a dbTablename.Next before
the "end" of the for loop.
That is causing the tremendous CPU usage.
THIS IS A TYPICAL MAILBOMB because your code could be rewritten like this

while true do
begin
   ...
   x.SendMail;
   <- here should be a dbTablename.Next;
end;

So put a Next command like I'm showing you otherwise you
are sending the same data over and over again. ;)

Regards,
Tomas Helgi
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:gerry020297
ID: 6947280
Hi Tomas,
 :) that was just a sample code which i had put forth. I have take care of traversing thru the records. As for putting the sendmail in the finally, it will not help as each record is to be sent as a mail. The Recepients address and other details will vary from record to record.
My concern is only with the Connect..Is there anyway(Anything at all) wherein i can reduce the CPU time.
Any suggestions are welcome :)

Regards
Gerry
0
 
LVL 25

Expert Comment

by:Tomas Helgi Johannsson
ID: 6947318
Hi!

Ok, I see.
I suggest you try to use Indy as aubs suggested. Just to
see if that changes anything.
I reasently used the TNMFTP component in the FastNet component-family. I experienced some trouble uploading files over a sertain amount of KB. Several KB of the files where missing on the FTP server after each upload. I switched to the Indy FTP client component with the same result.
Unfortunatly I found out that the server I was using was the problem because when I changed to another FTP server the problem I was facing disappeared.
It may be that I forgot to adjust some properties but as far as I can see I did everything right.
So if the problem is still at hand even though you use the Indy components then it may be the SMTP server you are connecting to.
You could also change the ReportLevel property and log to a file the Status event and other events as well. Maybe you would then see what the problem is.

Regards,
Tomas Helgi
0
 

Author Comment

by:gerry020297
ID: 6952833
Thanx aubs,
 yes i did try with Indy components and I was surprised that this component takes hardly 5-10% of the CPU usage!!! thats really great.Thanx for the suggestion again. :)
0
 
LVL 2

Expert Comment

by:aubs
ID: 6952844
Glad it worked out OK.

I did tell you that you would not regret it  :-)

Aubs
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now