首页 \ 问答 \ 如何解决python的out of memory问题

如何解决python的out of memory问题

我需要生成一个3000万个节点,平均度为10的规则网络 使用networkx提供的 g=nx.random_graphs.random_regular_graph(k,n) 生成网络,k=10,n=10000000 结果在网络生成过程中出现了out of memory异常 我的电脑的物理内存是肯定够的,应该是python内核不允许申请那么大的内存, 我如果减小n的大小就可以正常生成网络 各路大神有谁有办法解决这个问题呢?只要能让python使用足够多的内存就可以。 在java中我知道有办法设置增大jvm虚拟机使用内存的上限,不过python怎么设置我就不清楚了 大家有谁有办法吗 我使用的是一个pyton开发的 一个包,叫networkx 生成一个规则网络 节点数为一千万,如果把n改成一百万,都可以顺利生成网络 但是一千万就内存溢出 求解决办法
更新时间:2023-06-18 14:06

最满意答案

在各个表的id和time属性上创建索引,而且把其中除了第一次left join中的 b.time=a.time外,其余的 b.time=a.time去掉,并先对b表执行    b.time='2013-10-1'的查询。
如果各表都需要判断时间的话,那么请先在各表上执行基于时间的选择操作,在参加左外连接。因此,时间字段上的索引很重要。

其他回答

既然楼主用了left join ,相信功能上的要求是必须的。
想优化脚本的话,没有什么余地了应该。

如果想提高效率,可以在关联的字段上建索引,这样就会避免表扫描。效率会提高很多。
1、是否b、c、d、e之间有包含关系,有就改成join,如b join c join d join e right join a
2、b、c、d、e的time列不要参与连接,直接写在[表名].time='2013-10-1'
3、各表中time的选择率是否高,即满足time='2013-10-1'占表中总记录的百分比是否足够低,如果低建议在(time,id)上建索引,以避免全表扫描

相关问答

更多
  • 收藏(1) sql语句如下: SELECT udd.id,udd.doTime,udd.doType,udd.isOk,udd.resourceId, udd.userId,uu.alias userName,uu.email AS email,bd.nid AS drugId,bd.drug_name_en AS drugName FROM udl_drugs_downlaod_log udd LEFT JOIN use_user uu ON udd.userId=uu.id LEFT JOIN repo ...
  • 1、因为T1表式主表,所以 【select COUNT(DISTINCT T1.A1) from T1】和你求出的 【COUNT(DISTINCT T1.A1)】值是一样的。 2、而由于T2等是从表并且你使用了【COUNT(DISTINCT T2.B1)】因此null值会被排除掉,实际上和下面的语句求出的值是一样的 select COUNT(DISTINCT T2.B1) from T1 inner join T2 on T1.A1 = T2.A1; 3、从上面的分析可以看出你使用【left join】的目 ...
  • 在各个表的id和time属性上创建索引,而且把其中除了第一次left join中的 b.time=a.time外,其余的 b.time=a.time去掉,并先对b表执行 b.time='2013-10-1'的查询。 如果各表都需要判断时间的话,那么请先在各表上执行基于时间的选择操作,在参加左外连接。因此,时间字段上的索引很重要。
  • SELECT a.col12, b1.col8, c1.col9, d1.col10, e1.col11 FROM a INNER JOIN (SELECT b.col8, b.col2, b.col3 FROM b WHERE b.col2 = a.col2 GROUP BY b.col8) b1 ON (b1.col2 = a.col2) INNER JOIN (SELECT c.col9, c.col3, c.col4 FROM c ...
  • 假设列categoryid存在于tbl_notes表中... 尝试重写查询以使用JOIN语法,而不是使用old-school逗号作为连接运算符。 (如果问题不是一个错误的列,我怀疑问题在于混合两种类型的语法......但这只是一种怀疑,我没有理由测试将旧式逗号连接与JOIN关键字混合。) 我写这样的声明: SELECT n.*, c.clientname, nc.notecategoryname FROM tbl_notes n JOIN tbl_clients c ON n.clien ...
  • 找到了解决方案! 在一秒钟内返回,所以每个人都很开心。 SELECT 24hourTrips.id, driver_contacts.trip FROM (SELECT id,txnPNR FROM trips WHERE trips.`tripDropoff` > now() - INTERVAL 1 DAY AND TRIM(txnPNR) != '') AS 24hourTrips LEFT OUTER JOIN driver_contacts ON 24hourTrips.id = driver_c ...
  • SELECT m...., a...., r.... FROM 0_member AS m LEFT JOIN (SELECT user_id, min(sec_id) minsec FROM `0_area` GROUP BY user_id) g1 on g1.user_id=m.id LEFT JOIN 0_area AS a ON a.user_id = g1.user_id and a.sec_id=minsec ...
  • 由于这是一个左外连接,所以最好的办法是在large_table上使用索引,以尽早减少行数。 不幸的是,你的条件没有检查平等,所以组合索引是无用的。 您可以在large_table的三列上创建索引,并查看PostgreSQL是否使用它们(例如,使用位图扫描并合并结果)。 PostgreSQL选择不使用的那些索引可以被再次丢弃。 Since this is a left outer join, your best bet is to use indexes on large_table that reduces ...
  • 首先删除GROUP BY子句GROUP BY User_ID因为根本不需要它。 此外,您应该为表uniqueEntries和actualEntries一个User_ID列的索引,因为您将其用作连接列。 有了它,你的查询应该是这样的 INSERT INTO uniqueEntries SELECT actualEntries.* FROM actualEntries LEFT JOIN uniqueEntries ON uniqueEntries.User_ID = actualEnt ...
  • 似乎问题中的查询将生成半笛卡尔(半交叉)产品......将status行与status中的其他行进行匹配,从而可能使计数膨胀。 我怀疑我们只需要连接status表一次,匹配docId ,然后我们可以通过SELECT列表中表达式中的一些条件测试来运行行。 作为这种方法的一个简化例子(没有引入汇总,请考虑: SELECT i.id , i.docid , s.ingredientId , s.status , s.exemptionId , IF( s.in ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)