为什么我的网站提供88%的CPU [英] why my web site give 88% of CPU

查看:64
本文介绍了为什么我的网站提供88%的CPU的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的网站名称是nezamerafsanjan,我用asp.net mvc 4写它

看看这个图片: 88%CPU



我的主页代码:

 < span class =code-keyword> public  ActionResult Index()
{

HttpCookie username = Request.Cookies [ nezamcookie];
if (用户名!= null && User.Identity.IsAuthenticated == < span class =code-keyword> false )
{
string us = username.Values [ UserName]。ToString();
string ps = username.Values [ 。密码]的ToString();
WebSecurity.Login(us,ps,persistCookie: true );
// ControllerContext.HttpContext.Response.Redirect(Request.UrlReferrer.ToString());
}
// CreateDate = DateTime.Parse((persian.GetYear(r.CreateDate) )+/+ persian.GetMonth(r.CreateDate)+/+ persian.GetDayOfMonth(r.CreateDate))),
// UpdateDate = DateTime.Parse((persian.GetYear(r.UpdateDate)+/+ persian.GetMonth(r.UpdateDate)+/+ persian.GetDayOfMonth (r.UpdateDate)))
var Query = _db.News.Take( 30 < /跨度>);
var model =( from r in Query.AsEnumerable()
orderby r.CreateDate 降序
< span class =code-sdkkeyword>选择
new NewsHomeViewModel
{

Id = r.Id,
ImageUrl = r.ImageUrl,
摘要= r.Summary,
Title = r.Title,
UpdateDate =((persian.GetYear(r.UpdateDate)+ / + persian.GetMonth(r.UpdateDate)+ / + persian.GetDayOfMonth(r.UpdateDate)))
})。德e( 6 );
var modelSpecial =( from r in Query.AsEnumerable()
orderby r.CreateDate 降序
< span class =code-sdkkeyword> where
r.Special == true
select new NewsHomeViewModel
{

Id = r.Id,
ImageUrl = r.ImageUrl,
摘要= r.Summary,
Title = r.Title,
UpdateDate =((persian.GetYear(r.UpdateDate)+ / + persian.GetMonth(r.UpdateDate)+ / + persian.GetDayOfMonth(r.UpdateDate)))
})。Take( 12 );
var modelEducation =( from r in Query.AsEnumerable()
orderby r.CreateDate 降序
< span class =code-sdkkeyword> where r.Education == true
select new NewsHomeViewModel
{

Id = r.Id,
ImageUrl = r.ImageUrl,
摘要= r.Summary,
Title = r.Title,
UpdateDate =((persian.GetYear(r.UpdateDate)+ / + persian.GetMonth(r.UpdateDate)+ / + persian.GetDayOfMonth(r.UpdateDate)))
})。Take( 6 );
ViewBag.model = model;
ViewBag.NewsViewModelSpecial = modelSpecial;
ViewBag.modelEducation = modelEducation;
return View();
}





我的代码是新闻页面:

 [OutputCache(Duration =  360 ,VaryByHeader =   X-Requested-With,Location = OutputCacheLocation.Server)] 
public ActionResult Index( int page = 1
{

var model =( from r in db.News.AsEnumerable()
orderby r.CreateDate 降序
选择 new NewsViewModel
{
Body = r.Body,
评论= r.Comments,
教育= r.Education,
财务= r.Financial,
Id = r.Id,
ImageUrl = r.ImageUrl,
Notic = r.Notic,
Public = r.Public,
Refahi = r.Refahi,
Special = r.Special,
Summary = r.Summary,
Title = r.Title,
Visitors = r.Visitors,
CreateDate =((persian.GetYear(r.CreateDate)+ / + persian.GetMonth(r.CreateDate)+ / + persian.GetDayOfMonth(r.CreateDate))),
UpdateDate =((persian.GetY ear(r.UpdateDate)+ / + persian.GetMonth(r.UpdateDate)+ / + persian.GetDayOfMonth(r.UpdateDate)))
})。ToPagedList(page , 6 );
ViewData [ 新闻] = model;
if (Request.IsAjaxRequest())
{
return PartialView( _ PartialNews,ViewData [ 新闻]);
}

return View();
}





i不知道为什么这个应用程序在我的主机上传它时会产生大量的CPU和内存?

解决方案

您好 NorouzFar ,您的代码似乎没有问题但是关于消费,测试这个的最好方法是尝试仅上传一些html页面或主机上的其他网站,并检查您的代码是否导致此问题或主机本身存在问题。

my web site name is "nezamerafsanjan" and i writ it with asp.net mvc 4
look at this picutre:88%CPU

my code in Home Page :

public ActionResult Index()
       {

           HttpCookie username = Request.Cookies["nezamcookie"];
           if (username != null && User.Identity.IsAuthenticated == false)
           {
               string us = username.Values["UserName"].ToString();
               string ps = username.Values["Password"].ToString();
               WebSecurity.Login(us, ps, persistCookie: true);
               //ControllerContext.HttpContext.Response.Redirect(Request.UrlReferrer.ToString());
           }
           // CreateDate =DateTime.Parse( (persian.GetYear(r.CreateDate) + "/" + persian.GetMonth(r.CreateDate) + "/" + persian.GetDayOfMonth(r.CreateDate))),
           //         UpdateDate =DateTime.Parse ((persian.GetYear(r.UpdateDate) + "/" + persian.GetMonth(r.UpdateDate) + "/" + persian.GetDayOfMonth(r.UpdateDate)))
           var Query = _db.News.Take(30);
           var model = (from r in Query.AsEnumerable()
                        orderby r.CreateDate descending
                        select new NewsHomeViewModel
                        {

                            Id = r.Id,
                            ImageUrl = r.ImageUrl,
                            Summary = r.Summary,
                            Title = r.Title,
                            UpdateDate = ((persian.GetYear(r.UpdateDate) + "/" + persian.GetMonth(r.UpdateDate) + "/" + persian.GetDayOfMonth(r.UpdateDate)))
                        }).Take(6);
           var modelSpecial = (from r in Query.AsEnumerable()
                               orderby r.CreateDate descending
                               where r.Special == true
                               select new NewsHomeViewModel
                               {

                                   Id = r.Id,
                                   ImageUrl = r.ImageUrl,
                                   Summary = r.Summary,
                                   Title = r.Title,
                                   UpdateDate = ((persian.GetYear(r.UpdateDate) + "/" + persian.GetMonth(r.UpdateDate) + "/" + persian.GetDayOfMonth(r.UpdateDate)))
                               }).Take(12);
           var modelEducation = (from r in Query.AsEnumerable()
                                 orderby r.CreateDate descending
                                 where r.Education == true
                                 select new NewsHomeViewModel
                               {

                                   Id = r.Id,
                                   ImageUrl = r.ImageUrl,
                                   Summary = r.Summary,
                                   Title = r.Title,
                                   UpdateDate = ((persian.GetYear(r.UpdateDate) + "/" + persian.GetMonth(r.UpdateDate) + "/" + persian.GetDayOfMonth(r.UpdateDate)))
                               }).Take(6);
           ViewBag.model = model;
           ViewBag.NewsViewModelSpecial = modelSpecial;
           ViewBag.modelEducation = modelEducation;
           return View();
       }



my code is news page:

[OutputCache(Duration=360,VaryByHeader="X-Requested-With",Location= OutputCacheLocation.Server)]
        public ActionResult Index(int page = 1)
        {
            
            var model = (from r in db.News.AsEnumerable()
                         orderby r.CreateDate descending
                         select new NewsViewModel
                         {
                             Body = r.Body,
                             Comments = r.Comments,
                             Education = r.Education,
                             Financial = r.Financial,
                             Id = r.Id,
                             ImageUrl = r.ImageUrl,
                             Notic = r.Notic,
                             Public = r.Public,
                             Refahi = r.Refahi,
                             Special = r.Special,
                             Summary = r.Summary,
                             Title = r.Title,
                             Visitors = r.Visitors,
                             CreateDate = ((persian.GetYear(r.CreateDate) + "/" + persian.GetMonth(r.CreateDate) + "/" + persian.GetDayOfMonth(r.CreateDate))),
                             UpdateDate = ((persian.GetYear(r.UpdateDate) + "/" + persian.GetMonth(r.UpdateDate) + "/" + persian.GetDayOfMonth(r.UpdateDate)))
                         }).ToPagedList(page,6);
            ViewData["News"] = model;
            if (Request.IsAjaxRequest())
            {
                return PartialView("_PartialNews", ViewData["News"]);
            }
            
            return View();
        }



i dont know why this application give a lot of CPU and Memory when i upload it on my Host?

解决方案

Hi NorouzFar, You code doesn't appears problematic but regarding the consumption, the best way to test this is try uploading some html page only or some other website on the host and check if your code is causing this or the Host itself has an issue.


这篇关于为什么我的网站提供88%的CPU的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