Windows worker service WebApplication api memory problem

43 views Asked by At

I have a windows worker service and it collects lots of realtime data in memory. I create a WebApplication in this service and serve thousands data from api request. But with every request, memory usage increases. Memory just increases with every request. Think that 100 requests per seconds. How can i prevent memory usage with every request? Here is my api code:

 [HttpPost]
 [Route("get/")]
 [MatriksAuthorize]
 public async IAsyncEnumerable<TradePackage> GetTick([FromForm] int symbolId, [FromForm] int exchangeId, [FromForm] string subMarketCode)
 {
 
 var termId = RouteData.Values["TermId"]?.ToString();
 var categoryId = RouteData.Values["CategoryId"]?.ToString();
 if (string.IsNullOrEmpty(termId)) yield return null; ;

 var licenses = _userLicenseManager.GetUserLicense(termId, categoryId);
 var result = _tickDataCollector.GetTickData(symbolId, licenses, exchangeId, subMarketCode);
 if (result != null)
     foreach (TradePackage tradePackageBase in result)
     {
         yield return tradePackageBase;
     }
 
 }

Here is my data structure:

public class TradePackage
{  
[JsonPropertyName("d")]
public virtual bool IsDelayed { get; set; }

[JsonPropertyName("r")]
public bool IsRefresh { get; set; }

[JsonPropertyName("bt")]
public bool IsBlockTrade { get; set; }

[JsonPropertyName("i")]
public int SymbolId { get; set; }

[JsonPropertyName("tno")]
public uint TransactionNo { get; set; }

[JsonPropertyName("p")]
public double Price { get; set; }

[JsonPropertyName("sz")]
public double Size { get; set; }

[JsonPropertyName("ba")]
public BidAsk BidAsk { get; set; }

[JsonPropertyName("no")]
public bool NoHasTransactionDirection { get; set; }

[JsonPropertyName("b")]
public int BuyerId { get; set; }

[JsonPropertyName("s")]
public int SellerId { get; set; }

[JsonPropertyName("t")]
public TimeSpan TimeStamp { get; set; }
}
0

There are 0 answers