私は独自のアプリケーションプール(IIS 8)で実行しているWebサイトを持っています。プールの設定はデフォルトです(29時間ごとにリサイクル)。ASP.NET MVC WebサイトのWebサーバーで6GBのRAMを使用するIISワーカープロセス
私たちのWebサーバーは8GBのRAMしか持っていません。私はこのWebサイトのワーカープロセスが定期的に6GBのRAMに上昇し、サーバーをクロールするのに時間がかかることに気付きました。これは現在Webサーバー上にある唯一のサイトです。
また、SQL Express 2016もインストールされています。サイトはEFバージョン6.1.3を使用しています。
MVCサイトは非常に簡単です。これは、テーブルの行を見つけGETPDFコントローラを持って次のようにフィールドに格納されているPDF情報は、ブラウザにそれを提供しています: -
using (eBillingEntities db = new eBillingEntities())
{
try
{
string id = model.id;
string emailaddress = Server.HtmlEncode(model.EmailAddress).ToLower().Trim();
eBillData ebill = db.eBillDatas.ToList<eBillData>().Where(e => e.PURL == id && e.EmailAddress.ToLower().Trim() == emailaddress).FirstOrDefault<eBillData>();
if (ebill != null)
{
// update the 'Lastdownloaded' field.
ebill.LastDownloaded = DateTime.Now;
db.eBillDatas.Attach(ebill);
var entry = db.Entry(ebill);
entry.Property(en => en.LastDownloaded).IsModified = true;
db.SaveChanges();
// Find out from the config record whether the bill is stored in the table or in the local pdf folder.
//
Config cfg = db.Configs.ToList<Config>().Where(c => c.Account == ebill.Account).FirstOrDefault<Config>();
bool storePDFDataInEBillTable = true;
if (cfg != null)
{
storePDFDataInEBillTable = cfg.StorePDFDataInEBillDataTable;
}
// End of Modification
byte[] file;
if (storePDFDataInEBillTable)
{
file = ebill.PDFData;
}
else
{
string pathToFile = "";
if (string.IsNullOrEmpty(cfg.LocalPDFDataFolder))
pathToFile = cfg.LocalBackupFolder;
else
pathToFile = cfg.LocalPDFDataFolder;
if (!pathToFile.EndsWith(@"\"))
pathToFile += @"\";
pathToFile += ebill.PDFFileName;
file = System.IO.File.ReadAllBytes(pathToFile);
}
MemoryStream output = new MemoryStream();
output.Write(file, 0, file.Length);
output.Position = 0;
HttpContext.Response.AddHeader("content-disposition", "attachment; filename=ebill.pdf");
return new FileStreamResult(output, "application/pdf");
}
else
return View("PDFNotFound");
}
catch
{
return View("PDFNotFound");
}
は、ここでは任意のメモリリークはありますか?
ファイルバイト配列とメモリストリームが解放されますか?
また、エンティティフレームワークの参照をクリアするために何か必要なことはありますか?
コードが正常であれば、どこから探し始めるのがよいでしょうか?
よろしく
usingステートメントでメモリストリームをラップすると、「クローズドストリームにアクセスできない」というエラーが表示されます。 (MemoryStream出力=新しいメモリストリーム()) output.Write(file、0、file.Length); output.Position = 0; HttpContext.Response.AddHeader( "content-disposition"、 "attachment; filename = ebill.pdf"); 新しいFileStreamResultを返します(出力、 "application/pdf"); }} –