473,689 Members | 2,838 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

PROBLEM WITH THREADS - WIN 2003

Mr
Hi

We have a application with Framework 1.1 and Vs .NET 2003.
the application has a service with pooling; like a
File system Watcher, but works.

the system works fine in the development enviroment with
a performance very good; but production not.
-------------------------------------------------------------------------------------------

SAMPLE CODE
-------------------------------------------------------------------------------------------

using Microsoft.Appli cationBlocks.Da ta;
using System.Data.Sql Client;
using System;
using System.ServiceP rocess;
using System.Diagnost ics;
using System.Configur ation;
using System.Threadin g;
using System.Runtime. Remoting;
using System.IO;
using System.Data;
using LibreriasCIV.Pr oyectos;
using CLSutilidades.U tilidades;
using System.Enterpri seServices;

public class CIVmonitor : System.ServiceP rocess.ServiceB ase
{
private DateTime timeStart; //Used to note the start time of the service
private DateTime timeEnd; //Used to note the end time of the service
private TimeSpan timeElapsed = new TimeSpan(0); //' Initialize to 0;
// Used to calculate difference between timeEnd and TimeStart
private TimeSpan timeDifference;
private bool isPaused = false; // Notes whether the service is paused;
//ManualResetEven t b = new ManualResetEven t(false);
private bool INICIAR;
private DataSet DSproyectos ;
CLSutilidades.U tilidades.cUtil idadesSeguimien to OBJutil= new
CLSutilidades.U tilidades.cUtil idadesSeguimien to();//PARA TRABAJAR LOS ARCHIVOS
#region " Component Designer generated code ";

public CIVmonitor()
{
// This call is required by the Component Designer.
InitializeCompo nent();
// Add any initialization after the InitializeCompo nent() call
}
//UserService overrides dispose to clean up the component list.
protected override void Dispose(bool disposing)
{
if (disposing)
{
if (components != null)
{
components.Disp ose();
}
}
base.Dispose(di sposing);
}
// The main entry point for the process
static void Main()
{
System.Runtime. Remoting.Remoti ngConfiguration .Configure(AppD omain.CurrentDo main.SetupInfor mation.Configur ationFile);
System.ServiceP rocess.ServiceB ase[] ServicesToRun;
// More than one NT Service may run within the same process. To add
// another service to this process, change the following line to
// create a second service object. For example,
ServicesToRun = new System.ServiceP rocess.ServiceB ase[] {new CIVmonitor()};
System.ServiceP rocess.ServiceB ase.Run(Service sToRun);
}

//Required by the Component Designer
private System.Componen tModel.IContain er components = null;
// NOTE: The following procedure is required by the Component Designer
// It can be modified using the Component Designer.
// Do not modify it using the code editor.
private void InitializeCompo nent()
{
//
// CIVmonitor
//
this.CanPauseAn dContinue = true;
this.CanShutdow n = true;
this.ServiceNam e = "CIVmonitor ";

}

#endregion
// OnContinue occurs when the user asks a paused Service to continue. In
order
// for this method to be called the CanPauseAndCont inue property must be
// set to true. (It is false by default.)
protected override void OnContinue()
{
// Begin measuring the elapsed time. This means setting the
// timeStart back to the current time, and resetting isPaused
// to false
CrearTabla();
if (isPaused)
{
timeStart = DateTime.Now;
}
isPaused = false;
OBJutil.WriteLO G(Configuration Settings.AppSet tings.Get("LOGp ath").ToString( ),"","CIVmonito r Reanudo Operación ","CIVMONITOR", "ProcessDir ");

}

// OnPause occurs when the user asks a running Service to pause. In order
// for this method to be called the CanPauseAndCont inue property must be
// set to true. (It is false by default.)
protected override void OnPause()
{
timeEnd = DateTime.Now;
DSproyectos = null;

if (! isPaused)
{
timeDifference = timeEnd.Subtrac t(timeStart);
timeElapsed = timeElapsed.Add (timeDifference );
}
isPaused = true;

OBJutil.WriteLO G(Configuration Settings.AppSet tings.Get("LOGp ath").ToString( ),"","CIVmonito r Pausado ","CIVMONITOR", "ProcessDir ");
}

// OnShutdown occurs when the computer is powered off and the
// Service has not been stopped. In order for this method to be called
// the CanShutdown property must be set to true. (It is false by default.)
protected override void OnShutdown()
{
this.OnStop();
DSproyectos = null;
}

// OnStart is called whenever the service is started.
protected override void OnStart(string[] args)
{
System.Threadin g.Thread.Curren tThread.Name = "GESTOR INTEGRAL DE ARCHIVOS
CIV";
System.Threadin g.Thread.Curren tThread.Priorit y=
System.Threadin g.ThreadPriorit y.Highest;

timeElapsed = new TimeSpan(0);
// Initialize the Start time
timeStart = DateTime.Now;
isPaused = false;
OBJutil.WriteLO G(Configuration Settings.AppSet tings.Get("LOGp ath").ToString( ),"","CIVmonito r Iniciado "+timeElapsed," CIVMONITOR","Pr ocessDir");
INICIAR = true;
Debug.Write("IN ICIO");
CrearTabla(); //CREAR DATASET CON CADA UNO DE LOS PROYECTOS ACTIVOS, ESTOS
SON LOS QUE SE MONITOREARAN
Pickup (); //DISPARAR LA FUNCION QUE MONITOREARA ARCHIVOS
Debug.Write("IN ICIO");
}

// OnStop is called whenever the service is stopped.
protected override void OnStop()
{
timeEnd = DateTime.Now;
if (! isPaused)
{
timeDifference = timeEnd.Subtrac t(timeStart);
timeElapsed = timeElapsed.Add (timeDifference );
}
OBJutil.WriteLO G(Configuration Settings.AppSet tings.Get("LOGp ath").ToString( ),"","CIVMONITO R DETENIDO "+timeDifferenc e,"CIVMONITOR", "ProcessDir ");
OBJutil.WriteLO G(Configuration Settings.AppSet tings.Get("LOGp ath").ToString( ),"","CIVmonito r Detenido por "+timeElapsed," CIVMONITOR","Pr ocessDir");
DSproyectos=nul l; //LIMPIAR DS
INICIAR =false; //BANDERA A FALSE PARA QUE NO ITERE MAS
}

private void ProcessDir()
{
//
// Processes the files in that directory
//
try
{
while(INICIAR)
{
Debug.WriteLine (" ITERANDO ");
//ITERAR POR CADA UNO DE LOS ELEMENTOS DEL DATASET
if(DSproyectos. Tables.Count > 0 )
{
if(DSproyectos. Tables[0].Rows.Count > 0)
{
//foreach(DataRow dr in DSproyectos.Tab les[0].Rows) // LOS ARCHIVOS SE
ALMACENAN UNO A UNO EN UN VECTOR
for(int index=0;index<D Sproyectos.Tabl es[0].Rows.Count;ind ex++)
{
//LLAMAR AL OBJETO QUE VIGILA CARPETAS
CLScontroladora .Controladora.c Control OBJcontroladora = new
CLScontroladora .Controladora.c Control(
DSproyectos.Tab les[0].Rows[index].ItemArray[0].ToString(),
//CLInombre
DSproyectos.Tab les[0].Rows[index].ItemArray[1].ToString(),
//PROnombre
DSproyectos.Tab les[0].Rows[index].ItemArray[2].ToString(), //PROalias
DSproyectos.Tab les[0].Rows[index].ItemArray[3].ToString(),
//PROentrada
DSproyectos.Tab les[0].Rows[index].ItemArray[4].ToString(), //PROlog
DSproyectos.Tab les[0].Rows[index].ItemArray[5].ToString(),
//PRObackup
DSproyectos.Tab les[0].Rows[index].ItemArray[6].ToString(),
//PROsalida
DSproyectos.Tab les[0].Rows[index].ItemArray[7].ToString(),
//PROextension
DSproyectos.Tab les[0].Rows[index].ItemArray[8].ToString(), //PROftp
ConfigurationSe ttings.AppSetti ngs.Get("Conexi on").ToString() );
//CONEXION DB
OBJcontroladora .ClasificarData ();
}
Thread.Sleep(in t.Parse(Configu rationSettings. AppSettings["Pausa"].ToString())); //PAUSA EN MS PARA QUE NO SE COMA EL SERVICIO LA MAQUINA
}
}

}
}
catch(Exception exp)
{
OBJutil.WriteLO G(Configuration Settings.AppSet tings.Get("LOGp ath").ToString( ),"",exp.Messag e,"CIVMONITOR", "ProcessDir ");
}
}

private void CrearTabla()
{
SqlConnection connection = null;// SqlConnection that will be used to
execute the sql commands
DSproyectos = new DataSet("Proyec tos"); // SAVE PROYECS
try
{
try
{
Debug.WriteLine ("INICIALIZA NDO CADENA DE CONEXION");
connection = new
SqlConnection(C onfigurationSet tings.AppSettin gs["Conexion"]);
}
catch
{
Debug.WriteLine ("ERROR");
CLSutilidades.U tilidades.cUtil idadesSeguimien to OBJutil= new
CLSutilidades.U tilidades.cUtil idadesSeguimien to();//PARA TRABAJAR LOS ARCHIVOS
OBJutil.WriteLO G(Configuration Settings.AppSet tings.Get("LOGp ath").ToString( ),"","NO SE PUDO CONECTAR A LA DB","CIVMONITOR ","CrearTabla") ;
return;
}
DSproyectos = SqlHelper.Execu teDataset(conne ction,
CommandType.Sto redProcedure, "SpGetProyectos ", new SqlParameter("@ Estado",
"ACT") );
Debug.WriteLine ("SE RECUPERO EL DATASET
"+DSproyectos.T ables[0].Rows.Count);
}
catch(Exception exp)
{
string errMessage = "";
for( Exception tempException = exp; tempException != null ; tempException
= tempException.I nnerException )
{
errMessage += tempException.M essage + Environment.New Line +
Environment.New Line;
}
OBJutil.WriteLO G(Configuration Settings.AppSet tings.Get("LOGp ath").ToString( ),"","ERROR
AL TRATAR DE CONSULTAR INFORMACION DE CLIENTES/PROYECTOS EN LA DATABASE -
"+exp.Message," CIVMONITOR","Pr ocessDir");
OBJutil.WriteLO G(Configuration Settings.AppSet tings.Get("LOGp ath").ToString( ),"",exp.Messag e,"CIVMONITOR", "ProcessDir ");
}
finally
{
if(connection != null)
connection.Disp ose();
}

}
private void Pickup ()
{
try
{
System.Threadin g.Thread.Curren tThread.Name = "Monitor CIV";
Thread objThread= new Thread(new ThreadStart(Pro cessDir));
objThread.Name = "Gestor Directorios";
objThread.Prior ity = System.Threadin g.ThreadPriorit y.Highest;
objThread.Start ();
Debug.WriteLine ("PASO POR PICKUP ");
}

catch(ThreadAbo rtException exp)
{
OBJutil.WriteLO G(Configuration Settings.AppSet tings.Get("LOGp ath").ToString( ),"",exp.Messag e,"CIVMONITOR", "ProcessDir ");

}

}

}

We changed machine.config and nothing.

The performance in production is very slow, the system is WIN 2003.
DEVELOPMENT ENVIROMENT: WIN2000 - SQL SERVER 2000

PRODUCTION ENVIROMENT: WIN2003 - SQL SERVER 2000

What can i do?

Ideas

The application has a service with MultiThreading. For each task
starts a Thread.
Feb 14 '06 #1
5 1413
Hi,

It's not a good idea to post your entire code, nobody will read it
completely ( most of the us people are in the office :) )

Which is the slow part?

Did you check if you may have any sync problems, like two threads
reading/writing the same variable?

what if you try to pinpoint the problem, remove as much code as possible
until you get the method where the performance problem is.

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
Feb 14 '06 #2
Mr
thanks

The threads in the server works very slow.

the production server has Win 2003 with SQL 2000.

The problem is; We need more priority for the execution of Threads, because
the process has only a few of CPU.
The program works fine, but very slow.
We need more priority.
ideas?

"Ignacio Machin ( .NET/ C# MVP )" wrote:
Hi,

It's not a good idea to post your entire code, nobody will read it
completely ( most of the us people are in the office :) )

