本文主要对PostgreSql在Windows下的连接测试。

测试环境: Win7 x64, PostgreSql 10.1 x64

测试语言: VS2015 C#

因为Pg的数据库连接是开启进程来处理的,不像MySQL一样是线程处理。在Windows下开启进程是比较耗时耗资源,不像Linux开启进程。

所以,我做了个测试:循环开启200个线程分别去连接Pg,开启连接后不主动关闭;并且让线程等待300秒也不去主动关闭,以确认Pg开启的进程数。

测试结果: Pg进程数并不会随着连接数的增加而增加,而是保持一定数量不变。

而后,又修改代码,去掉多线程连接数据库,只用主线程连接,还是开200个连接,结果: Pg进程只增加了1,并保持不变。

注:正常情况下,什么都不做,系统会保持8个常驻进程。

以下是测试截图和测试代码:

 using System;
using System.Threading;
using Pg.Model; namespace PgConnectTest
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("正在测试连接进程...200个进程");
int proCount = ;
while (proCount <= )
{
Console.WriteLine($"开启第{proCount}个线程连接Postgres...");
ThreadPool.QueueUserWorkItem(state =>
{
var db = new MesDbContext();
db.Users.Add(new User() {Account = "", Passwd = "", Label = "shanghai"});
db.SaveChanges();
Thread.Sleep();
});
proCount++;
Thread.Sleep();
}
}
}
}
 using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema; namespace Pg.Model
{
public class Model
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public long Id { get; set; }
public DateTime CreTime { get; set; } = DateTime.Now;
public long? CreUid { get; set; }
public DateTime? UpdTime { get; set; }
public long? UpdUid { get; set; }
public string Remark { get; set; }
public bool IsDel { get; set; } = false;
} [Table("User")]
public class User : Model
{
//[Index(IsUnique = true)]
public string Account { get; set; }
public string Passwd { get; set; }
public string Label { get; set; }
} }
 using System.Data.Entity;
using System.Data.Entity.Migrations; namespace Pg.Model
{
public class MesDbContext: DbContext
{
public MesDbContext():base("name=mes")
{
Database.SetInitializer(new MigrateDatabaseToLatestVersion<MesDbContext, MigrateConfig>());
} public DbSet<User> Users { get; set; }
} public class MigrateConfig : DbMigrationsConfiguration<MesDbContext>
{
public MigrateConfig()
{
AutomaticMigrationsEnabled = true;
AutomaticMigrationDataLossAllowed = true;
}
} }

========= 2017.11.19 以下===============

又经过推敲,其实跟写的代码有关系,

如果是用framework的线程池 ThreadPool.QueueUserWorkItem(state => { }); ,其实不会连续开启很多线程,差不多我测试的结果是开启7个线程。

如果是换作 Task.Run(() => { }); 任务,那么情况差不多,Pg进程开启的数量也是10几个。

但是,如果是直接 new Thread(() => {}) 方式,那么甚至会开启上百个Pg进程

极端,如果是只使用主线程,那么只会开启一个Pg进程。

