Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

SMTP component takes too much CPU usage...

Posted on 2002-04-17
7
Medium Priority
?
287 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 300 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 26

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 26

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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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 26

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Loops Section Overview
Suggested Courses

971 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