Solved

SMTP component takes too much CPU usage...

Posted on 2002-04-17
7
274 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 24

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 24

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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

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 24

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

760 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

18 Experts available now in Live!

Get 1:1 Help Now