尽管设置了频率,Azure SQL 同步仍然会消耗笔记本电脑的资源

标签 azure azure-sql-database

我们有一个在开发笔记本电脑上运行的 SQL 服务器,并且希望部署多台笔记本电脑并使用 Azure 同步将更改分发给每个用户。性能太慢,无法在我们当前的应用程序中使用远程 SQL 数据库——这是一个单独的问题。速度并不重要,而且我预计用户之间不会发生冲突。我将更新设置为 12 小时,并将冲突解决设置为成员(member)获胜。

一切似乎都按预期工作,除了 Microsoft SQL Data Sync 2.0 Windows 服务进程持续消耗 2%-5% 的 CPU 并持续以约 80 kbps 的速度传输数据。我担心笔记本电脑在野外时这会耗尽电池。有更好的方法吗?

这是 Azure 数据库的资源利用率。我在某个时刻停止了同步,看看频率设置是否会自动重新启动它(它不会)。

enter image description here

最佳答案

您可以根据需要编写自己的同步应用程序。 Thisthis资源为您提供良好的指导。下面您将看到一个示例应用程序。

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;



using System.Data.SqlClient;

using Microsoft.Synchronization.Data.SqlServer;

using Microsoft.Synchronization.Data;

using Microsoft.Synchronization;



namespace SQLAzureDataSync

{

    class Program

    {

        public static string sqlazureConnectionString = "Server=[Your SQL Azure Server].database.windows.net;Database=AdventureWorksLTSQLAzure;User ID=[Your SQL Azure User Name]@[Your SQL Azure Server];Password=[Your SQL Azure Password];Trusted_Connection=False;Encrypt=True;";

        public static string sqllocalConnectionString = "Server=(local);Database=AdventureWorksLT2008;Trusted_Connection=True";

        public static readonly string scopeName = "alltablesyncgroup";



        static void Main(string[] args)

        {

            // Test if input arguments were supplied:

            if (args.Length == 0)

            {

                System.Console.WriteLine("Please enter an argument.");

                System.Console.WriteLine("Usage: SyncTest.exe -setup");

                System.Console.WriteLine("       SyncTest.exe -sync");

            }

            else if (args[0] == "-setup")

                Setup();

            else if (args[0] == "-sync")

                Sync();

        }



        public static void Setup()

        {

            try

            {



                SqlConnection sqlServerConn = new SqlConnection(sqllocalConnectionString);

                SqlConnection sqlAzureConn = new SqlConnection(sqlazureConnectionString);

                DbSyncScopeDescription myScope = new DbSyncScopeDescription(scopeName);



                DbSyncTableDescription Customer = SqlSyncDescriptionBuilder.GetDescriptionForTable("Customer", sqlServerConn);

                DbSyncTableDescription Product = SqlSyncDescriptionBuilder.GetDescriptionForTable("Product", sqlServerConn);



                // Add the tables from above to the scope

                myScope.Tables.Add(Customer);

                myScope.Tables.Add(Product);



                // Setup SQL Server for sync

                SqlSyncScopeProvisioning sqlServerProv = new SqlSyncScopeProvisioning(sqlServerConn, myScope);

                if (!sqlServerProv.ScopeExists(scopeName))

                {

                    // Apply the scope provisioning.

                    Console.WriteLine("Provisioning SQL Server for sync " + DateTime.Now);

                    sqlServerProv.Apply();

                    Console.WriteLine("Done Provisioning SQL Server for sync " + DateTime.Now);

                }

                else

                    Console.WriteLine("SQL Server Database server already provisioned for sync " + DateTime.Now);



                // Setup SQL Azure for sync

                SqlSyncScopeProvisioning sqlAzureProv = new SqlSyncScopeProvisioning(sqlAzureConn, myScope);

                if (!sqlAzureProv.ScopeExists(scopeName))

                {

                    // Apply the scope provisioning.

                    Console.WriteLine("Provisioning SQL Azure for sync " + DateTime.Now);

                    sqlAzureProv.Apply();

                    Console.WriteLine("Done Provisioning SQL Azure for sync " + DateTime.Now);

                }

                else

                    Console.WriteLine("SQL Azure Database server already provisioned for sync " + DateTime.Now);



                sqlAzureConn.Close();

                sqlServerConn.Close();

            }

            catch (Exception ex)

            {

                Console.WriteLine(ex);

            }

        }



        public static void Sync()

        {

            try

            {



                SqlConnection sqlServerConn = new SqlConnection(sqllocalConnectionString);

                SqlConnection sqlAzureConn = new SqlConnection(sqlazureConnectionString);

                SyncOrchestrator orch = new SyncOrchestrator

                {

                    LocalProvider = new SqlSyncProvider(scopeName, sqlAzureConn),

                    RemoteProvider = new SqlSyncProvider(scopeName, sqlServerConn),

                    Direction = SyncDirectionOrder.UploadAndDownload

                };

                Console.WriteLine("ScopeName={0} ", scopeName.ToUpper());

                Console.WriteLine("Starting Sync " + DateTime.Now);

                ShowStatistics(orch.Synchronize());



                sqlAzureConn.Close();

                sqlServerConn.Close();

            }

            catch (Exception ex)

            {

                Console.WriteLine(ex);

            }

        }



        public static void ShowStatistics(SyncOperationStatistics syncStats)

        {

            string message;



            message = "\tSync Start Time :" + syncStats.SyncStartTime.ToString();

            Console.WriteLine(message);

            message = "\tSync End Time   :" + syncStats.SyncEndTime.ToString();

            Console.WriteLine(message);

            message = "\tUpload Changes Applied :" + syncStats.UploadChangesApplied.ToString();

            Console.WriteLine(message);

            message = "\tUpload Changes Failed  :" + syncStats.UploadChangesFailed.ToString();

            Console.WriteLine(message);

            message = "\tUpload Changes Total   :" + syncStats.UploadChangesTotal.ToString();

            Console.WriteLine(message);

            message = "\tDownload Changes Applied :" + syncStats.DownloadChangesApplied.ToString();

            Console.WriteLine(message);

            message = "\tDownload Changes Failed  :" + syncStats.DownloadChangesFailed.ToString();

            Console.WriteLine(message);

            message = "\tDownload Changes Total   :" + syncStats.DownloadChangesTotal.ToString();

            Console.WriteLine(message);

        }

    }

}

关于尽管设置了频率,Azure SQL 同步仍然会消耗笔记本电脑的资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52519354/

相关文章:

azure - 使用 az cli 在 azure 中创建文件共享

Azure 媒体服务 - 允许流式传输到特定域

node.js - 在 Azure SQL 上续写 "Connection closed"

azure - 如何检查Azure SQL数据库中特定用户的所有访问权限?

sql-server - 无法通过 EF ExecuteSqlCommand 重建索引

c# - EF 6 System.Data.Objects.ObjectContext 错误

azure - Azure Kubernetes 服务上的 Istio?

Azure Powershell 命令在我的资源组下找不到我的 VM?

azure - Azure 上的架构更新 : Column name does not exist

azure - Azure Web SQL 数据库的 session 数量是否有限制?