dotnet / EntityFramework.Docs

Documentation for Entity Framework Core and Entity Framework 6
https://docs.microsoft.com/ef/
Creative Commons Attribution 4.0 International
1.63k stars 1.96k forks source link

Guidance for Cosmosdb Options in the Documentation #4189

Closed fgalarraga closed 1 year ago

fgalarraga commented 1 year ago

Went through the example options below:

Cosmos options

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
    => optionsBuilder.UseCosmos(
        "AccountEndpoint=https://localhost:8081/;AccountKey=C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==",
        databaseName: "OptionsDB",
        options =>
        {
            options.ConnectionMode(ConnectionMode.Gateway);
            options.WebProxy(new WebProxy());
            options.LimitToEndpoint();
            options.Region(Regions.AustraliaCentral);
            options.GatewayModeMaxConnectionLimit(32);
            options.MaxRequestsPerTcpConnection(8);
            options.MaxTcpConnectionsPerEndpoint(16);
            options.IdleTcpConnectionTimeout(TimeSpan.FromMinutes(1));
            options.OpenTcpConnectionTimeout(TimeSpan.FromMinutes(1));
            options.RequestTimeout(TimeSpan.FromMinutes(1));
        });

There are certain options that do not work with "ConnectionMode.Gateway" when we look at the "CosmosClientOptions Class" documentation which is referenced in the doc. It clearly states that many of the timeout settings are for "(Direct/TCP)" only.

When running our project, the following options work fine for local Cosmosdb emulator:

        .UseCosmos(ConnectionString, DatabaseName, options =>
        {
            options.ConnectionMode(ConnectionMode.Gateway);
            options.LimitToEndpoint();
            options.RequestTimeout(TimeSpan.FromMinutes(1));
        })

We have set our options to the following for a CosmosDb on Azure:

        .UseCosmos(ConnectionString, DatabaseName, options =>
            {
                options.ConnectionMode(ConnectionMode.Direct);
                options.LimitToEndpoint();
                options.GatewayModeMaxConnectionLimit(32);
                options.MaxRequestsPerTcpConnection(8);
                options.MaxTcpConnectionsPerEndpoint(16);
                options.IdleTcpConnectionTimeout(TimeSpan.FromMinutes(1));
                options.OpenTcpConnectionTimeout(TimeSpan.FromMinutes(1));
                options.RequestTimeout(TimeSpan.FromMinutes(1));
            })

Is there guidance on running EF with Cosmosdb with the emulator vs on Azure? If so, could this page be updated to give that guidance?

Thank you, Frank Galarraga (@fgalarraga) & Matt Beasley (@mattbeasley96)


Document Details

Do not edit this section. It is required for learn.microsoft.com ➟ GitHub issue linking.

ajcvickers commented 1 year ago

Note from triage: we could add a note here indicating that not all these options are used together, but it does seem very unlikely that anyone would really want to do this, rather than choose the options that make sense for the way Cosmos is currently being used.