we are trying to access an API endpoint for 200K times. we are able to access it without an error with the following code snippet:
private static HttpClient clinet = new HttpClient();
public static async Task Main()
{
string auth_token = SASToken.CreateToken(resourceURi, Keyname, key);
clinet.BaseAddress = new Uri(string.Format("https://{0}.servicebus.windows.net/", serviceNamespace));
clinet.DefaultRequestHeaders.TryAddWithoutValidation("Authorization", auth_token);
dynamic obj = new object();
for (int i = 0; i < 50000; i++)
{
obj.randValues.Add(0.145f);
}
obj.sim_Id = "991521f2-632d-4bfe-af76-a216ff29a5ab";
obj.startTime = "2020-11-18T06:10:58.325Z";
obj.EventType = "OPT_Cycle";
string Jdata= Newtonsoft.Json.JsonConvert.SerializeObject(obj);
for (int i = 0; i < 200000; i++)
{
HttpResponseMessage msg = await PostTelemetryAsync(Jdata);
if (msg.StatusCode == System.Net.HttpStatusCode.Created)
{
Console.WriteLine("SUcess Data :" + msg.StatusCode);
}
else
{
Console.WriteLine("fail :" + msg.StatusCode);
}
}
Console.Write(testst);
Console.ReadKey();
}
private static async Task<HttpResponseMessage> PostTelemetryAsync(string data)
{
try
{
var url = string.Format("{0}/messages", hubName);
System.IO.MemoryStream streamcontent = new System.IO.MemoryStream(Encoding.UTF8.GetBytes(data));
streamcontent.Position = 0;
HttpContent content = new StreamContent(streamcontent);`enter code here`
content.Headers.Add("ContentType", "application/json");
return await clinet.PostAsync(url, content);
}
catch (Exception ex)
{
throw ex;
}
}
The above approach took a large time to complete(~180 mins).
is there any other approach to speed it up.