本文主要对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. C#里面获得应用程序的当前路径

    在C#里面获得应用程序的当前路径 Environment.CurrentDirectorySystem.IO.Directory.GetCurrentDirectory() ——上面两种获得的是当前路 ...

  2. depth深度

    du.tree.find ls -li find ./ -inum 1193220 | while read a ;do rm -f $a;done find ./ -size 0b -type f ...

  3. “全栈2019”Java第六十六章:抽象类与接口详细对比

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

  4. “全栈2019”Java第五十四章:多态详解

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

  5. win10打开移动热点让手机连接上网教程

    概述: 为什么要这么做呢? 我笔记本插网线可以上网,但是没有买猫盒,所以只能pc开热点,让手机上网. 过程如下: 1开启移动热点,设置密码 1.1开启移动热点,截图如下: 1.2设置热点名称,密码 2 ...

  6. leetcode-682-Baseball Game

    题目描述: You're now a baseball game point recorder. Given a list of strings, each string can be one of ...

  7. 使用ceph-deploy进行ceph安装

    ceph安装包介绍: 1.ceph-deploy: ceph的部署软件,通过该软件可以简便部署,这个软件并非整个ceph集群系统中必须的 2.ceph: ceph整个服务集群中的每个节点必须的软件.提 ...

  8. yum安装pip命令

    pip命令是python里的命令,类似于linux系统里的yum命令 我们只需要安装python-pip这个包即可. yum -y install  python-pip 在linux下还有一个命令: ...

  9. python学习,day3:函数式编程

    调用函数来实现文件的修改(abc.txt),并增加上时间,调用的是time模块, 需要注意的是,每个函数一定要用‘’‘ ‘’’ 标注下函数说明 # coding=utf-8 # Author: RyA ...

  10. python函数超时情况应对总结

    最近处理一个线程中的函数超时问题. 函数里面有一个地方可能会卡死,我们需要去判断这个是不是卡死了,并做出相应的应对方案. 最开始想的是在函数上增加一个装饰器,使其在超时时抛出异常,然后在其他地方捕获这 ...