PostgreSQL On Windows Process Connection Performance的更多相关文章

  1. 为应用程序池“XX”提供服务的进程在与 Windows Process Activation Service 通信时出现严重错误

    场景 WCF应用程序部署在IIS7中,使用net.tcp协议对外给几百台客户端提供服务,应用程序池不断崩溃重启. 分析过程 在事件查看器中看到的错误信息类似于 为应用程序池“XX”提供服务的进程在与 ...

  2. IIS启动失败,启动Windows Process Activation Service时,出现错误13:数据无效 ;HTTP 错误 401.2 - Unauthorized 由于身份验证头无效,您无权查看此页

    因为修改过管理员账号的密码后重启服务器导致IIS无法启动,出现已下异常 1.解决:"启动Windows Process Activation Service时,出现错误13:数据无效&quo ...

  3. [转帖]为应用程序池“XXX”提供服务的进程在与 Windows Process Activation Service 通信时出现严重错误。该进程 ID 为“XXXX”。数据字段包含错误号。

    [终极解决方案]为应用程序池“XXX”提供服务的进程在与 Windows Process Activation Service 通信时出现严重错误.该进程 ID 为“XXXX”.数据字段包含错误号. ...

  4. IIS 为应用程序池提供服务的进程在与 Windows Process Activation Service 通信时出现严重错误的解决方法

    系统环境:Windows Server 2008 R2 64位, IIS 7.0 错误信息: 为应用程序池提供服务的进程在与 Windows Process Activation Service 通信 ...

  5. 在启动Windows Process Activation Service时,出现错误13:数据无效

    在启动Windows Process Activation Service时,出现错误13:数据无效 1.错误原因: 当Windows Process Activation Service从C:\Wi ...

  6. Fixed: The Windows Process Activation Service service terminated with the following error: The system cannot find the file specified

    I'm not yet clear what I did, but I'm blogging it so it can be found if someone else has this issue. ...

  7. 【必杀】为应用程序池“XXX”提供服务的进程在与 Windows Process Activation Service 通信时出现严重错误。该进程 ID 为“XXXX”。数据字段包含错误号。

    之前写过一篇文章,https://www.cnblogs.com/qidian10/p/6028784.html 解释如何解决此类问题,但现在回过头来想一下,之前的文章还是太过浅显,无法完全有效的彻底 ...

  8. 通过ctypes获得python windows process的内存使用情况

    通过ctypes 类库中的win32方法GetProcessMemoryInfo()获得当前进程的内存使用情况.该函数可以在32或者64位,python2.6+及python3.x之上都能有用. &q ...

  9. PostgreSQL在windows 10上的下载和安装

    一.下载 PostgreSQL Windows版本下载地址: https://www.postgresql.org/download/windows/ 下载地址包含2个版本,根据个人喜好下载即可: 1 ...

随机推荐

  1. centos7 安装git

    centos7下git的安装和配置   git的安装: yum 源仓库里的 Git 版本更新不及时,最新版本的 Git 是 1.8.3.1,但是官方最新版本已经到了 2.9.2.想要安装最新版本的的 ...

  2. Major Performance Impacts

    - Default opaque flags (3s) - Filter size (3s) - ??? (4s) - Image refresh performance (1s)

  3. Android源码:(一) 安卓2.1到4.4操作系统通用的Actionbar实现的tab导航例子。

    说一下我在完成这个例子之前的尝试吧 一,修改“actionbarsherlock”的导航例子.我在实现这个例子之前,尝试过“actionbarsherlock”,修改它的一个tab导航的例子,修改成功 ...

  4. Java反射机制与工厂模式

    工厂模式属于创建型模式,它提供了一种创建对象的最佳方式. 它的特点是:客户端的程序类不直接牵扯到对象的实例化管理,只与接口发生关联,通过工厂类获取指定接口的实例化对象. 简单工厂模式如下: inter ...

  5. code::blocks学习(2)

    转自: http://blog.csdn.net/sinat_27088253/article/details/52137855 http://jingyan.baidu.com/article/0b ...

  6. “全栈2019”Java第七十四章:内部类与静态内部类相互嵌套

    难度 初级 学习时间 10分钟 适合人群 零基础 开发语言 Java 开发环境 JDK v11 IntelliJ IDEA v2018.3 文章原文链接 "全栈2019"Java第 ...

  7. “全栈2019”Java第二十九章:数组详解(中篇)

    难度 初级 学习时间 10分钟 适合人群 零基础 开发语言 Java 开发环境 JDK v11 IntelliJ IDEA v2018.3 文章原文链接 "全栈2019"Java第 ...

  8. 【FAQ】maven包引入版本引发的问题

    pom.xml文件中的 dependency顺序可能会引起jar包版本不一致的问题,越上面越先引入进来

  9. ArchLinux下十八岁的感悟

    这次不写技术文章,谈谈自己.现在我们之间没有博主和来访者的关系,我们就是简单聊聊天.你若愿意,就听我说一说. 或者你可以按下crtl+w退出该页面,博主有其他的技术文章.但我希望你能看看最好可以给我留 ...

  10. redis 3.0 集群__安装

    参考文档 http://redis.io/topics/cluster-tutorial http://redis.io/topics/cluster-spec http://redis.readth ...