我有一个脚本可以读取simpledb域并将它们写入s3。这场演出充其量是平庸的。有没有办法提高阅读速度?在
import boto
import datetime
from xml.dom.minidom import Document
from boto.s3.key import Key
awsa = "myawsaccesskey"
awss = "myawssecretkey"
conn = boto.connect_sdb(awsa, awss)
domains = conn.get_all_domains()
s3conn = boto.connect_s3(awsa, awss)
archbucket = s3conn.get_bucket("simpledbbu")
for d in domains:
print d.name
doc = None
doc = Document()
root = doc.createElement("items")
doc.appendChild(root)
countermax = 0
counter = 0
for item in d:
print "loading {0} of {1}".format(counter,countermax)
counter += 1
node = doc.createElement("item")
node.setAttribute("itemName", item.name)
for k,v in item.items():
if not isinstance(v, basestring):
i = 0
for val in v:
node.setAttribute("{0}::{1}".format(k,i),val)
i += 1
else:
node.setAttribute(k,v)
root.appendChild(node)
k = Key(archbucket)
k.key = "{0}/{1}".format(datetime.date.today().strftime("%Y%m%d"),d.name)
x = doc.toprettyxml(indent=" ")
k.set_contents_from_string(x)
以下是简介:
^{pr2}$
并行运行5到10个线程,每个线程复制一个域。在
如果使用域的队列进行复制并让线程等待队列中的元素,这实际上非常简单。在
http://www.ibm.com/developerworks/aix/library/au-threadingpython/
我同意接受的答案,但是如果您只是想备份s3上的simpledb域,那么boto的to_xml()函数的性能已经相当不错了。另外,您不需要运行自己的simpledb解析器。在
相关问题 更多 >
编程相关推荐