为什么通过 Internet 或 VPN 连接到 postgres 比 sql server 慢?我有测试
DateTime now0 = System.DateTime.Now;
string sqlconnectsrting = "server=xxx.xxx.xxx.xxx;database=pubs;uid=sa;pwd=";
for (int i = 0; i < 1000; i++)
{
SqlConnection connect = new SqlConnection(sqlconnectsrting);
connect.Open();
connect.Close();
}
System.DateTime now1 = System.DateTime.Now;
Console.WriteLine(String.Format("SQL Connect time : {0}", now1 - now0));
now0 = System.DateTime.Now;
string npgconnectsrting = "Server=xxx.xxx.xxx.xxx;Port=5433;User Id=postgres;Password=postgres;Database=hr_data;";
for (int i = 0; i < 1000; i++)
{
NpgsqlConnection connect = new NpgsqlConnection(npgconnectsrting);
connect.Open();
connect.Close();
}
now1 = System.DateTime.Now;
Console.WriteLine(String.Format("Postgres Connect time : {0}", now1 - now0));
当连接是本地主机时,它们是相似的,但是当连接是通过互联网时。SQL 连接需要 1-5 秒,但 postgres 需要 3-7 分钟。有没有什么办法解决这一问题?
团黄英