多进程对 MySQL update的影响
今天要做数据清洗的时候,要更新一个数据库字段,考虑到用多进程去更新数据库,也许程序会跑得快一些,结果开了64个进程,
结果是其他程序更新的时候,速度非常慢,最后发现的原因是,数据库中有64个SQL语句执行更新,这样就导致了对数据库进行增删改查的速度很慢。
这是一个血的教训,所有以后的操作尽量少用多进程更新数据库。即使是想用多进程进行SQL update,可以少开几个进程,提升效果比较明显
粘贴查来代码,以供以后学习参考
#-*-coding:utf-8-*- from common.contest import *
import time def spider(item): print "正在清晰地url是:", item['item_url'] item_url = item['item_url']
item_lotnum1 = item['item_lotnum']
item_sold = item['item_sold']
artron_session_url = item['artron_session_url']
artfoxlive_session_url = item['artfoxlive_session_url']
print item_lotnum1
print item_sold try:
item_lotnum2 = "@@@" + item_lotnum1 + "@@@"
item_lotnum = re.findall('@@@000(.*?)@@@',item_lotnum2)[0]
except:
try:
item_lotnum2 = "@@@" + item_lotnum1 + "@@@"
item_lotnum = re.findall('@@@00(.*?)@@@', item_lotnum2)[0]
except:
try:
item_lotnum2 = "@@@" + item_lotnum1 + "@@@"
item_lotnum = re.findall('@@@0(.*?)@@@', item_lotnum2)[0]
except:
item_lotnum = item_lotnum1 item_sold_cur_spider = ""
if '流拍' in item_sold:
item_sold = -2
item_sold_cur_spider = -2
elif '撤拍' in item_sold:
item_sold = -3
item_sold_cur_spider = -3 elif '落槌价' in item_sold:
item_sold1 = str(item_sold).replace('落槌价', '').replace(':', '').replace(',', '').replace(':', '').replace(' ', '').replace(' ', '')
item_sold = re.findall('\d+', item_sold1)[0]
item_sold_cur_spider = re.findall('[^\d]+', item_sold1)[0] else:
pass print item_sold
print item_sold_cur_spider
print artron_session_url
print artfoxlive_session_url item_lotnum = item_lotnum.replace('@','')
print item_lotnum sql = 'update spider_yachang_2017_2_update_sold_price set item_sold_price_spider2 = %s, item_sold_cur_spider2 = %s
where session_url=%s and item_lotnum= %s '
data = (str(item_sold), str(item_sold_cur_spider), str(artron_session_url), str(item_lotnum))
update_data1(sql, data=data) if __name__ == "__main__":
time1 = time.time()
sql = """
SELECT
*
FROM
oversea_artfoxlive_2017_2_detail_info
""" resultList = select_data(sql)
print len(resultList)
pool = multiprocessing.Pool(64)
for item in resultList:
# print "正在爬取的位置是:",resultList.index(item)
# spider(item)
pool.apply_async(spider, (item,))
pool.close()
pool.join()
多进程对 MySQL update的影响的更多相关文章
- mysql update受影响的行数为0或查询结果为空时
当执行update语句时,如果受影响的行数是0,返回的也是true. $conn = new mysqli(); $sql = "update ..."; $query = $co ...
- 记录一下MySql update会锁定哪些范围的数据
目录 1.背景 2.前置知识 2.1 数据库的隔离级别 2.2 数据库版本 2.3 数据库的存储引擎 2.4 锁是加在记录上还是索引上 2.5 update...where加锁的基本单位是 2.6 行 ...
- MySQL update语句和insert插入语句写法完全不一样啊,不要搞混
1.mysql update 语句: update user set name = 'xiaoming',age = 18 where uid = 3000; 更新记录时update操作也不需要写ta ...
- Mysql update error: Error Code: 1175. You are using safe update mode and you tried to update a table
Mysql update error: Error Code: 1175. You are using safe update mode and you tried to update a table ...
- MySQL UPDATE
MySQL UPDATE 查询 如果我们需要修改或更新MySQL中的数据,我们可以使用 SQL UPDATE 命令来操作.. 语法 以下是 UPDATE 命令修改 MySQL 数据表数据的通用SQL语 ...
- mysql update语句
UPDATE ClientBankInfo SET status = 3 WHERE sn IN (SELECT sn FROM zjzc.ClientBankInfo WHERE cardNo IN ...
- Mysql update语句赋值嵌套与在表列中数据后面增加数据
1.Mysql update语句赋值嵌套select 点击(此处)折叠或打开 update a set col=(select col from a where id='5') where id&g ...
- Mysql update in报错 [Err] 1093 - You can't specify target table 'company_info' for update in FROM clause
Mysql update in报错 解决方案: [Err] 1093 - You can't specify target table 'company_info' for update in FRO ...
- MySQL UPDATE 查询
MySQL UPDATE 查询 如果我们需要修改或更新MySQL中的数据,我们可以使用 SQL UPDATE 命令来操作.. 语法 以下是 UPDATE 命令修改 MySQL 数据表数据的通用SQL语 ...
随机推荐
- 【架构】SpringCloud 注册中心、负载均衡、熔断器、调用监控、API网关示例
示例代码: https://github.com/junneyang/springcloud-demo 参考资料: SpringCloud系列 Eureka 一句话概括下spring框架及spring ...
- Metronic V1.5.2 Responsive Admin Dashboard Template build with Twitter Bootstrap 3.0
Template Name: Metronic - Responsive Admin Dashboard Template build with Twitter Bootstrap 3.0 Versi ...
- myeclipse创建maven android项目
一.搭建环境 1.安装android maven插件,我在网上找了半天.没有找到这个插件,于是选择了在线安装.选择myeclipse 的 [help]->[install form catalo ...
- (回溯法)和为n的所有不增正整数和式分解算法
题目: 利用递归算法输出正整数和为n的所有不增的正整数和式.例如当n=5时,不增的和式如下: 5=5 5=4+1 5=3+2 5=3+1+1 5=2+2+1 5=2+1+1+1 5=1+1+1+1+1 ...
- Python面向对象编程 - 一个记事本程序范例(一)
notebook.py import datetime last_id = 0 class Note: '''Represent a note in the notebook. Match again ...
- js-知识集锦
CreateTime--2016年9月22日14:37:51Author:Marydonjs小知识点集锦1. JSON.stringify(Obj);//将Object对象转换成json格式的st ...
- SettingsEclipse
迁移时间--2017年5月20日08:45:07 CreateTime--2016年11月15日11:07:44Author:Marydon --------------------------- ...
- 〖Linux〗Shell脚本修改输出文字颜色
Shell函数: echocolor(){ color=${} && shift case ${color} in black) echo -e "\e[0;30m${@}\ ...
- def函数之另类用法
#python 27 #xiaodeng def list_opts(): return [ ('name', 'xiaodeng'), ('age', 28), ('), ('where', 'en ...
- Python 实现的、带GUI界面的词云生成器
代码地址如下:http://www.demodashi.com/demo/14233.html 详细说明: "词云"就是数据可视化的一种形式,给出一段文本,根据文本中词语的出现频率 ...