Web Api 2 - RAM使用情况

时间:2014-03-26 13:23:46

标签: c# asp.net asp.net-mvc web-services asp.net-web-api

我在共享主机上运行我的Web服务,它在应用程序池上提供高达100MB的RAM 我的Web服务有大约12个控制器并使用异步实体框架+使用缓存: https://github.com/filipw/AspNetWebApi-OutputCache

对于测试,服务会响应非常少量的数据 - 例如,20个客户的列表,包含他们的地址和联系人数据,没有图像等。

启动(第一次请求)后,Web服务在另外几个请求之后使用最多144MB RAM,它使用了大约250-350MB RAM - 而不是服务器回收我的服务。

这个数据量和控制器的RAM使用率是否正常?或者在优化方面存在问题吗?

我是WebApi的新手,我正在撰写论文,但我尝试使用Entity Framework等对数据库进行异步访问。

编辑:在服务器上设置32位模式后,RAM使用率约为100-130Mb,这比以前明显更好,但我还是不确定它是否有好结果。

这里我包含了我的控制器样本,以获取所有客户列表:

    // READ ALL -GET
    // ROUTE /api/Customers/
    [HttpGet]
    [CacheOutput(ClientTimeSpan = 30, ServerTimeSpan = 86400)]
    public async Task<IHttpActionResult> GetCustomers()
    {
        using (var db = new ApplicationDbContext())
        {
            var customers = await db.Customers
                .Include(s => s.Address)
                .Include(s => s.Contact)
                .Include(s => s.Company).ToListAsync<Customer>();
            if (customers == null)
                return NotFound();

            List<CustomerViewModel> viewCustomers = new List<CustomerViewModel>();

            foreach (var c in customers)
            {
                CustomerViewModel customer = new CustomerViewModel{
                    Id = c.CustomerId,
                    FirstName = c.FirstName,
                    LastName = c.SureName,
                    ICO = c.ICO,
                    Notes = c.Notes,
                    Street = c.Address.Street,
                    Number = c.Address.Number,
                    ZipCode = c.Address.ZipCode,
                    City = c.Address.City,
                    Country = c.Address.Country,
                    MobileAreaCode = c.Contact.MobileAreaCode,
                    MobileNumber = c.Contact.MobileNumber,
                    Email = c.Contact.Email,
                    TelephoneAreaCode = c.Contact.TelephoneAreaCode,
                    TelephoneNumber = c.Contact.TelephoneNumber
                };
                if (c.Company != null)
                    customer.CompanyId = (int)c.CompanyId;
                else
                    customer.CompanyId = -1;
                viewCustomers.Add(customer);
            }
            return Ok(viewCustomers);
        }
    }

0 个答案:

没有答案