Solved

SMTP component takes too much CPU usage...

Posted on 2002-04-17
7
283 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Suggested Courses
Course of the Month9 days, 1 hour left to enroll

617 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