Which is the slow part?

Did you check if you may have any sync problems, like two threads
reading/writing the same variable?

what if you try to pinpoint the problem, remove as much code as possible
until you get the method where the performance problem is.

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

Feb 14 '06 #3
You need to profile the code to see where the slow parts are. Since
the service is reading/writing data to a database I suspect that will
be your bottleneck. Changing the priority of the worker will have
little effect especially if the thread is speading most of its time in
an idle state waiting for the database IO to complete.

If you can post a short, but complete program that demonstrates the
slowness you're seeing we can help. Often times, in the process of
attempting to provide that short program, you'll discover the problem
yourself.

Also, like Ignacio, when all else fails use the process of
trial-and-error by removing and adding back code until you find the
performance problem.

Brian

Mr wrote:
thanks

The threads in the server works very slow.

the production server has Win 2003 with SQL 2000.

The problem is; We need more priority for the execution of Threads, because
the process has only a few of CPU.
The program works fine, but very slow.
We need more priority.
ideas?

"Ignacio Machin ( .NET/ C# MVP )" wrote:
Hi,

It's not a good idea to post your entire code, nobody will read it
completely ( most of the us people are in the office :) )

Which is the slow part?

Did you check if you may have any sync problems, like two threads
reading/writing the same variable?

what if you try to pinpoint the problem, remove as much code as possible
until you get the method where the performance problem is.

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation


