今天要做数据清洗的时候,要更新一个数据库字段,考虑到用多进程去更新数据库,也许程序会跑得快一些,结果开了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的影响的更多相关文章

  1. mysql update受影响的行数为0或查询结果为空时

    当执行update语句时,如果受影响的行数是0,返回的也是true. $conn = new mysqli(); $sql = "update ..."; $query = $co ...

  2. 记录一下MySql update会锁定哪些范围的数据

    目录 1.背景 2.前置知识 2.1 数据库的隔离级别 2.2 数据库版本 2.3 数据库的存储引擎 2.4 锁是加在记录上还是索引上 2.5 update...where加锁的基本单位是 2.6 行 ...

  3. MySQL update语句和insert插入语句写法完全不一样啊,不要搞混

    1.mysql update 语句: update user set name = 'xiaoming',age = 18 where uid = 3000; 更新记录时update操作也不需要写ta ...

  4. 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 ...

  5. MySQL UPDATE

    MySQL UPDATE 查询 如果我们需要修改或更新MySQL中的数据,我们可以使用 SQL UPDATE 命令来操作.. 语法 以下是 UPDATE 命令修改 MySQL 数据表数据的通用SQL语 ...

  6. mysql update语句

    UPDATE ClientBankInfo SET status = 3 WHERE sn IN (SELECT sn FROM zjzc.ClientBankInfo WHERE cardNo IN ...

  7. Mysql update语句赋值嵌套与在表列中数据后面增加数据

    1.Mysql update语句赋值嵌套select  点击(此处)折叠或打开 update a set col=(select col from a where id='5') where id&g ...

  8. 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 ...

  9. MySQL UPDATE 查询

    MySQL UPDATE 查询 如果我们需要修改或更新MySQL中的数据,我们可以使用 SQL UPDATE 命令来操作.. 语法 以下是 UPDATE 命令修改 MySQL 数据表数据的通用SQL语 ...

随机推荐

  1. Python基础语法学习整理

    1.基础 r’  ‘:原始字符串 pow.round是内建函数 2.序列通用操作: 索引:d[] 分片:[:] 相加:d+[] 乘法:[1,2]*3 成员判断:in 可用函数:len  max  mi ...

  2. [Algorithm] Given the root to a binary tree, return the deepest node

    By given a binary tree, and a root node, find the deepest node of this tree. We have way to create n ...

  3. Asp.net 生成静态页面

    http://www.cnblogs.com/tonycall/archive/2009/07/18/1526079.html Asp.net 生成静态页面(简单用法) 第一次发表,有什么错误,请大家 ...

  4. 【转】TCP/IP详解学习笔记(一)

      TCP/IP详解学习笔记   这位仁兄写得太好了. http://blog.csdn.net/goodboy1881/category/204448.aspx TCP/IP详解学习笔记(13)-T ...

  5. strcpy sprintf memcpy 它们之间的区别

    strcpy,sprintf,memcpy的区别 strcpy 函数操作的对象是 字符串,完成 从 源字符串 到 目的字符串 的 拷贝 功能.  snprintf 函数操作的对象 不限于字符串:虽然目 ...

  6. Java从零开始学三十(String和StringBuffer类)

    一.StringBuffer连接字符操作 当一个字符串的内容需要被经常改变时就要使用StringBuffer 在StringBuffer中使用append()方法,完成字符串的连接操作   二.Str ...

  7. 自我分析-Spring IOC

    Spring IOC容器实现原理大致是容器(Map)+反射(Java反射和cglib).Spring提供丰富的ApplicationContext.以FileSystemXmlApplicationC ...

  8. 算法笔记_173:历届试题 斐波那契(Java)

    目录 1 问题描述 2 解决方案   1 问题描述 问题描述 斐波那契数列大家都非常熟悉.它的定义是: f(x) = 1 .... (x=1,2) f(x) = f(x-1) + f(x-2) ... ...

  9. java经典小程序

    1,编写程序,判断给定的某个年份是否是闰年. 闰年的判断规则如下: (1)若某个年份能被4整除但不能被100整除,则是闰年. (2)若某个年份能被400整除,则也是闰年. import java.ut ...

  10. 〖Linux〗gvim使用alt+1,2,3..进行标签页切换

    gvim ~/.gvimrc,往里边添加: """"""""""""" ...