웹 서비스는 때때로 크게 느려집니다
-
19-09-2019 - |
문제
우리 회사는 C#/asp.net으로 작성된 웹 서비스에 문제가 발생하고 있습니다. 이 서비스는 SQL Server의 데이터에 대한 ID 키 와이 데이터에 대한 PDF 보고서를 생성하고 저장하는 경로를 수신합니다.
대부분의 경우,이 웹 서비스는 일반적으로 최대 몇 초 안에 호출 웹 페이지에 결과를 매우 빠르게 반환합니다.
그러나 때때로 상당한 둔화에 도달하는 것 같습니다. 웹 서비스를 호출하는 웹 응용 프로그램은이 속도가 저하 될 때 타임 아웃 오류가 발생합니다. 우리는 확인했고 PDF가 서버에 생성되어 저장되므로 웹 서비스가 결국 실행되는 것처럼 보입니다. 처리가 완료되는 데 약 1 ~ 2 분이 걸리는 것 같습니다. PDF는 데이터 역학에서 ActiveReports를 사용하여 생성됩니다.
이 문제가 발생하면 웹 서비스의 구성 파일 (예 : Connection String 라인에 빈 공간을 추가)을 작은 변경하는 것은 웹 서비스를 다시 시작하는 것으로 보이며 그 후에는 모든 것이 완벽하게 괜찮습니다.
동일한 웹 서버에서 실행중인 다른 웹 애플리케이션은 이러한 유형의 동작을 경험하지 않고이 특정 웹 서비스 만 경험하지 않는 것 같습니다.
아래 웹 서비스 코드를 추가했습니다. 타사 라이브러리에 대한 기본 전화입니다. 우리는 테스트 에서이 문제를 재현 할 수 없습니다.
이 문제의 원인이 무엇인지 궁금합니다.
[WebMethod]
public string Publish(int identity, string transactionType, string directory, string filename)
{
try
{
AdpConnection Conn = new AdpConnection(ConfigurationManager.AppSettings["myDBConnString"]);
AdpCommand Cmd = new AdpCommand("storedproc_GetData", oConn);
AdpParameter Param;
Cmd.CommandType = CommandType.StoredProcedure;
Param = Cmd.CreateParameter("@Identity", DbType.Int32);
Param.Value = identity;
Cmd.Parameters.Add(oParam);
Conn.Open();
string aResponse = Cmd.ExecuteScalar().ToString();
Conn.Close();
if (transactionType == "typeA")
{
//Parse response
DataSet dsResponse = ParseDataResponse(aResponse);
//dsResponse.WriteXml(@ConfigurationManager.AppSettings["DocsDir"] + identity.ToString() + ".xml");
DataDynamics.ActiveReports.ActiveReport3 rpt = new DataDynamics.ActiveReports.ActiveReport3();
rpt.LoadLayout(@ConfigurationManager.AppSettings["myReportPath"] + "TypeA.rpx");
rpt.AddNamedItem("ReportPath", @ConfigurationManager.AppSettings["myReportPath"]);
rpt.AddNamedItem("XMLSTRING", FormatXML(dsResponse.GetXml()));
DataDynamics.ActiveReports.DataSources.XMLDataSource xmlds = new DataDynamics.ActiveReports.DataSources.XMLDataSource();
xmlds.FileURL = null;
xmlds.RecordsetPattern = "//DataPatternA";
xmlds.LoadXML(FormatXML(dsResponse.GetXml()));
if (!System.IO.Directory.Exists(@ConfigurationManager.AppSettings["DocsDir"] + directory + @"\"))
{
System.IO.Directory.CreateDirectory(@ConfigurationManager.AppSettings["DocsDir"] + directory + @"\");
}
string sXML = FormatXML(dsResponse.GetXml());
StreamWriter sw = new StreamWriter(@ConfigurationManager.AppSettings["DocsDir"] + directory + @"\" + filename + ".xml", false);
sw.Write(sXML);
sw.Close();
rpt.DataSource = xmlds;
rpt.Run(true);
DataDynamics.ActiveReports.Export.Pdf.PdfExport xPdf = new DataDynamics.ActiveReports.Export.Pdf.PdfExport();
xPdf.Export(rpt.Document, @ConfigurationManager.AppSettings["DocsDir"] + directory + @"\" + filename + ".pdf");
}
}
catch(Exception ex)
{
return "Error: " + ex.ToString();
}
return @ConfigurationManager.AppSettings["DocsDir"] + directory + @"\" + filename + ".pdf";
}
해결책
짧은 참고 사항 : 스트림 라이터를 처분하지 않고 서비스에 다른 일회용 객체도있을 수 있습니다. 이로 인해 앱에서 메모리 누출이 발생하여 IIS가 작업자 프로세스를 다시 시작할 수 있습니다. 이것은 아마도 당신의 문제에 대한 해결책이 아닐지라도 일회용 객체를 처분하면 미래의 문제를 예방하는 데 도움이 될 것입니다!
다른 팁
이것이 진정한 문제가 어디에 있는지 알면 IIS를 디버깅해야합니다.
당신은 사용해야합니다 IIS 디버그 진단 도구 무슨 일이 일어나고 있는지 결정하는 데 도움이됩니다.
나는 또한 읽을 것이다 테스 페란데즈의 블로그 디버깅시 IIS 문제.