我使用REST的服務,需要在以下方式Bacis驗證:使用REST的服務 - 第一次花費更長的時間如下要求
private void button1_Click(object sender, EventArgs e) {
try {
var url = "http://172.34.1.111:8088/ustrich/rest/projects/pid/1234";
using (var wc = this.CreateWebClient(url)) {
var stopWatch = new Stopwatch();
stopWatch.Start();
var s = wc.DownloadString(url);
stopWatch.Stop();
this.label1.Text = stopWatch.Elapsed.ToString();
this.textBox1.Text = s;
}
} catch (Exception ex) {
this.textBox1.Text = ex.ToString();
}
}
protected WebClient CreateWebClient(string url) {
var webClient = new WebClient();
var cache = new CredentialCache { { new Uri(url), "Basic", new NetworkCredential("rest", "rest") } };
webClient.Credentials = cache;
webClient.Headers.Add("Content-Type", "text/xml; charset=utf-8");
webClient.Encoding = Encoding.UTF8;
return webClient;
}
問題是現在,當我開始我的試驗 - 應用程序並執行此代碼,這是wc.DownloadString(url)第一次需要大約5秒。接下來的電話,當我點擊按鈕上的第二個等時間時,它只需要300ms。 現在我的問題:我的代碼中有什麼問題嗎?我可以在那裏優化某些內容以解決首次通話需要5秒的問題嗎? 感謝您的幫助。
這就是IIS的工作方式,新的內容必須在首次處理時處理。 – Alex 2012-07-26 08:03:46
什麼類型的應用程序是測試應用程序? – 2012-07-26 08:13:53
您的應用是以5秒爲準還是RESTful API以5秒爲首次打擊? – 2012-07-26 08:14:47