C/S架构快速开发框架SQL并发测试压力测试 | www.csframework.com
C/S架构快速开发框架SQL并发测试压力测试 | www.csframework.com
文章介绍 应C/S框架旗舰版V5.0用户要求,写了个C/S架构快速开发框架SQL并发测试压力测试工具, 针对CSFramework.DB数据底层进行压力测试,模拟1000~10000个SQL连接数进行测试,成功通过。 测试工具支持: 1. 本地数据库 2. 阿里云ECS服务器的数据 3. SQL连接池Polling C# Code: /// <summary> /// C/S框架网,CSFramework.DB,C/S框架数据库并发测试 /// </summary> public partial class frmSQLConcurrentTester : Form { static object _threadCount = 0;//线程数量 static object _connCount = 0;//已建立的SQL连接数 static List<object> _threadList = new List<object>();//线程数量 static DateTime _startTime = DateTime.Now; public frmSQLConcurrentTester() { InitializeComponent(); } private void btnTest_Click(object sender, EventArgs e) { txtResult.Text = ""; OnResult("开始测试..."); btnTest.Enabled = false; _connCount = 0; _threadCount = 0; _startTime = DateTime.Now; //初始化进度条 this.DoPrepareProgress(); //启动多线程 int t = int.Parse(txtThreads.Text); int count = 1; while (count <= t) { Task.Run(() => { DoThread(); }); Application.DoEvents(); count++; } //等待全部线程完成处理 Thread.Sleep(500); WaitThreads(); OnResult("测试结束..."); TimeSpan ts = DateTime.Now - _startTime; lblTime.Text = "用时:" + ts.TotalSeconds.ToString() + "秒."; btnTest.Enabled = true; btnTest.Invalidate(); GC.Collect();//回收垃圾 } /// <summary> /// 等待线程 /// </summary> private void WaitThreads() { while (_threadList.Count > 0) { //处理线程.... Application.DoEvents(); } } /// <summary> /// 启动一个线程 /// </summary> private void DoThread() { lock (_threadCount) { _threadCount = int.Parse(_threadCount.ToString()) + 1; } int currentID = int.Parse(_threadCount.ToString()); if (currentID > int.Parse(txtThreads.Text)) return; _threadList.Add(currentID); this.Invoke(new SyncCall(this.OnResult), new object[] { "开始线程:" + currentID.ToString() }); string connStr = ""; //本地连接 if (rbConnLocal.Checked) connStr = "Server =.; Database = CSFrameworkV5_System; User ID = sa; Password = test;"; else//远程连接 connStr = "Server =120.77.22.34; Database = CSFrameworkV5_System; User ID = sa; Password = test;"; //启动线程池 if (chkPooling.Checked) connStr = connStr + "pooling = true; connection lifetime = 0; min pool size = 1; max pool size = 32767"; else connStr = connStr + "pooling = false; "; string SQL = "INSERT INTO tb_QO(QONO,DocDate,CustomerCode,RefPONO,Currency,CreationDate,CreatedBy,LastUpdateDate,LastUpdatedBy)" + "VALUES(@QONO, @DocDate, @CustomerCode, @RefPONO, @Currency, @CreationDate, @CreatedBy, @LastUpdateDate, @LastUpdatedBy)"; int threadProcess = 0; while (int.Parse(_connCount.ToString()) < int.Parse(txtConns.Text)) { IDatabase db = DatabaseFactory.CreateDatabase(DatabaseType.SqlServer, connStr); CommandHelper cmd = db.CreateCommand(SQL); cmd.AddParam("@QONO", GetDocNo()); cmd.AddParam("@DocDate", DateTime.Now); cmd.AddParam("@CustomerCode", DateTime.Now.ToString("yyyyMMddHHmmssfff")); cmd.AddParam("@RefPONO", DateTime.Now.ToString("yyyyMMddHHmmssfff")); cmd.AddParam("@Currency", "RMB"); cmd.AddParam("@CreatedBy", "admin"); cmd.AddParam("@LastUpdatedBy", "admin"); cmd.AddParam("@LastUpdateDate", DateTime.Now); cmd.AddParam("@CreationDate", DateTime.Now); threadProcess += db.ExecuteCommand(cmd.Command); db = null; this.Invoke(new SyncCall(this.OnProgress), new object[] { 1 }); //锁定连接数计时器 lock (_connCount) { _connCount = int.Parse(_connCount.ToString()) + 1; } } this.Invoke(new SyncCall(this.OnResult), new object[] { "线程<" + currentID.ToString() + ">结束,共处理:" + threadProcess.ToString() +"条记录!"}); _threadList.Remove(currentID); } /// <summary> /// 初始化进度条 /// </summary> private void DoPrepareProgress() { lblProgress.Text = "0/0"; pb.Minimum = 0; pb.Maximum = int.Parse(txtConns.Text); pb.Value = 0; } /// <summary> /// 获取单据号码 /// </summary> /// <returns></returns> private string GetDocNo() { Thread.Sleep(5); return DateTime.Now.ToString("yyyyMMddHHmmssfff") + Guid.NewGuid().ToString().ToLower().Replace("-", "").Substring(0, 10); } /// <summary> /// 显示结果信息 /// </summary> /// <param name="value"></param> private void OnResult(object value) { string text = value.ToString(); txtResult.AppendText(text + "\r\n"); txtResult.ScrollToCaret(); } /// <summary> /// 更新进度条 /// </summary> /// <param name="value"></param> private void OnProgress(object value) { if (pb.Value + 1 <= pb.Maximum) { pb.Value++; lblProgress.Text = pb.Value.ToString() + "/" + pb.Maximum.ToString(); TimeSpan ts = DateTime.Now - _startTime; lblTime.Text = "用时:" + ts.TotalSeconds.ToString() + "秒."; } else { } } } //来源:C/S框架网 | www.csframework.com | QQ:23404761 C# Code: /// <summary> /// 异步调用过程 /// </summary> /// <param name="value"></param> public delegate void SyncCall(object value); //来源:C/S框架网 | www.csframework.com | QQ:23404761 SQL Code: CREATE TABLE [dbo].[tb_QO]( [isid] [int] IDENTITY(1,1) NOT NULL, [QONO] [varchar](32) NOT NULL, [DocDate] [datetime] NULL, [CustomerCode] [varchar](20) NULL, [RefPONO] [varchar](50) NULL, [Currency] [varchar](20) NULL, [PaymentType] [varchar](20) NULL, [Sales] [varchar](20) NULL, [Client] [nvarchar](20) NULL, [Remark] [nvarchar](200) NULL, [FlagApp] [char](1) NULL, [AppDate] [datetime] NULL, [AppUser] [varchar](20) NULL, [CreationDate] [datetime] NULL, [CreatedBy] [varchar](50) NULL, [LastUpdateDate] [datetime] NULL, [LastUpdatedBy] [varchar](50) NULL, CONSTRAINT [PK_tb_QO] PRIMARY KEY CLUSTERED ( [QONO] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] //来源:C/S框架网 | www.csframework.com | QQ:23404761 扫一扫加微信
参考文档:
基于C#.NET C/S架构的生产看板管理系统软件开发框架平台 进销存快速开发框架(Winform三层架构+DevExpress+SQL2008R2) C/S架构进销存快速开发框架开发模板功能介绍 Winform C/S架构快速开发框架Oracle版本与MsSQL版本区别 原创:C/S架构快速开发框架通用可配置的数据修改日志解决方案 【原创】进销存软件开发模板基于C/S架构快速开发框架C#+Winform+DevExpress 原创C/S架构开源软件 - C#.NET+Winform+Dev+SQL快速开发框架 C/S架构多语言界面UI框架软件开发框架(C#.NET+Winform+DEV+SQL) 组织架构、组织机构、部门管理及权限分配 - C/S架构快速开发框架 Winform企业级WCF快速开发框架平台(C/S架构+WCF+DevExpress+SQL多数据库) 物流运输管理系统TMS成功案例-CSFramework快速开发框架(Winform+C/S+SQLServer) 基于C/S架构轻量级快速开发框架软件开发平台(C#+ADO.NET+EF) ERP快速开发工具软件-基于C/S架构Winform快速开发平台 MIS管理信息系统快速开发框架-C/S架构+Winform软件快速开发平台 C/S架构快速开发框架软件采购对比(采购评估文档下载)
其它资料:
什么是C/S结构? | C/S框架核心组成部分 | C/S框架-WebService部署图 | C/S框架-权限管理 | C/S结构系统框架 - 5.1旗舰版介绍 | C/S结构系统框架 - 功能介绍 | C/S结构系统框架 - 产品列表 | C/S结构系统框架 - 应用展示(图) | 三层体系架构详解 | C/S架构轻量级快速开发框架 | C/S框架网客户案例 | WebApi快速开发框架 | C/S框架代码生成器 | 用户授权注册软件系统 | 版本自动升级软件 | 数据库底层应用框架 | CSFramework.CMS内容管理系统 | |