本文主要对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# 委托与事件的区别

    委托与事件的区别 委托和事件没有可比性,因为委托是数据类型,事件是对象(可以理解为对委托变量的封装.),下面说的是委托的对象(用委托方式实现的事件)和(标准的event方式实现)事件的区别.事件的内部 ...

  2. BZOJ1901 Dynamic Rankings|带修主席树

    题目链接:戳我 其实我并不会做,于是看了题解 我们都知道主席树是利用前缀和记录历史版本来搞区间K大的一种数据结构.不过一般的主席树只能搞定静态区间第K大.如果带修怎么办呢? 想一下...单点修改+区间 ...

  3. fatal: unable to auto-detect email address (got 'tim@newton.(none)')的解决方法

    问题描述: 使用git commit -m "wrote a readme file",就遇到了这个问题** Please tell me who you are. Run git ...

  4. 526. Beautiful Arrangement

    Suppose you have N integers from 1 to N. We define a beautiful arrangement as an array that is const ...

  5. 【转】C#具名参数和可选参数

    源地址:https://www.cnblogs.com/similar/p/5006705.html 另:可选参数的一个陷阱 参考:https://www.cnblogs.com/still-wind ...

  6. java操作AWS S3一些坑记录

    1,aws sdk jar版本不一致问题 一开始我在pom.xml中只配置了如下aws-java-sdk-s3 <!-- https://mvnrepository.com/artifact/c ...

  7. ArchLinux下Shell基础学习

    首先来认识脚本语言:通常指的是命令行界面的解析器.(来自维基的解释) 第一部分:认识Shell 大家可以看到这里使用了#!/bin/sh和!/bin/bash.可是俩者有什么区别呢?下图有解释. sh ...

  8. php-elasticsearch scroll分页详解

    背景 ps:首先我们在一个索引里面写入一万条以上的数据.作为数据源 现在我想看到第一万零一条数据,首先第一想法是,from 10000 size 1 ,这样做会包下面错误.显然是不成立的.此时便会用到 ...

  9. 使用webbench工具测试网站访问压力

    介绍 Webbench是一个在Linux下使用的网站压测工具.它使用fork()模拟多个客户端 同时访问我们设定的URL,测试网站在压力下工作的性能, 最多可以模拟3万个并发连接去测试网站的负载能力. ...

  10. axios简单介绍

    axios的配置,get,post,axiso的同步问题解决 一.缘由 vue-resoure不更新维护,vue团队建议使用axios. 二.axios安装 1.利用npm安装npm install ...