Python只使用mem-cached内存进行处理?

时间:2015-11-05 22:58:52

标签: python numpy memory parallel-processing memcached

是否有一些我可以导入的库使所有我的本机python执行读取和写入本地变量到memcached instean?因此使用NO本地内存(没有RAM)?

假装我有以下机器:

Machine0a有100GB内存专用于托管我的memcached
Machine0b有100GB内存专用于托管我的memcached
Machine0c有100GB内存专用于托管我的memcached
Machine1具有.01GM内存和一堆核心。
Machine2具有.01GM内存和一堆核心。

我基本上希望能够编写以下脚本:

Machine1上,我每小时运行以下cron作业:

import pylibmc
import onlyusememcached

#Have python make ALL process VARIABLES in memcached
#   with some unique name that only this program recognizes
really_big_number = 100000000 #-> THIS IS IN THE MEMCACHED 
#   Under the hood this is stored in memcached as    `Machine1ID.ProcessID.GlobalScopeID.really_big_number`

a = []
#   Under the hood `a` is stored in memcached as    `Machine1ID.ProcessID.GlobalScopeID.a`
for x in range(really_big_number):
    #   Under the hood `x` is stored in the memcached as `Machine1ID.ProcessID.GlobalScopeID.forloopScopeID.x``
    a.append([0,1,2,3,4,5,6,7,8,9])

#Save `a` as a shared variable with a normal memcached call:
mc = pylibmc.Client(["127.0.0.1:11211"], binary=True)
mc['SharedA'] = a 

Machine2上,我每小时运行以下cron作业+ 5分钟:

import pylibmc
import onlyusememcached
import numpy

#Go get my shared `a` from the memcached
mc = pylibmc.Client(["127.0.0.1:11211"], binary=True)
a =  mc['SharedA']
#   `a` is now copied into memcached as `Machine2ID.ProcessID.GlobalScopeID.a`

b = numpy.cov(a) 
#   `b` is now stored into memcached as `Machine2ID.ProcessID.GlobalScopeID.b`
#   numpy operations ALL happen with ONLY memcached memory 
#   so Machine 2 doesn't need any memory of its own to perform the cov calculations
#   Machine 2 ONLY needs the processor

我想要懒惰并重新使用常规python脚本,这些脚本执行所有自己的存储并转发到memcached而不是本地计算机。
我希望onlyusememcached模块对我来说很聪明,这样就可以保持范围而不会导致导入模块的所有机器和进程发生冲突。
我想买一堆专用于大量内存的机器。
我想买一堆专门用于加工的机器。

这个模块是否存在?

1 个答案:

答案 0 :(得分:0)

我认为构建它的方法实际上并不困难。 我所要做的就是编写一个覆盖c内存分配函数的c库。

python默认内存分配函数在这里,它们都只使用本机C内存分配函数。

https://docs.python.org/2/c-api/memory.html

c默认内存分配函数为mallocfree

当然存在实现memcached

的c库

http://docs.libmemcached.org/libmemcached.html

所以我要做的就是制作我自己的新mallocfree函数并正确导入它们。

#define malloc(x) ....
#define free(x) ....

使用libmemcached而不是访问RAM