English 中文(简体)
Load aalone Greatpill Dictionary Encoded as Json Without Killing Memory Usage?
原标题:Load a Single Large Python Dictionary Encoded as Json Without Killing Memory Usage?
  • 时间:2012-05-04 21:10:28
  •  标签:
  • python
  • json

I ve seen a lot of similar questions to this, but nothing that really matched. Most other questions seemed to relate to speed. What I m experiencing is a single json dictionary that sits in a 1.1gig file on my local box taking up all of my 16 gigabytes of memory when I try to load it using anything along the lines of:

f = open(some_file, "rb")
new_dictionary = json.load(f)

不管图书馆一的使用是什么(我曾尝试过ujson、json、 yajl),不管我是否作为一流阅读东西。 这对我来说是绝对的。 cra记忆的使用是什么,我是如何接手?

In case it helps, the dictionary is just a bunch of nested dictionaries all having ints point to other ints. A sample looks like:

{"0":{"3":82,"4":503,"15":456},"956":{"56":823,"678":50673,"35":1232}...}

<><>UPDATE: 当我用简单的json来做这件事时,实际上只有8克。 没有人想到,为什么这个人比所有其他人少得多。

<><>>> 因此,我做了更多的调查。 我用简单的json装上了字典,试图把所有钥匙变成ts(根据利里的建议,扼杀可能占用更多的空间)。 空间保持在8克格。 然后,我尝试了温斯顿·埃沃特建议,即管理一组。 空间仍然保持在8克。 最后,我听到了我新的数据结构,撤出了沙里,并重新上载。 排位和持位数仍为8克。 我猜测斯·沙尔只是想说,大的2名独裁者拥有很大的空间。 我相信,如果我用简单的json装上它,那么我至少知道它不是一个“智者”问题。

最佳回答

Gabe really figured this out in a comment, but since it s been a few months and he hasn t posted it as an answer, I figured I should just answer my own question, so posterity sees that there is an answer.

不管怎么说,答案是,只有一位2名独裁者才占用了大片空间。 每一名独裁者都用一些空间管理费用开车,由于其中有许多,其气球从1.1格格格到8格格不等,除试图使用不同的数据结构或获得更多的斜线外,别无他用。

问题回答

我的一点实验表明,在json物体被 par平后,打上了<代码>gc.( ),将记忆使用降至当初设计该物体时的位置。

这里是我获得的少量记忆使用结果:

Build. No GC
762912
Build. GC
763000
Standard Json. Unicode Keys. No GC
885216
Standard Json. Unicode Keys. GC
744552
Standard Json. Int Keys. No GC
885216
Standard Json. Int Keys. GC
744724
Simple Json. Unicode Keys. No GC
894352
Simple Json. Unicode Keys. GC
745520
Simple Json. Int Keys. No GC
894352
Simple Json. Int Keys. GC
744884

Basically, running gc.collect() appears to cleanup some sort of garbage producing during the JSON parsing process.

我不相信我会说这句话,但json实际上是一种非常简单的形式,建造你自己的教区将太困难。

尽管如此,只有:

  • You don t need the full dictionary at the end (i.e., you can consume the data as you read it)
  • You have a good idea what sort of structure the data is in (an arbitrarily deep dictionary would make this much more difficult)




相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签