I have a window service written using VB.NET. This window service will scan
folders for file and grab the file content to be inserted to SQL Server on
file detection. There are altogether 18 folders to be watched. Each folder is
assigned with a timer for watching purpose. Hence there will be 18 timers and
each timer is set to elapse on every second.
Problem here, once the window service is installed and started, the CPU
usage is very high (take about 10% of overall CPU usage at a four 2GHz
processors server even when there is no file being sent in for processing).
This highly comsumption of CPU power is because of the timers elapsed event?
Any idea to improve it? Any advice and comment would be much appreciated. 7 4973
On 2004-12-01, LBT <LB*@discussion s.microsoft.com > wrote: I have a window service written using VB.NET. This window service will scan folders for file and grab the file content to be inserted to SQL Server on file detection. There are altogether 18 folders to be watched. Each folder is assigned with a timer for watching purpose. Hence there will be 18 timers and each timer is set to elapse on every second.
Problem here, once the window service is installed and started, the CPU usage is very high (take about 10% of overall CPU usage at a four 2GHz processors server even when there is no file being sent in for processing). This highly comsumption of CPU power is because of the timers elapsed event?
More then likely what your doing in the event... How often are the
timers firing? Which timer class are you using?
Any idea to improve it? Any advice and comment would be much appreciated.
Have you looked at the FileSystemWatch er class in System.IO. You
shouldn't need timers and polling this way...
--
Tom Shelton [MVP]
Thanks for the reply.
I have used the Timer under "Components " tab located in the .NET IDE Toolbox.
I did use the FileSystemWatch er class before but the class somehow have
limitation. Whenever SQL Server is down or offline, the file that being
halfway processed or subsequent file sent in to the folder will not be
processed as FileSystemWatch er only provides method such as OnCreated,
OnModified, OnDeleted, etc. The file will be stuck inside the folder without
processed after all. Hence I have changed the mechanism by always scanning
folder for file using timer.
"Tom Shelton" wrote: On 2004-12-01, LBT <LB*@discussion s.microsoft.com > wrote: I have a window service written using VB.NET. This window service will scan folders for file and grab the file content to be inserted to SQL Server on file detection. There are altogether 18 folders to be watched. Each folder is assigned with a timer for watching purpose. Hence there will be 18 timers and each timer is set to elapse on every second.
Problem here, once the window service is installed and started, the CPU usage is very high (take about 10% of overall CPU usage at a four 2GHz processors server even when there is no file being sent in for processing). This highly comsumption of CPU power is because of the timers elapsed event?
More then likely what your doing in the event... How often are the timers firing? Which timer class are you using?
Any idea to improve it? Any advice and comment would be much appreciated.
Have you looked at the FileSystemWatch er class in System.IO. You shouldn't need timers and polling this way...
-- Tom Shelton [MVP]
In article <6F************ *************** *******@microso ft.com>, LBT wrote: Thanks for the reply.
I have used the Timer under "Components " tab located in the .NET IDE Toolbox.
I did use the FileSystemWatch er class before but the class somehow have limitation. Whenever SQL Server is down or offline, the file that being halfway processed or subsequent file sent in to the folder will not be processed as FileSystemWatch er only provides method such as OnCreated, OnModified, OnDeleted, etc. The file will be stuck inside the folder without processed after all. Hence I have changed the mechanism by always scanning folder for file using timer.
You should still be able to use filesystemwatch er... You simply need to
queue failed requests - then you would only need one timer. That timer
would check periodically to see if there were files that needed to be
processed in the failed queue.
private sub watcher_Created (byval sender as object, byval e as
filesystemevent args e)
try
attempt to process file
catch ex as exception
we couldn't process - so
failedqueue.add (file)
end try
end sub
private sub timer_elapsed (....)
try
attempt to process files in queue
catch ex as excpetion
add current file back to queue
failedqueue.add (file)
end try
end sub
make sense?
--
Tom Shelton [MVP]
OS Name: Microsoft Windows XP Professional
OS Version: 5.1.2600 Service Pack 2 Build 2600
System Up Time: 39 Days, 19 Hours, 23 Minutes, 47 Seconds
Appreciated for the suggestion :) But I still have doubt and wish that Tom
could provide me some valuable idea.
I think I will explain some logic flow of my window service in order to have
a better understanding to cope my hassle.
The window service needs to process files from 16 directories. Each folder
has its own file format. There will be no limitation on the number of files
that can be sent in to a folder at one time. But only 1 file is allowed to
process at one time (sequence of file based on creation datetime is very
important). I might need a queue table to stack the records (file info)
before each file get its turn to be processed. The role of the window service
is to obtain the file content and insert to a SQL table as a record. In the
SQL table, there is a INSERT trigger which will be invoked and execute a
stored procedure to carry out validation towards the record. At the last
portion of the stored procedure, it will update the queued record to
"FINISH". When WS detect for this "FINISH" status, it will move the file to
archive folder and processing for 1 file is considered finish.
Question here, if I use the FileSystemWatch er class, it will help me to put
the file info to the queue table with the help of OnCreated event. But I
might still need a timer to process the queue table to ensure that file is
processed in sequence and only one file is processed at one time.
Currently, I use a timer to scan directory. If no file is detected, the
process will stop and wait for next elapsed event. If file(s) detected, all
file info as grabbed at that time will be put to a queue table. All record(s)
inside the queue table should be finish processed before subsequent file
exists in a folder would be catered again. In order words, the timer elapsed
event will not scan directory for file until queue table is finish processed
(controlled using a boolean flag).
As what can be seen, timer should be there for first method
(FileSystemWatc her + Timer) and second method which I used for this moment.
Timer seem can't be escaped from using for both methods and the use of timer
would again increase the CPU usage when all timers elapsed at the same time.
For yuor information, timer interval is set to 1 second.
Any way I can improve so that the CPU usage will not reach the critical
level? What I've tested shows that the CPU usage is considered high when
there is no file being sent in to any of the folders. The CPU usage will
become higher when there is file sent in for processing. Any weakness in my
existing file processing mechanism? Any better workaround?
Thanks a lot
Uset the FileSystemWatch er to tell you when a new file has been created.
Then use the same scanning algorithm you currently use. By using the
FileSystemWatch er, you eliminate both excessive scans and delayed scans.
Once you have completed scanning, then restart start the FileSystemWatch er.
Mike Ober.
"LBT" <LB*@discussion s.microsoft.com > wrote in message
news:78******** *************** ***********@mic rosoft.com... Appreciated for the suggestion :) But I still have doubt and wish that Tom could provide me some valuable idea.
I think I will explain some logic flow of my window service in order to
have a better understanding to cope my hassle.
The window service needs to process files from 16 directories. Each folder has its own file format. There will be no limitation on the number of
files that can be sent in to a folder at one time. But only 1 file is allowed to process at one time (sequence of file based on creation datetime is very important). I might need a queue table to stack the records (file info) before each file get its turn to be processed. The role of the window
service is to obtain the file content and insert to a SQL table as a record. In
the SQL table, there is a INSERT trigger which will be invoked and execute a stored procedure to carry out validation towards the record. At the last portion of the stored procedure, it will update the queued record to "FINISH". When WS detect for this "FINISH" status, it will move the file
to archive folder and processing for 1 file is considered finish.
Question here, if I use the FileSystemWatch er class, it will help me to
put the file info to the queue table with the help of OnCreated event. But I might still need a timer to process the queue table to ensure that file is processed in sequence and only one file is processed at one time.
Currently, I use a timer to scan directory. If no file is detected, the process will stop and wait for next elapsed event. If file(s) detected,
all file info as grabbed at that time will be put to a queue table. All
record(s) inside the queue table should be finish processed before subsequent file exists in a folder would be catered again. In order words, the timer
elapsed event will not scan directory for file until queue table is finish
processed (controlled using a boolean flag).
As what can be seen, timer should be there for first method (FileSystemWatc her + Timer) and second method which I used for this
moment. Timer seem can't be escaped from using for both methods and the use of
timer would again increase the CPU usage when all timers elapsed at the same
time. For yuor information, timer interval is set to 1 second.
Any way I can improve so that the CPU usage will not reach the critical level? What I've tested shows that the CPU usage is considered high when there is no file being sent in to any of the folders. The CPU usage will become higher when there is file sent in for processing. Any weakness in
my existing file processing mechanism? Any better workaround?
Thanks a lot
Currently I used the System.IO.Direc tory.GetFiles method to scan directory.
Is it the method will cause lot of undesired overhead? The use of
FileSystemWatch er will be able to eliminate this?
Thanks
"Michael D. Ober" wrote: Uset the FileSystemWatch er to tell you when a new file has been created. Then use the same scanning algorithm you currently use. By using the FileSystemWatch er, you eliminate both excessive scans and delayed scans. Once you have completed scanning, then restart start the FileSystemWatch er.
Mike Ober.
"LBT" <LB*@discussion s.microsoft.com > wrote in message news:78******** *************** ***********@mic rosoft.com... Appreciated for the suggestion :) But I still have doubt and wish that Tom could provide me some valuable idea.
I think I will explain some logic flow of my window service in order to have a better understanding to cope my hassle.
The window service needs to process files from 16 directories. Each folder has its own file format. There will be no limitation on the number of files that can be sent in to a folder at one time. But only 1 file is allowed to process at one time (sequence of file based on creation datetime is very important). I might need a queue table to stack the records (file info) before each file get its turn to be processed. The role of the window service is to obtain the file content and insert to a SQL table as a record. In the SQL table, there is a INSERT trigger which will be invoked and execute a stored procedure to carry out validation towards the record. At the last portion of the stored procedure, it will update the queued record to "FINISH". When WS detect for this "FINISH" status, it will move the file to archive folder and processing for 1 file is considered finish.
Question here, if I use the FileSystemWatch er class, it will help me to put the file info to the queue table with the help of OnCreated event. But I might still need a timer to process the queue table to ensure that file is processed in sequence and only one file is processed at one time.
Currently, I use a timer to scan directory. If no file is detected, the process will stop and wait for next elapsed event. If file(s) detected, all file info as grabbed at that time will be put to a queue table. All record(s) inside the queue table should be finish processed before subsequent file exists in a folder would be catered again. In order words, the timer elapsed event will not scan directory for file until queue table is finish processed (controlled using a boolean flag).
As what can be seen, timer should be there for first method (FileSystemWatc her + Timer) and second method which I used for this moment. Timer seem can't be escaped from using for both methods and the use of timer would again increase the CPU usage when all timers elapsed at the same time. For yuor information, timer interval is set to 1 second.
Any way I can improve so that the CPU usage will not reach the critical level? What I've tested shows that the CPU usage is considered high when there is no file being sent in to any of the folders. The CPU usage will become higher when there is file sent in for processing. Any weakness in my existing file processing mechanism? Any better workaround?
Thanks a lot
Hi,
I made a form, adding this code
Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
Dim oTimer(19) As MyTimer
For I As Integer = 0 To 19
oTimer(I) = New MyTimer
oTimer(I).Inter val = 1000
oTimer(I).nID = I
AddHandler oTimer(I).Elaps ed, AddressOf oTimer_Elapsed
oTimer(I).Start ()
Next
End Sub
Public Sub oTimer_Elapsed( ByVal sender As Object, ByVal e As
System.Timers.E lapsedEventArgs )
Dim sArray() As String = System.IO.Direc tory.GetFiles(" C:\T\" &
CType(sender, MyTimer).nID & "\", "*.*")
If Not sArray Is Nothing Then
If sArray.Length > 0 Then
Debug.WriteLine ("Found file...")
End If
End If
End Sub
Public Class MyTimer
Inherits System.Timers.T imer
Private m_nID As Integer
Public Property nID() As Integer
Get
Return m_nID
End Get
Set(ByVal Value As Integer)
m_nID = Value
End Set
End Property
End Class
When running it (made 20 directories) it takes zero % processor power.
Also, a word of caution, a mistake that I made a while ago, if you create a
new timer and dont stop the old one (or run out of scope) it still elapes,
and when you have several thousand, the processor will start feeling it..
- Fredrik Melin
"LBT" <LB*@discussion s.microsoft.com > wrote in message
news:E4******** *************** ***********@mic rosoft.com... I have a window service written using VB.NET. This window service will scan folders for file and grab the file content to be inserted to SQL Server on file detection. There are altogether 18 folders to be watched. Each folder is assigned with a timer for watching purpose. Hence there will be 18 timers and each timer is set to elapse on every second.
Problem here, once the window service is installed and started, the CPU usage is very high (take about 10% of overall CPU usage at a four 2GHz processors server even when there is no file being sent in for processing). This highly comsumption of CPU power is because of the timers elapsed event? Any idea to improve it? Any advice and comment would be much appreciated. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Ian Taite |
last post by:
Hello,
I'm exploring why one of my C# .NET apps has "high" memory usage, and
whether I can reduce the memory usage.
I have an app that wakes up and processes text files into a database
periodically. What happens, is that the app reads the contents of a
text file line by line into an ArrayList. Each element of the ArrayList
is a string representing a record from the file. The ArrayList is then
processed, and the arraylist goes out of...
|
by: jam |
last post by:
Dear all,
I am wrtiing a console application and doing some test on timer, the below
is my sample code I got from some site, but I cannot make it work...
Error is
'System.Timers.Timer' does not contain a definition for 'Tick'
So what should i do???
the final thing I wanna get is, I have a console will call a exe running in
background, and then I wanna check it is is still running ( Use get process
|
by: Michael Evans |
last post by:
First, we rely on a stable update rate so that our physics and dynamics
calculations and integrations are based on a known interval and
therefore are true-to-life.
Second, the graphics positions in our image generators are updated by
this dynamics application, and we need to update them at the rate they
are being refreshed so that we don't get any stutter from frames being
used twice or having to be thrown out.
Without microsecond...
|
by: Liverpool fan |
last post by:
I have a windows application written using VB .NET that encompasses a
countdown timer modal dialog. The timer is a System.Timers.Timer with
an interval of 1 second. AutoReset is not set so accepts the default of
True. The Elapsed event handler updates the dialog box with how long
before it will close, acting as a timer itself. The dialog has a time
to close property which is checked every time the Elapsed event fires.
The problem I have...
|
by: paresh |
last post by:
Hi all,
I need to set timer in C/linux like alram, such that i will get a
timeout signal after specific timeout and my process remain executing
as is it.
I can use signal(SIGALRM, xyz) and then alarm(some value in sec), there
is a constraint in this as i can pass timeout only in seconds and i
need in milli sec.
Any idea how todo this.
| |
by: DaTurk |
last post by:
Hi,
I'm creating an application that will need to use a timer to do a
static method call every second. My question, is what would be the
best timer to use? I know there are several, but I'd like to use a
timer that is probably the most reliable, and hopefully designed with
high performance in mind. Thank you in advance.
|
by: =?Utf-8?B?TWlrZTk5MDA=?= |
last post by:
Hello,
I am wondering if it is a good idea to use GC.Collect() in a timer. For
example, timer is fired every 5 minutes and calls GC.Collect().
In our server app the memory goes to 600MB and stays there. The memory
hardly goes down. When I disconnect the client and the connect it again the
memory could reclaim to 400MB. But it could go down to 50 MB.
|
by: Andrew Wan |
last post by:
I found this excellent High Speed Timer (in Pascal). I compiled it
(using Turbo Pascal 7 and it runs fine):
http://www.sorucevap.com/bilisimteknolojisi/programcilik/pascal/ders.asp?207995
and same High Speed Timer here too:
http://groups.google.com/group/comp.lang.pascal/browse_thread/thread/92e9398f16c10ba4/e67ff3cf587648ef?lnk=st&q=inline(%24CD)+inline(%241C)+inline(%249C)&rnum=1&hl=en#e67ff3cf587648ef
I converted it to C (using p2c),...
|
by: dantz |
last post by:
HI everyone,
I hope someone can help me on this.
I have form application that has 3 Timers that does an animation (changing an image for every interval)
Each image are loaded at start of application and saved into a Dictionary<string, List<Image>>
The dictionary will have 5 items which is for 5 controls.
then each control will have this images in the dictionary(I also assigned the timers):
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |