PyTables写得不够快

2024-09-29 23:30:01 发布

您现在位置:Python中文网/ 问答频道 /正文

我目前在尝试让PyTables更快地向自身写入数据时遇到了困难。让我解释一下我目前的情况。在

现在我有数据是通过多播来的,这是一种高速率的数据。我有一个解析器和一个数据结构,它将数据散列到字典中,这些字典被发送到PyTables中存储。在

我有一个线程接受这个字典,它的键是和id,它的值是应用于id的数据实例的数组。线程迭代键值对,并将数据添加到与id对应的表中

这是我当前的实现,到目前为止,字典数组充当缓冲区,它随时间线性增加。这是我明显的问题。代码显示了写入线程为写入数据而进行的常量循环。在

def acceptDict():
    while True:
        while not dicts.empty():
            lock.acquire()
            dictInst = dicts.get()
            print dicts.qsize()
            for instrument, dataArray in dictInst.iteritems():
                if instrument in tableExists:
                    tableD = openFi.getNode("/t" + str(instrument), "direct")
                else:
                    tableExists[instrument] = 1
                    group = openFi.createGroup("/", "t" + str(instrument), str(instrument))
                    tableD = openFi.createTable(group, "direct", Tick, "direct")
                for i in dataArray:
                    tableD.row['timestamp'] = i[0]
                    tableD.row['side'] = i[1]
                    tableD.row['level'] = i[2]
                    tableD.row['price'] = i[3]
                    tableD.row['quant'] = i[4]
                    tableD.row['orders'] = i[5]
                    tableD.row.append()
                tableD.flush()
            lock.release() 

Tags: 数据inid字典数组pytables线程row

热门问题