gpt4 book ai didi

asp.net - 我如何获得更好的网站性能

转载 作者:行者123 更新时间:2023-12-04 14:50:22 24 4
gpt4 key购买 nike

你好!

我在 Windows 2008 服务器上运行 IIS7。
在偷看时间,我们有以下行为:

  • CPU 负载接近空闲
  • 请求排队(由资源监视器监控)
  • 执行时间超过 10 秒

  • 1-4) 请参阅以前的版本和编辑

    5) 异步操作

    按照建议,我创建了一个简单的网页……一页……带有以下代码隐藏:
    using System;
    using System.Threading;
    using System.Web;
    using System.Web.UI;

    namespace PerformanceTest
    {
    public partial class AsyncPage : Page
    {
    protected override void OnInit(EventArgs e)
    {
    base.OnInit(e);

    var pageAsyncTask = new PageAsyncTask(this.BeginAsyncOperation, this.EndAsyncOperation, this.TimeoutAsyncOperation, null);
    this.RegisterAsyncTask(pageAsyncTask);
    // or
    //this.AddOnPreRenderCompleteAsync(this.BeginAsyncOperation, this.EndAsyncOperation);

    // this might be useful for doing cleanup or sth alike
    this.PreRenderComplete += HandlePreRenderComplete;
    }

    private void HandlePreRenderComplete(object sender, EventArgs e)
    {
    this.Trace.Write("HandlePreRenderComplete");
    this.Trace.Write(string.Format("managedThreadId #{0}", Thread.CurrentThread.ManagedThreadId));
    }

    private delegate void Sleep(int miliseconds);

    private IAsyncResult BeginAsyncOperation(object sender, EventArgs e, AsyncCallback asyncCallback, object state)
    {
    this.Trace.Write("BeginAsyncOperation");
    this.Trace.Write(string.Format("managedThreadId #{0}", Thread.CurrentThread.ManagedThreadId));

    var sleep = new Sleep(Thread.Sleep);
    return sleep.BeginInvoke(1000, asyncCallback, state);
    }

    private void EndAsyncOperation(IAsyncResult asyncResult)
    {
    this.Trace.Write("EndAsyncOperation");
    this.Trace.Write(string.Format("managedThreadId #{0}", Thread.CurrentThread.ManagedThreadId));
    }

    private void TimeoutAsyncOperation(IAsyncResult asyncResult)
    {
    this.Trace.Write("TimeoutAsyncOperation");
    this.Trace.Write(string.Format("managedThreadId #{0}", Thread.CurrentThread.ManagedThreadId));
    }
    }
    }

    看起来很不错,不是吗?实际上它没有任何改变,因为压力超过 30 秒,响应时间高达 8 秒,CPU 使用率接近 0%。

    6) 更新 machine.config
    <system.net>
    <connectionManagement>
    <add address="*" maxconnection="12" />
    </connectionManagement>
    </system.net>
    <system.web>
    <processModel autoConfig="true"
    maxWorkerThreads="100"
    maxIoThreads="100"
    minWorkerThreads="50"
    minIoThreads="50" />
    <httpRuntime minFreeThreads="88"
    minLocalRequestFreeThreads="76" />

    </system.web>

    最佳答案

    关于asp.net - 我如何获得更好的网站性能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7580445/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com