Feb 14 '06 #4
Mr <Mr@discussions .microsoft.com> wrote:
We have a application with Framework 1.1 and Vs .NET 2003.
the application has a service with pooling; like a
File system Watcher, but works.

the system works fine in the development enviroment with
a performance very good; but production not.


<snip>

The first thing I'd do is try to reproduce the problem in a console
application. That would be a lot shorter to post, and a lot easier to
debug too.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Feb 14 '06 #5
To add what the others, said. It's wrong to set the priority of a thread
above normal, espcially in a service, it won't make your code run faster
anyway. In you thread procedure (ProcessDir) you run an endless loop, which
does't really shows what you are actually doing (the ClasificarData is
missing) except Sleeping for a while! Now, if this is what you call slow,
why did you include the Sleep call, and what amount of time are you putting
this (high priority!) thread asleep?

Willy.

"Mr" <Mr@discussions .microsoft.com> wrote in message
news:D1******** *************** ***********@mic rosoft.com...
| thanks
|
| The threads in the server works very slow.
|
| the production server has Win 2003 with SQL 2000.
|
| The problem is; We need more priority for the execution of Threads,
because
| the process has only a few of CPU.
| The program works fine, but very slow.
| We need more priority.
| ideas?
|
| "Ignacio Machin ( .NET/ C# MVP )" wrote:
|
| > Hi,
| >
| > It's not a good idea to post your entire code, nobody will read it
| > completely ( most of the us people are in the office :) )
| >
| > Which is the slow part?
| >
| > Did you check if you may have any sync problems, like two threads
| > reading/writing the same variable?
| >
| > what if you try to pinpoint the problem, remove as much code as possible
| > until you get the method where the performance problem is.
| >
| >
| >
| > --
| > Ignacio Machin,
| > ignacio.machin AT dot.state.fl.us
| > Florida Department Of Transportation
| >
| >
| >
Feb 14 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
12071
by: Tobias | last post by:
Hi! I had Apache 2.0.47 and PHP 4.3.0 DEV running successfully on a W2k Server. For some reason, I couldn't get PHP to read XML-Attributes with the DOM XML -functions. So I thought, it would be time to update PHP to a newer version. So I simply replaces the old php-files with the new ones and of course kept the php.ini. But now, PHP doesn't work anymore. As soon as I request a page with php code, I get a "document contains no data"...
2
4039
by: Vinay Aggarwal | last post by:
I have been thinking about the lazy initialization and double checked locking problem. This problem is explain in detail here http://www.cs.umd.edu/~pugh/java/memoryModel/DoubleCheckedLocking.html I am not fully convinced that this problem cannot be solved. I am going to propose a solution here. For the sake of discussion I will post my solution here. It is possible that the proposed solution does not work, feedback and comments are...
6
2221
by: Evan David Light | last post by:
After agonizing over this problem for a few days, I've decided to seek help. No, not the variety that involes a jacket that zips up the back but this august body of intrepid individuals. I've discovered the following: - My compile line should resemble: CC -D_PTHREADS -D_POSIX_C_SOURCE=199506L -LANG:std -n32 -mips3 -c <src> -o <obj> - My link line should resemble: CC -LANG:std -n32 -mips3 <objs> -o <executable> -lpthread
7
2864
by: David Sworder | last post by:
Hi, I'm developing an application that will support several thousand simultaneous connections on the server-side. I'm trying to maximize throughput. The client (WinForms) and server communicate via a socket connection (no remoting, no ASP.NET). The client sends a message to the server that contains some instructions and the server responds in an asynchronous fashion. In other words, the client doesn't block while waiting for the...
6
4593
by: David | last post by:
Hi all, In my code I have a bottleneck which consists of a cpu-intensive loop of size LENGTH. What I did was to divide that loop into two threads, Thread1 doing the 0 to LENGTH/2 part, and Thread2 doing the LENGTH/2 to LENGTH part. There is no synchronization between threads, so they should work pretty freely. My machine has two processors (dual P3, Windows 2003 server). Now comes the problem: when running the program, both threads...
8
3416
by: Rob Edwards | last post by:
When trying to add the Microsoft CDO for Exchange Management Library (aka CDOEXM.dll) I receive the following message: "A reference to 'Microsoft CDO for Exchange Management Library' could not be added. Converting the type library to a .Net assembly failed. A depended type library 'CDO' could not be converted to a .NET assembly. A dependent type library 'ADODB' could not be converted to a .NET assembly. Item has already been added." ...
3
1855
by: Jack Fox | last post by:
While stress-testing our ASP.NET app, we discovered a flaw in our test set-up, which also reveals a flaw in our ASP.NET configuration that we do not know how to address. We simulated too many clients, making requests faster than the bandwidth on that part of the network could consume the responses. It seems that the inability of the requestors to receive their responses causes IIS, and/or aspnet_wp.exe, to eventually max-out its...
3
1343
by: Dave | last post by:
Hi, I have a .NET class which uses the .NET threadpool (using QueueUserWorkItem) to create about 8 threads, which do some work while the parent thread waits for them all to complete, which works fine when referenced from a normal EXE. When I reference this DLL in a webservice however, the threads seem to be created one by one in order, rather than at the same time - it is as if there is only one available thread in the ThreadPool and the...
3
2289
by: Doug | last post by:
I'm having problems w/ the VS2005 debugger with C#. It blows past any breakpoints in even the simplest "Hello World" console application. I can't do any step-by-step debugging. I've provided the code and debugging output later in this post. I've seen a number of threads with similar problems that I'll address below. The one that's the largest concern is this one, which talks about the same problem trying to use the debugger with SQL...
0
8531
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8951
jinu1996
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...
0
8793
tracyyun
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...
1
6457
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4322
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...
0
4550
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2965
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2225
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1952
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.