PostgreSQL On Windows Process Connection Performance
本文主要对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的更多相关文章
- 为应用程序池“XX”提供服务的进程在与 Windows Process Activation Service 通信时出现严重错误
场景 WCF应用程序部署在IIS7中,使用net.tcp协议对外给几百台客户端提供服务,应用程序池不断崩溃重启. 分析过程 在事件查看器中看到的错误信息类似于 为应用程序池“XX”提供服务的进程在与 ...
- IIS启动失败,启动Windows Process Activation Service时,出现错误13:数据无效 ;HTTP 错误 401.2 - Unauthorized 由于身份验证头无效,您无权查看此页
因为修改过管理员账号的密码后重启服务器导致IIS无法启动,出现已下异常 1.解决:"启动Windows Process Activation Service时,出现错误13:数据无效&quo ...
- [转帖]为应用程序池“XXX”提供服务的进程在与 Windows Process Activation Service 通信时出现严重错误。该进程 ID 为“XXXX”。数据字段包含错误号。
[终极解决方案]为应用程序池“XXX”提供服务的进程在与 Windows Process Activation Service 通信时出现严重错误.该进程 ID 为“XXXX”.数据字段包含错误号. ...
- IIS 为应用程序池提供服务的进程在与 Windows Process Activation Service 通信时出现严重错误的解决方法
系统环境:Windows Server 2008 R2 64位, IIS 7.0 错误信息: 为应用程序池提供服务的进程在与 Windows Process Activation Service 通信 ...
- 在启动Windows Process Activation Service时,出现错误13:数据无效
在启动Windows Process Activation Service时,出现错误13:数据无效 1.错误原因: 当Windows Process Activation Service从C:\Wi ...
- 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. ...
- 【必杀】为应用程序池“XXX”提供服务的进程在与 Windows Process Activation Service 通信时出现严重错误。该进程 ID 为“XXXX”。数据字段包含错误号。
之前写过一篇文章,https://www.cnblogs.com/qidian10/p/6028784.html 解释如何解决此类问题,但现在回过头来想一下,之前的文章还是太过浅显,无法完全有效的彻底 ...
- 通过ctypes获得python windows process的内存使用情况
通过ctypes 类库中的win32方法GetProcessMemoryInfo()获得当前进程的内存使用情况.该函数可以在32或者64位,python2.6+及python3.x之上都能有用. &q ...
- PostgreSQL在windows 10上的下载和安装
一.下载 PostgreSQL Windows版本下载地址: https://www.postgresql.org/download/windows/ 下载地址包含2个版本,根据个人喜好下载即可: 1 ...
随机推荐
- WPF Viewport3D 解决透视模式时窗体模糊
最近折腾Viewport3D玩,遇到了一些诡异的问题,研究一下略有心得,特此和大家分享~ 三维图形概述: https://msdn.microsoft.com/zh-cn/library/ms7474 ...
- System.Data.OracleClient.dll方式操作oracle数据库
System.Data.OracleClient.dll方式操作oracle数据库 一.查询语句: using (OracleConnection conn = new OracleConnectio ...
- 【Selenium专题】WebDriver启动Chrome浏览器(二)
官方API Constructor Summary ChromeDriver() Creates a new ChromeDriver using the default server configu ...
- java远程开关机
最近,很多客户向我们反馈终端启动后异常的问题,因此,我自己做了一个远程开关的小工具,该工具的目的在于通过批量的方式来控制终端启动.其设计逻辑是通过服务端发送cmd指令 ,客户端接受并执行指令,把结果返 ...
- 【《Effective C#》提炼总结】提高Unity中C#代码质量的22条准则
引言 原则1尽可能地使用属性而不是可直接访问的数据成员 原则2偏向于使用运行时常量而不是编译时常量 原则3 推荐使用is 或as操作符而不是强制类型转换 原则4 推荐使用条件属性而不是if条件编译 原 ...
- 五、Centos linux系统优化-实战
一.linux用户名和密码远程登陆的修改: windows默认的远程端口和管理员:user:administrator prot:3389在管理--->本地用户和组 进行权限设置或者修 ...
- OCP题库变了,2018年052新题库-29题
29.In one of your databases: * The database default tablespace is EXAMPLE. * Deferred_segment_creati ...
- 百度联盟广告 http://cpro.baidustatic.com/cpro/ui/c.js
<script src="http://cpro.baidustatic.com/cpro/ui/c.js" type="text/javascript" ...
- protobuf高效传输对比json gizp等等
https://blog.csdn.net/u013929284/article/details/72582215 利用Protocol Buffers可以很好的解决JSON数据在传输方面的不足,它是 ...
- suid, sgid,粘滞位,chattr
一. 基本含义和作用 1. SUID:当设置了SUID 位的文件被执行时,该文件将以所有者的身份运行,也就是说无论谁来执行这个文件,他都有文件所有者的特权. 2. SGID:与上面的内容类似.用于设置 ...