G
Guest
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.ApplicationBlocks.Data;
using System.Data.SqlClient;
using System;
using System.ServiceProcess;
using System.Diagnostics;
using System.Configuration;
using System.Threading;
using System.Runtime.Remoting;
using System.IO;
using System.Data;
using LibreriasCIV.Proyectos;
using CLSutilidades.Utilidades;
using System.EnterpriseServices;
public class CIVmonitor : System.ServiceProcess.ServiceBase
{
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;
//ManualResetEvent b = new ManualResetEvent(false);
private bool INICIAR;
private DataSet DSproyectos ;
CLSutilidades.Utilidades.cUtilidadesSeguimiento OBJutil= new
CLSutilidades.Utilidades.cUtilidadesSeguimiento();//PARA TRABAJAR LOS ARCHIVOS
#region " Component Designer generated code ";
public CIVmonitor()
{
// This call is required by the Component Designer.
InitializeComponent();
// Add any initialization after the InitializeComponent() call
}
//UserService overrides dispose to clean up the component list.
protected override void Dispose(bool disposing)
{
if (disposing)
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose(disposing);
}
// The main entry point for the process
static void Main()
{
System.Runtime.Remoting.RemotingConfiguration.Configure(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile);
System.ServiceProcess.ServiceBase[] 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.ServiceProcess.ServiceBase[] {new CIVmonitor()};
System.ServiceProcess.ServiceBase.Run(ServicesToRun);
}
//Required by the Component Designer
private System.ComponentModel.IContainer 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 InitializeComponent()
{
//
// CIVmonitor
//
this.CanPauseAndContinue = true;
this.CanShutdown = true;
this.ServiceName = "CIVmonitor";
}
#endregion
// OnContinue occurs when the user asks a paused Service to continue. In
order
// for this method to be called the CanPauseAndContinue 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.WriteLOG(ConfigurationSettings.AppSettings.Get("LOGpath").ToString(),"","CIVmonitor 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 CanPauseAndContinue property must be
// set to true. (It is false by default.)
protected override void OnPause()
{
timeEnd = DateTime.Now;
DSproyectos = null;
if (! isPaused)
{
timeDifference = timeEnd.Subtract(timeStart);
timeElapsed = timeElapsed.Add(timeDifference);
}
isPaused = true;
OBJutil.WriteLOG(ConfigurationSettings.AppSettings.Get("LOGpath").ToString(),"","CIVmonitor 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.Threading.Thread.CurrentThread.Name = "GESTOR INTEGRAL DE ARCHIVOS
CIV";
System.Threading.Thread.CurrentThread.Priority=
System.Threading.ThreadPriority.Highest;
timeElapsed = new TimeSpan(0);
// Initialize the Start time
timeStart = DateTime.Now;
isPaused = false;
OBJutil.WriteLOG(ConfigurationSettings.AppSettings.Get("LOGpath").ToString(),"","CIVmonitor Iniciado "+timeElapsed,"CIVMONITOR","ProcessDir");
INICIAR = true;
Debug.Write("INICIO");
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("INICIO");
}
// OnStop is called whenever the service is stopped.
protected override void OnStop()
{
timeEnd = DateTime.Now;
if (! isPaused)
{
timeDifference = timeEnd.Subtract(timeStart);
timeElapsed = timeElapsed.Add(timeDifference);
}
OBJutil.WriteLOG(ConfigurationSettings.AppSettings.Get("LOGpath").ToString(),"","CIVMONITOR DETENIDO "+timeDifference,"CIVMONITOR","ProcessDir");
OBJutil.WriteLOG(ConfigurationSettings.AppSettings.Get("LOGpath").ToString(),"","CIVmonitor Detenido por "+timeElapsed,"CIVMONITOR","ProcessDir");
DSproyectos=null; //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.Tables[0].Rows) // LOS ARCHIVOS SE
ALMACENAN UNO A UNO EN UN VECTOR
for(int index=0;index<DSproyectos.Tables[0].Rows.Count;index++)
{
//LLAMAR AL OBJETO QUE VIGILA CARPETAS
CLScontroladora.Controladora.cControl OBJcontroladora = new
CLScontroladora.Controladora.cControl(
DSproyectos.Tables[0].Rows[index].ItemArray[0].ToString(),
//CLInombre
DSproyectos.Tables[0].Rows[index].ItemArray[1].ToString(),
//PROnombre
DSproyectos.Tables[0].Rows[index].ItemArray[2].ToString(), //PROalias
DSproyectos.Tables[0].Rows[index].ItemArray[3].ToString(),
//PROentrada
DSproyectos.Tables[0].Rows[index].ItemArray[4].ToString(), //PROlog
DSproyectos.Tables[0].Rows[index].ItemArray[5].ToString(),
//PRObackup
DSproyectos.Tables[0].Rows[index].ItemArray[6].ToString(),
//PROsalida
DSproyectos.Tables[0].Rows[index].ItemArray[7].ToString(),
//PROextension
DSproyectos.Tables[0].Rows[index].ItemArray[8].ToString(), //PROftp
ConfigurationSettings.AppSettings.Get("Conexion").ToString());
//CONEXION DB
OBJcontroladora.ClasificarData();
}
Thread.Sleep(int.Parse(ConfigurationSettings.AppSettings["Pausa"].ToString())); //PAUSA EN MS PARA QUE NO SE COMA EL SERVICIO LA MAQUINA
}
}
}
}
catch(Exception exp)
{
OBJutil.WriteLOG(ConfigurationSettings.AppSettings.Get("LOGpath").ToString(),"",exp.Message,"CIVMONITOR","ProcessDir");
}
}
private void CrearTabla()
{
SqlConnection connection = null;// SqlConnection that will be used to
execute the sql commands
DSproyectos = new DataSet("Proyectos"); // SAVE PROYECS
try
{
try
{
Debug.WriteLine("INICIALIZANDO CADENA DE CONEXION");
connection = new
SqlConnection(ConfigurationSettings.AppSettings["Conexion"]);
}
catch
{
Debug.WriteLine("ERROR");
CLSutilidades.Utilidades.cUtilidadesSeguimiento OBJutil= new
CLSutilidades.Utilidades.cUtilidadesSeguimiento();//PARA TRABAJAR LOS ARCHIVOS
OBJutil.WriteLOG(ConfigurationSettings.AppSettings.Get("LOGpath").ToString(),"","NO SE PUDO CONECTAR A LA DB","CIVMONITOR","CrearTabla");
return;
}
DSproyectos = SqlHelper.ExecuteDataset(connection,
CommandType.StoredProcedure, "SpGetProyectos", new SqlParameter("@Estado",
"ACT") );
Debug.WriteLine("SE RECUPERO EL DATASET
"+DSproyectos.Tables[0].Rows.Count);
}
catch(Exception exp)
{
string errMessage = "";
for( Exception tempException = exp; tempException != null ; tempException
= tempException.InnerException )
{
errMessage += tempException.Message + Environment.NewLine +
Environment.NewLine;
}
OBJutil.WriteLOG(ConfigurationSettings.AppSettings.Get("LOGpath").ToString(),"","ERROR
AL TRATAR DE CONSULTAR INFORMACION DE CLIENTES/PROYECTOS EN LA DATABASE -
"+exp.Message,"CIVMONITOR","ProcessDir");
OBJutil.WriteLOG(ConfigurationSettings.AppSettings.Get("LOGpath").ToString(),"",exp.Message,"CIVMONITOR","ProcessDir");
}
finally
{
if(connection != null)
connection.Dispose();
}
}
private void Pickup ()
{
try
{
System.Threading.Thread.CurrentThread.Name = "Monitor CIV";
Thread objThread= new Thread(new ThreadStart(ProcessDir));
objThread.Name = "Gestor Directorios";
objThread.Priority = System.Threading.ThreadPriority.Highest;
objThread.Start();
Debug.WriteLine("PASO POR PICKUP ");
}
catch(ThreadAbortException exp)
{
OBJutil.WriteLOG(ConfigurationSettings.AppSettings.Get("LOGpath").ToString(),"",exp.Message,"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.
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.ApplicationBlocks.Data;
using System.Data.SqlClient;
using System;
using System.ServiceProcess;
using System.Diagnostics;
using System.Configuration;
using System.Threading;
using System.Runtime.Remoting;
using System.IO;
using System.Data;
using LibreriasCIV.Proyectos;
using CLSutilidades.Utilidades;
using System.EnterpriseServices;
public class CIVmonitor : System.ServiceProcess.ServiceBase
{
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;
//ManualResetEvent b = new ManualResetEvent(false);
private bool INICIAR;
private DataSet DSproyectos ;
CLSutilidades.Utilidades.cUtilidadesSeguimiento OBJutil= new
CLSutilidades.Utilidades.cUtilidadesSeguimiento();//PARA TRABAJAR LOS ARCHIVOS
#region " Component Designer generated code ";
public CIVmonitor()
{
// This call is required by the Component Designer.
InitializeComponent();
// Add any initialization after the InitializeComponent() call
}
//UserService overrides dispose to clean up the component list.
protected override void Dispose(bool disposing)
{
if (disposing)
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose(disposing);
}
// The main entry point for the process
static void Main()
{
System.Runtime.Remoting.RemotingConfiguration.Configure(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile);
System.ServiceProcess.ServiceBase[] 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.ServiceProcess.ServiceBase[] {new CIVmonitor()};
System.ServiceProcess.ServiceBase.Run(ServicesToRun);
}
//Required by the Component Designer
private System.ComponentModel.IContainer 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 InitializeComponent()
{
//
// CIVmonitor
//
this.CanPauseAndContinue = true;
this.CanShutdown = true;
this.ServiceName = "CIVmonitor";
}
#endregion
// OnContinue occurs when the user asks a paused Service to continue. In
order
// for this method to be called the CanPauseAndContinue 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.WriteLOG(ConfigurationSettings.AppSettings.Get("LOGpath").ToString(),"","CIVmonitor 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 CanPauseAndContinue property must be
// set to true. (It is false by default.)
protected override void OnPause()
{
timeEnd = DateTime.Now;
DSproyectos = null;
if (! isPaused)
{
timeDifference = timeEnd.Subtract(timeStart);
timeElapsed = timeElapsed.Add(timeDifference);
}
isPaused = true;
OBJutil.WriteLOG(ConfigurationSettings.AppSettings.Get("LOGpath").ToString(),"","CIVmonitor 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.Threading.Thread.CurrentThread.Name = "GESTOR INTEGRAL DE ARCHIVOS
CIV";
System.Threading.Thread.CurrentThread.Priority=
System.Threading.ThreadPriority.Highest;
timeElapsed = new TimeSpan(0);
// Initialize the Start time
timeStart = DateTime.Now;
isPaused = false;
OBJutil.WriteLOG(ConfigurationSettings.AppSettings.Get("LOGpath").ToString(),"","CIVmonitor Iniciado "+timeElapsed,"CIVMONITOR","ProcessDir");
INICIAR = true;
Debug.Write("INICIO");
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("INICIO");
}
// OnStop is called whenever the service is stopped.
protected override void OnStop()
{
timeEnd = DateTime.Now;
if (! isPaused)
{
timeDifference = timeEnd.Subtract(timeStart);
timeElapsed = timeElapsed.Add(timeDifference);
}
OBJutil.WriteLOG(ConfigurationSettings.AppSettings.Get("LOGpath").ToString(),"","CIVMONITOR DETENIDO "+timeDifference,"CIVMONITOR","ProcessDir");
OBJutil.WriteLOG(ConfigurationSettings.AppSettings.Get("LOGpath").ToString(),"","CIVmonitor Detenido por "+timeElapsed,"CIVMONITOR","ProcessDir");
DSproyectos=null; //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.Tables[0].Rows) // LOS ARCHIVOS SE
ALMACENAN UNO A UNO EN UN VECTOR
for(int index=0;index<DSproyectos.Tables[0].Rows.Count;index++)
{
//LLAMAR AL OBJETO QUE VIGILA CARPETAS
CLScontroladora.Controladora.cControl OBJcontroladora = new
CLScontroladora.Controladora.cControl(
DSproyectos.Tables[0].Rows[index].ItemArray[0].ToString(),
//CLInombre
DSproyectos.Tables[0].Rows[index].ItemArray[1].ToString(),
//PROnombre
DSproyectos.Tables[0].Rows[index].ItemArray[2].ToString(), //PROalias
DSproyectos.Tables[0].Rows[index].ItemArray[3].ToString(),
//PROentrada
DSproyectos.Tables[0].Rows[index].ItemArray[4].ToString(), //PROlog
DSproyectos.Tables[0].Rows[index].ItemArray[5].ToString(),
//PRObackup
DSproyectos.Tables[0].Rows[index].ItemArray[6].ToString(),
//PROsalida
DSproyectos.Tables[0].Rows[index].ItemArray[7].ToString(),
//PROextension
DSproyectos.Tables[0].Rows[index].ItemArray[8].ToString(), //PROftp
ConfigurationSettings.AppSettings.Get("Conexion").ToString());
//CONEXION DB
OBJcontroladora.ClasificarData();
}
Thread.Sleep(int.Parse(ConfigurationSettings.AppSettings["Pausa"].ToString())); //PAUSA EN MS PARA QUE NO SE COMA EL SERVICIO LA MAQUINA
}
}
}
}
catch(Exception exp)
{
OBJutil.WriteLOG(ConfigurationSettings.AppSettings.Get("LOGpath").ToString(),"",exp.Message,"CIVMONITOR","ProcessDir");
}
}
private void CrearTabla()
{
SqlConnection connection = null;// SqlConnection that will be used to
execute the sql commands
DSproyectos = new DataSet("Proyectos"); // SAVE PROYECS
try
{
try
{
Debug.WriteLine("INICIALIZANDO CADENA DE CONEXION");
connection = new
SqlConnection(ConfigurationSettings.AppSettings["Conexion"]);
}
catch
{
Debug.WriteLine("ERROR");
CLSutilidades.Utilidades.cUtilidadesSeguimiento OBJutil= new
CLSutilidades.Utilidades.cUtilidadesSeguimiento();//PARA TRABAJAR LOS ARCHIVOS
OBJutil.WriteLOG(ConfigurationSettings.AppSettings.Get("LOGpath").ToString(),"","NO SE PUDO CONECTAR A LA DB","CIVMONITOR","CrearTabla");
return;
}
DSproyectos = SqlHelper.ExecuteDataset(connection,
CommandType.StoredProcedure, "SpGetProyectos", new SqlParameter("@Estado",
"ACT") );
Debug.WriteLine("SE RECUPERO EL DATASET
"+DSproyectos.Tables[0].Rows.Count);
}
catch(Exception exp)
{
string errMessage = "";
for( Exception tempException = exp; tempException != null ; tempException
= tempException.InnerException )
{
errMessage += tempException.Message + Environment.NewLine +
Environment.NewLine;
}
OBJutil.WriteLOG(ConfigurationSettings.AppSettings.Get("LOGpath").ToString(),"","ERROR
AL TRATAR DE CONSULTAR INFORMACION DE CLIENTES/PROYECTOS EN LA DATABASE -
"+exp.Message,"CIVMONITOR","ProcessDir");
OBJutil.WriteLOG(ConfigurationSettings.AppSettings.Get("LOGpath").ToString(),"",exp.Message,"CIVMONITOR","ProcessDir");
}
finally
{
if(connection != null)
connection.Dispose();
}
}
private void Pickup ()
{
try
{
System.Threading.Thread.CurrentThread.Name = "Monitor CIV";
Thread objThread= new Thread(new ThreadStart(ProcessDir));
objThread.Name = "Gestor Directorios";
objThread.Priority = System.Threading.ThreadPriority.Highest;
objThread.Start();
Debug.WriteLine("PASO POR PICKUP ");
}
catch(ThreadAbortException exp)
{
OBJutil.WriteLOG(ConfigurationSettings.AppSettings.Get("LOGpath").ToString(),"",exp.Message,"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.