Solved

SMTP component takes too much CPU usage...

Posted on 2002-04-17
7
281 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
Independent Software Vendors: 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 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Create a path if not exists 7 128
Tembedded WB animatid gifs not animated on some pcs 2 94
Delphi problems to abort a printjob 9 51
IP without any Dots 1 100
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…
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…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

710 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