- 浏览: 228409 次
- 性别:
- 来自: 北京
文章分类
最新评论
-
hnraysir:
必须登录评论下,谢谢。by elesos.com
分库和分表 -
化蝶自在飞:
命运使然.前生来世都注定了的.
贫穷是罪恶之源 -
Kidwind:
出现这样的错误ViewDoesNotExist at /con ...
django的jsCalendar的widget -
hanyh:
我的项目比较小,就直接写在views.py里面了。你出现的是什 ...
django的jsCalendar的widget -
Kidwind:
请问JsCalendarWidget应该放在哪个位置,我的是放 ...
django的jsCalendar的widget
共享内存计数的时候没有锁定,会造成少量的更新遗失,不过对整体来说,遗失的数据量没有大的影响。
<?php /** * * * 每个进程都单独连接数据库 * */ //configruation parameters $tbl_id = 0; $count_per_process = 10; $concurrents = 100; $logpath = "/tmp/s.log"; $host = "10.218.26.75"; $user = "user"; $pwd = "pwd"; $db = "test"; $port = 3306; $sep = 1000; $uid_count = 100000; $uid_path= 100000; if ($argc != 13) { echo "Usage:php multiprocess.php tbl_id concurrents count_per_process logpath host user pwd db port sep_counts uid_count uid_path\n"; echo "Usage:php multiprocess.php 表ID 并发数 每进程多少次 记录路径 主机 用户 密码 数据库 端口 多少条记录一次 用户数 用户UID保存路径\n"; exit(1); } else { $tbl_id= trim($argv[1]); $concurrents = (int)trim($argv[2]); $count_per_process= (int)trim($argv[3]); $logpath = trim($argv[4]); $host = trim($argv[5]); $user = trim($argv[6]); $pwd = trim($argv[7]); $db = trim($argv[8]); $port = trim($argv[9]); $sep = trim($argv[10]); $uid_count= (int)trim($argv[11]); $uid_path = trim($argv[12]); if($uid_count < $concurrents and ($uid_count % $concurrents !=0 )) { die("UID数必须多过并发进程数并曲uid数必须是进程数的整数倍\n"); } $uid_count = $uid_count / $concurrents; } $shm_key = ftok(__FILE__, 't'); $shm_id = shmop_open($shm_key, "c", 0644, 100); shmop_write($shm_id, 0, 0); $m_start= microtime(true); $conf = array( 'count' => $count_per_process, 'host' => $host, 'user' => $user, 'pwd' => $pwd, 'db' => $db, 'port' => $port, 'logpath' => $logpath, 'shm_id' => $shm_id, 'tbl_id' => $tbl_id, 'sep' => $sep, 'uid_count' => $uid_count, 'uid_path' => $uid_path, ); error_log("+++++++++++++++++++++begin++++++++++++++++\n",3,$logpath); error_log("$m_start\n",3,$logpath); for ($i = 1; $i <= $concurrents; ++$i) { $pid = pcntl_fork(); if (!$pid) { $worker = new Simulator(getmypid(),$conf); $worker->execute(); exit($i); } } //main process while (pcntl_waitpid(0, $status) != -1) { $status = pcntl_wexitstatus($status); echo "Child $status completed\n"; } $m_end = microtime(true); $m_duration = $m_end - $m_start; echo "total time consumes:".$m_duration."\n"; $shm_size = shmop_size($shm_id); $counter_str= shmop_read($shm_id, 0, $shm_size); echo "shm counter :$counter_str\n"; $e =(int)$count_per_process * (int)$concurrents; echo "theory counter :$e \n"; if (!shmop_delete($shm_id)) { echo "Couldn't mark shared memory block for deletion."; } shmop_close($shm_id); error_log("$m_end\n",3,$logpath); error_log("+++++++++++++++++++++end++++++++++++++++\n",3,$logpath); class Simulator{ private $link; private $pid; private $sep; //每隔多少条记录时间 private $tbl_id; private $uid_path; private $uid_count; private $uid_tmp_count; private $uid_is_ok; private $uid_data; private $count; private $logpath; private $error_path = "error.log"; private $counter=0; private $domains = array(".com",".cn",".info",".org",".net",".biz",".mil",".net",".jp",".tw"); private $domain_size; function __construct($pid,$conf) { $this->pid= $pid; if($conf['tbl_id'] == 0) { $this->tbl_id= ''; } else { $this->tbl_id= $conf['tbl_id']; } $this->domain_size = count($this->domains)-1; $this->count = $conf['count']; $this->sep = (int)$conf['sep']; $this->shm_id = $conf['shm_id']; $this->logpath = $conf['logpath']; $this->uid_path = $conf['uid_path']; $this->uid_count = (int)$conf['uid_count']; $this->uid_is_ok = false; //关键字 $this->uid_tmp_count = 0; // $this->link = mysql_connect($conf['host'].":".$conf['port'],$conf['user'],$conf['pwd']); if(!$this->link) { var_dump($conf); die("connected faild:".mysql_error()); } $db_selected = mysql_select_db($conf['db'],$this->link); if(!$db_selected) { die("can't use db:".mysql_error()); } } function __destruct() { if($this->link) { mysql_close($this->link); } if($this->uid_is_ok) { //echo "destory"; $path = $this->uid_path; //$path = $this->uid_path."-$this->pid"; $fp = fopen($path,"a"); if($fp) { $contents = ""; $i = 1; foreach($this->uid_data as $uid) { if($i % 2000 == 0) { $contents .= $uid."\n"; fwrite($fp,$contents); $contents = ""; } $contents .= $uid."\n"; } fwrite($fp,$contents); fclose($fp); } } } private function inc() { $counter_str= shmop_read($this->shm_id, 0, 100); $c = (int) $counter_str + 1; if($c % $this->sep == 0) { error_log(microtime(true)." $c\n",3,$this->logpath); } shmop_write($this->shm_id, $c, 0); } public function execute() { $start = microtime(true); $this->pre = microtime(true); // echo $this->count; for($i = 0;$i < $this->count;$i++) { $uid = $this->getUid(); $email = $this->getEmail(); $name = $this->getName(); $sql = "INSERT INTO contact{$this->tbl_id}(uid,name,email) VALUES ($uid,'$name','$email')"; $result = mysql_query($sql,$this->link); $this->inc(); if(!$result) { error_log(mysql_error()."\n",3,$this->error_path); } } $end = microtime(true); $duration = $end - $start; //$line = "process ".$this->pid." ".$count." ".$duration."\n"; //echo "$line"; // error_log($line,3,$this->logpath); } private function getEmail() { $email = $this->getName()."@".$this->getName().$this->domains[mt_rand(0,$this->domain_size)]; //echo $email."\n"; return $email; } private function getName() { $chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_'; $size = strlen($chars); mt_srand((double)microtime()*1000000*getmypid()); $i = mt_rand(6,18); $output = ""; while(strlen($output)<$i) $output.=substr($chars,(mt_rand() % $size),1); return $output; } private function getUid() { if($this->uid_is_ok) { return $this->uid_data[mt_rand(0,$this->uid_count-1)]; } else { mt_srand((double)microtime()*1000000*getmypid()); $uid = mt_rand(1000000000,9999999999); $this->uid_data[] = $uid; $this->uid_tmp_count += 1; if($this->uid_tmp_count == $this->uid_count) { $this->uid_is_ok = true; } return $uid; } } } ?>
发表评论
-
使用syslog-ng进行日志中心化(一)
2009-12-16 18:44 1026一个日志中心化设计收集项目,前端有230台的服务器,使用sys ... -
phpunit 实践(1)
2009-12-02 17:41 0如何测试抽象类 Phpunit作为功能测试、单元测试的一种工 ... -
异步数据处理
2009-11-24 15:19 0对量很大的操作,有时需要对数据进行异步处理,如记录论坛的点击数 ... -
改用phpt作为默认的测试框架
2009-11-20 11:36 1140以前作PHP测试的时候经常用PHPUNIT,现在个人倾向用ph ... -
yahoocn邮箱登录脚本
2009-11-12 18:15 5912最近发现线上登录Yahoo邮箱取地址薄的代码不能用了,调试发现 ... -
register_shutdown_function vs __destruct
2009-11-12 17:46 1631php中为什么有了 __destruct函数后还没有把regi ... -
如何检测效率(PHP)问题:TODO
2009-10-26 16:58 976基本上代码要关心: 时间(CPU) 空间(内存) IO(磁盘读 ... -
php框架特性
2009-10-23 11:47 0why php框架? http://www.nyphp.org ... -
phpinfo()包含足够多的配置信息
2009-10-21 16:13 821如果自己编译安装不知道啥配置在那里,在这里面找 -
PECL安装
2009-09-16 23:05 1663需要autoconf 需要header 多版本需要指定路径 / ... -
核心差异在于异常处理
2009-09-15 22:03 7951,mysql主从同步生效怎么办? 2,mc失效怎么办? 3, ... -
分库和分表
2009-07-23 10:42 94971,背景:一个地址薄的应用程序,设计的用户量为2亿,统计出每个 ... -
事务型和社区型网站语言的选择?
2009-07-21 15:28 840javaeye用ruby;facebook用php;sina用 ... -
安全意识
2009-07-14 15:30 886一,分类 Rotational(ceasar)轮转 trans ... -
分析php文件的调用关系图
2009-07-14 14:50 2229step1:下载0.3 http://t3.dotg ... -
php vld 安装使用
2009-07-14 14:31 1669cvs -d :pserver:cvsread@cvs.x ... -
DJP Hash
2009-05-26 14:52 941HASH_OU_NUMS-->函数 funct ... -
php引用
2009-05-06 10:58 876引用 <?php function foo($bar){ ... -
PHP参考手册中的openlog函数说明误导
2009-04-23 12:06 1886PHP参考手册中的openlog函数说明如下: openlo ... -
PHP同时加载zendDebugger和xdebug会冲突
2008-12-31 14:15 1390会导致php无法正常饯行,注释掉一个 [debugger] # ...
相关推荐
数据插入数据库5种方式工具源码 功能描述: 基本Insert Into 单线程Bulk Insert 多线程Bulk Insert 单线程SqlBulkCopy 多线程SqlBulkCopy 试验的5种方法,比较各种方法的导入速度 要把导入的文件放在C盘如:c:\\20...
本子系统通过BCP把所有网页批量存入数据库,根据实际测试,其执行效率是数据库插入操作的十倍,大大节省操作时间,并且大大降低数据库负荷。 • WEB搜索子系统:英文名WEB Search Engine,用于全文检索数据库中的...
MySQL是一个多线程的,结构化查询语言(SQL)数据库服务器。SQL 在世界上是最流行的数据库语言。MySQL 的执行性能非常高,运行速度非常快,并非常容易使用。是一个非常棒的数据库。新的版本可以作为复杂情况以及大负荷...
5、利用线程池进行多线程处理提高索引保存速度 6、利用 AOP 切面计算索引保存时间 7、搜索模块利用 HTML+CSS+JS 实现前端搜索功能 8、为索引构建 搜索树 操作方法:1、找到文档中db.sql运行数据库2、下载解压后在...
该系统采用C#语言,在VS2012的开发环境中,利用多线程技术将大数据量Excel表格数据导入到SQL Server中,加快了信息导入的速度。并且在临时表与目标表之间的合并过程中,摒弃了传统的游标逐条插入方式,取而代之的是...
写入向前日志模式,避免多线程访问时锁定数据库,写入时不必使用排它锁影响其它线程读取,而是把事务操作写入到WAL文件中,延迟合并 加大缓存,Cache Size=5000,提升性能。操作系统通过文件映射MapFile把整个数据库...
不要认为这是数据库基准,因为没有网络往返,并且仅使用单个客户端线程与数据库进行通信。 ###楷模 ###测试假设 装载整个骨料 简单模型是单个表的数据源 标准模型表示父/子关系。 实施可以自由选择一个表或...
11.5 多线程与数据库 335 11.6 多线程与图形处理 340 11.7 总结 343 第12章 文件处理 344 12.1 处理文件的输入/输出 344 12.1.1 文本文件的处理 344 12.1.2 类型文件的处理 348 12.1.3 无类型文件的处理 356 12.2 ...
§1.1 Oracle数据库结构 23 §1.1.1 Oracle数据字典 23 §1.1.2 表空间与数据文件 24 §1.1.3 Oracle实例(Instance) 24 §1.2 Oracle文件 26 §1.2.1 数据文件 26 §1.2.2 控制文件 26 §1.2.3 重做日志文件 26 §...
实现了自绘控件,云端控制主要在CnComm类多线程串口通讯库, camerads-DirectShow使用示例 演示了摄像头的使用 CatListBoxDemo ListBox控件与其它控件阙套使用方法 CCAMS系统是一种用于局域网下的CS模式的软件...
Java的产生与流行是当今Internet发展的客观要求,Java是一门各方面性能都很好的编程语言,它的基本特点是简单、面向对象、分布式、解释的、健壮的、安全的、结构中立的、可移植的、性能很优异的、多线程的、动态的,...
10.2.3 调节服务器参数 10.2.4 MySQL 怎样打开和关闭数据库表 10.2.5 在同一个数据库中创建大量数据库表的缺点 10.2.6 为什么有这么多打开的表? 10.2.7 MySQL 怎样使用内存 10.2.8 MySQL ...
<br>多线程采集与发布,使得采集速度更进一步,而系统占用率降低。 <br>同时兼顾全自动采集的方便快捷与手动采集的自由选择。 <br> 更新历史: <br> BFCImporter2.0 Beta 3: (文件日期:...
o 4.15 安装后期(post-installation)的设置与测试 + 4.15.1 运行mysql_install_db 的问题 + 4.15.2 启动 MySQL 服务器的问题 + 4.15.3 自动启动和停止 MySQL + 4.15.4 选项文件 o 4.16 升级和降级...
与cgi的区别在于servlet处于服务器进程中,它通过多线程方式运行其service方法,一个实例可以服务于多个请求,并且其实例一般不会销毁,而CGI对每个请求都产生新的进程,服务完成后就销毁,所以效率上低于servlet。...
修改高级表格支持库,解决插入行/插入列在未指定行号/列号的情况下插入位置不正确的BUG。 7. 修改文本语音转换支持库,增加“机读文本.重新创建并初始化()”方法。 8. 修改应用接口支持库,增强“取快捷方式目标...
在同一个数据库中创建多个表的缺陷 7.5. 优化MySQL服务器 7.5.1. 系统因素和启动参数的调节 7.5.2. 调节服务器参数 7.5.3. 控制查询优化器的性能 7.5.4. 编译和链接怎样影响MySQL的速度 7.5.5. MySQL如何使用内存 ...