首页 > 学院 > 开发设计 > 正文

.NET下的并行开发

2019-11-17 01:46:43
字体:
来源:转载
供稿:网友

.NET下的并行开发

并行开发一直是程序员在开发项目中遇到的一道坎,但为了迎合硬件的升级,面对高端多核的处理器,并行编程势在必行。在.NET平台下的开发支持并行模式,下面用一个实际项目说明并行的高效率和神奇之处。

在优化中国铁建企业经营管理系统时,遇到一个迫切需要解决的问题.就是报表处理响应时间的问题,在系统最初数据较少,导出报表响应时间较快。但是随着数据的不断扩充,就一个分局的数据导出(大概600条)也需要5分钟左右,当然这个和电脑的配置相关。若是总股份公司的项目报表导出(6000条左右),那个时间在普通的电脑上根本就是漫长的等待。于此,在中国铁建股份公司的高端配置服务器上导出的时间也需要很久。系统在报表处理这块就需要优化,我的解决方案就是并行。

由于总公司的报表是由一个个分局(子公司)的报表合成的,原来的编程是根据程序的串行原则运行,就是完成一个子公司的报表后,才能继续进行下一个子公司的报表操作。总公司一共有大概50个左右的分局和项目指挥部,这样就严重的增长了报表生产导出的时间。利用并行,就是把原来的子公司让他们在几乎(这个需要看看.NET并行的运行原则,他们在并行时还是有很小的时间间隔)同一时间处理报表,开始运行。把原来需要50次左右的时间段变为一次(所需时间最慢开始,最后结束的那次)。这样就大大的加快了报表的处理速度。但是并行并不是很好控制,我测试,探索了很久才解决数据共享,数据冲突的问题。

当然,并行开发需要利用程序调用系统的多核处理器,这样在cpu的资源占用上特别的高,我的项目在报表导出时基本是cpu占用是100%。以空间换取时间这是必须要接受的。不过,在真正的多核高端服务器的硬件上,结合并行程序的改良,总公司的报表导出时间问题终于得到解决了。

以下有一些过程截图,值得一说的是报表生成时间的过程跟踪截图,它基本反映了并行程序在运行过程中的记录。

图1 总股份公司的报表导出时间跟踪

PRPAAAnd1JREFUeF7tvTGuJE2TJPZ4JKq8BgXegALvQ2F4giEwVFoaeYBGC4ulsMJigQVWGI0ze4dm19eb34sX7e5mHhGZ6VFpP1D4v66M8PAwN3e3yKpX+T99fHz8/PVa+r+fP+dN/j//9//18b/+b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