我创建了一个Web服务,可以访问Microsoft Analysis Services Cube中的数据。我想看看webservice将如何执行,所以我生成了简单的控制台应用程序,它生成了' x'线程和每个线程使得' y'对Web服务的请求。
控制台应用
static int counter = 0;
static void Main(string[] args)
{
WaitCallback callBack;
callBack = new WaitCallback(RunAsync);
for (var i = 0; i < 7; i++)
{
Console.WriteLine("openeed thread:" + i);
ThreadPool.QueueUserWorkItem(callBack, i);
}
Console.ReadLine();
}
private static void RunAsync(object state)
{
for (var i = 0; i < 200; i++)
{
using (var client = new HttpClient())
{
client.BaseAddress = new Uri("http://localhost:49425/");
client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", "some data");
var x = client.GetAsync('URL');
if (x.Result.IsSuccessStatusCode)
{
var result = x.Result.Content.ReadAsAsync<float>();
}
Interlocked.Increment(ref counter);
Console.WriteLine(counter + " Thread : "+ state + " # request " + i);
}
}
}
}
以下是在网络服务上调用的方法:
public float GetTurnover(Guid ClientUid, int startDate, int endDate)
{
float returnValue = 0.0f;
var cn = new AdomdConnection();
cn.ConnectionString = Constants.CubeConnectionString;
try
{
var open = Task.Run(() => cn.Open());
Task.WaitAll(open);
}
catch
{
}
var mdxQuery = new StringBuilder();
// string test = @"some query";
using (var command = new AdomdCommand(query, cn))
{
DataTable dt = new DataTable();
dt.Columns.Add("Amount", typeof(float));
try
{
var data = command.ExecuteReader();
dt.Load(data);
var close = Task.Run(() => cn.Close());
Task.WaitAll(close);
float.TryParse(dt.Rows[0].ItemArray[1].ToString(), out returnValue);
return returnValue;
}
catch
{
}
return returnValue;
}
这一行:var open = Task.Run(() => cn.Open());
有时会在100-150个请求之后中断,这是不一致的。我在IIS和Cube上增加了同时连接的#,但它似乎没有帮助。
任何想法是什么打破?
修改
Stacktrace:
Microsoft.AnalysisServices.AdomdClient.AdomdConnectionException was unhandled by user code
HResult=-2146233088
Message=The connection either timed out or was lost.
Source=Microsoft.AnalysisServices.AdomdClient
StackTrace:
at Microsoft.AnalysisServices.AdomdClient.XmlaClient.EndRequest()
at Microsoft.AnalysisServices.AdomdClient.XmlaClient.SendMessage(Boolean endReceivalIfException, Boolean readSession, Boolean readNamespaceCompatibility)
at Microsoft.AnalysisServices.AdomdClient.XmlaClient.Discover(String requestType, String requestNamespace, ListDictionary properties, IDictionary restrictions, Boolean sendNamespacesCompatibility)
at Microsoft.AnalysisServices.AdomdClient.XmlaClient.SupportsProperty(String propName)
at Microsoft.AnalysisServices.AdomdClient.XmlaClient.Connect(ConnectionInfo connectionInfo, Boolean beginSession)
at Microsoft.AnalysisServices.AdomdClient.AdomdConnection.XmlaClientProvider.Connect(Boolean toIXMLA)
at Microsoft.AnalysisServices.AdomdClient.AdomdConnection.XmlaClientProvider.Microsoft.AnalysisServices.AdomdClient.AdomdConnection.IXmlaClientProviderEx.ConnectXmla()
at Microsoft.AnalysisServices.AdomdClient.AdomdConnection.ConnectToXMLA(Boolean createSession, Boolean isHTTP)
at Microsoft.AnalysisServices.AdomdClient.AdomdConnection.Open()
at DataAccess.Repositories.DashboardRepository.<>c__DisplayClass4.<GetTurnover>b__0() in :line 27
at System.Threading.Tasks.Task.InnerInvoke()
at System.Threading.Tasks.Task.Execute()
InnerException: System.Net.WebException
HResult=-2146233079
Message=The remote server returned an error: (503) Server Unavailable.
Source=System
StackTrace:
at System.Net.HttpWebRequest.GetResponse()
at Microsoft.AnalysisServices.AdomdClient.HttpStream.GetResponseStream()
at Microsoft.AnalysisServices.AdomdClient.HttpStream.GetResponseDataType()
InnerException: