I’m aware of limits on azure app services, like max outbound tcp connections.
Are there recommended configuration settings for using the Mongo C# driver in a busy application hosted on an azure app service. Things like - min/max connection pool size, timeouts, wait queue multiple (although this seems set for deprecation)
Hi @Paul_Allington, thanks for your question!
There’s nothing specific to the driver that needs to be addressed; the limits on Azure App Services still apply.
One thing that is worth mentioning is to instantiate your MongoClient as a singleton in your application, as recommended by the docs. In this way, you can take advantage of connection pooling.
I have it as a singleton yeah. Occasionally we get a big spike in waitqueuefullexceptions. So I wondered what defaults are recommended based on the limits in azure. Like what should be the max connection pool size and the timeouts?
Just to add on, when doing same query with nodejs i send 1000 concurrent request with ramp up period 1 sec from Jmeter and less than 1% request errors out but the same query errors 30-35% request using net core 6, don’t know why
1 Like
Hi Paul, we have just started experiencing this ourselves on a similar set up. Did you get to the bottom of a sensible set of defaults?
Integrating MongoDB with a C# application hosted on Azure App Service involves several key configurations to ensure optimal performance, security, and reliability within the Azure application development framework.
Use Azure Key Vault to manage and retrieve sensitive information like database credentials securely. Implement robust authentication and authorization mechanisms in your application.
Integrate Azure Application Insights with your App Service to monitor performance and diagnose issues. Use MongoDB’s built-in logging to track database performance and errors.
using MongoDB.Driver;
using System;
namespace YourAppNamespace
{
public class MongoDBService
{
private readonly IMongoDatabase _database;
public MongoDBService()
{
var connectionString = Environment.GetEnvironmentVariable("MONGODB_CONNECTION_STRING");
var settings = MongoClientSettings.FromConnectionString(connectionString);
settings.MaxConnectionPoolSize = 100; // Adjust based on your needs
var client = new MongoClient(settings);
_database = client.GetDatabase("YourDatabaseName");
}
// Your database interaction methods here
}
}