多进程对 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语 ...
随机推荐
- GO语言基础之struct
结构struct 1. Go 中的struct与C中的struct非常相似,并且Go没有class 2. 使用 type <Name> struct{} 定义结构,名称遵循可见性规则(即首 ...
- iOS-数据库sqlite的使用
.数据库的增删查改的方法 sqlite3_exec(db, [sql UTF8String], NULL, NULL, &erro); 数据库的使用 步骤:01.导入框架<sqlite3 ...
- spring源代码系列(一)sring源代码编译 spring源代码下载 spring源代码阅读
想对spring框架进行深入的学习一下,看看源码,提升和沉淀下自己,工欲善其事必先利其器,还是先搭建好开发环境吧. 环境搭建 sping源代码之前是svn管理,如今已经迁移到了github中了.新版本 ...
- ZH奶酪:PHP图片压缩(TinyPNG在线API)和(使用Imagick扩展)
1.调用TinyPng网站提供的API 1.1.须知 (1)tinypng的官网:https://tinypng.com/ 不知道国内访问会不会很慢,在Singapore打开这个网站很流畅: (2)A ...
- uni - 介绍
uni-app 是一个使用 Vue.js 开发跨平台应用的前端框架,开发者编写一套代码,可编译到iOS.Android.H5.小程序等多个平台 优点:基于vue.mpvue.微信小程序 微信小程序AP ...
- jquery选中以什么开头的元素
$("[id^=percent]").size() ^=:表示以什么开头 $=:表示以什么结尾 ~=:表示包含什么 id:表示按id选择
- Tomcat启动时选择加载项目
到tomcat\conf\Catalina\localhost下新建文件:myapp.xml 内容如下: <Context path="/myapp" docBase=&qu ...
- android缓存具体解释
Android缓存: 採用缓存,能够进一步大大缓解数据交互的压力.又能提供一定的离线浏览.下边我简略列举一下缓存管理的适用环境: 1. 提供网络服务的应用 2. 数据更新不须要实时更新,哪怕是3-5分 ...
- spring mysql多数据源配置
spring mysql多数据源配置 @Configuration public class QuartzConfig { @Autowired private AutowireJobFactory ...
- Eclipse 如何导入web项目
Eclipse 如何导入web项目 CreateTime--2018年3月8日09:07:16 Author:Marydon 方法一:推荐使用 1.将web项目手动拷贝到Eclipse的工作空间下 ...