首页 \ 问答 \ Python多处理:为什么较大的chunksize较慢?(Python multiprocessing: why are large chunksizes slower?)

Python多处理:为什么较大的chunksize较慢?(Python multiprocessing: why are large chunksizes slower?)

我一直在使用Python的多处理模块分析一些代码('job'函数只是对数字进行平方)。

data = range(100000000)
n=4
time1 = time.time()
processes = multiprocessing.Pool(processes=n)
results_list = processes.map(func=job, iterable=data, chunksize=10000)
processes.close()
time2 = time.time()
print(time2-time1)
print(results_list[0:10])

我发现奇怪的一件事是最佳的chunksize似乎是大约10k元素 - 这在我的计算机上花了16秒。 如果我将chunksize增加到100k或200k,那么它会减慢到20秒。

这种差异可能是由于长时间列表中酸洗所需的时间更长吗? 100个元素的块大小需要62秒,我假设是由于在不同进程之间来回传递块所需的额外时间。


I've been profiling some code using Python's multiprocessing module (the 'job' function just squares the number).

data = range(100000000)
n=4
time1 = time.time()
processes = multiprocessing.Pool(processes=n)
results_list = processes.map(func=job, iterable=data, chunksize=10000)
processes.close()
time2 = time.time()
print(time2-time1)
print(results_list[0:10])

One thing I found odd is that the optimal chunksize appears to be around 10k elements - this took 16 seconds on my computer. If I increase the chunksize to 100k or 200k, then it slows to 20 seconds.

Could this difference be due to the amount of time required for pickling being longer for longer lists? A chunksize of 100 elements takes 62 seconds which I'm assuming is due to the extra time required to pass the chunks back and forth between different processes.


原文:https://stackoverflow.com/questions/40799172
更新时间:2022-05-13 08:05

最满意答案

您可以为此目的使用jquery,但不应对整个页面使用进度条。它应该与ASP.NET MVC视图一起使用,尤其是部分视图。 以下有用的文章可以提供帮助

如何显示进度条?

问候。


You can use jquery for that purpose but you should not use progress bar for whole page.It should be used with ASP.NET MVC views especially the partial views. The following useful article can help

How Do I Display a Progress Bar?

Regards.

相关问答

更多
  • 要回答您的问题,根据您当前的设置,这是不可能的。 使用ViewBag的尝试很好,但在Action完成并返回View之前,ViewBag实际上并未在Controller和View之间传递。 正如我所提到的,SignalR将是解决这个问题的一种方法,但对于你的用例来说却是过度的。 To answer your question, this isn't possible given your current setup. Nice attempt with using the ViewBag, but the V ...
  • 不要打电话 _progressBar.setValue(_model.getStatus()); 从你的SwingWorker中,因为这是从后台线程调用Swing代码,并且是PropertyChangeListener的作用。 相反,只需设置进度属性即可。 此外,不要从doInBackground方法内调用done(),因为这需要由SwingWorker从EDT调用。 所以,当SwingWorker实际完成时调用这个方法。 此外,完成()应完成() - 第一个字母不应该大写,并且您应该在此代码中使用@Ov ...
  • NeatUpload是一个非常好的解决方案。 取决于您对Ajax的定义,但它使用iframe进行整页重新加载并在其间进行插值。 NeatUpload is a pretty good solution. Depends on your definition of Ajax, but it does full page reloads with iframes and interpolates inbetween.
  • 我的想法: 创建控制器方法,返回JSON: { "Message" : "Processing something serious", "Percentage" : "43" } 通过JS处理它 - 将消息跨度和条形指示器放在单独的div中,更改它的内容。 对于进度条,我会使用这个 。 I'm doing some playing around, and currently I've got the following in mind: In the initial controller ...
  • Web进度条可能有点棘手,无法正常工作。 我看到你可以做两个选项: 最简单的方法是让一个进度条只显示一个动画,向用户表明某些东西仍在工作,但实际上它并没有显示你长时间运行的任务的进度,它只是动画。 当然,更难的方法是显示进度已经达到多远的实时报告。 在这种情况下,您将必须使用javascript中的setTimeout()方法每2或3秒钟左右调用一个函数,并在该函数中执行ajax调用MVC Controller方法,该方法可以从您的long中检索当前报告的进度运行任务,然后在GUI中以某种方式显示它。 无论 ...
  • 为了显示更新过程的进度,您需要发送部分更新,指示到目前为止已完成的总百分比。 所以更适用的解决方案是使用类似jQuery UI ProgressBar的东西,并有一个机制将上述百分比发送给用户,然后用最后发送的值更新进度条。 您可以查看以下文章了解更多详情: 在ASP.NET应用程序中使用jQuery ProgressBar小部件 使用jQuery UI Progressbar报告服务器端操作进度 in order to show a progress for the update process, you ...
  • 您可以为此目的使用jquery,但不应对整个页面使用进度条。它应该与ASP.NET MVC视图一起使用,尤其是部分视图。 以下有用的文章可以提供帮助 如何显示进度条? 问候。 You can use jquery for that purpose but you should not use progress bar for whole page.It should be used with ASP.NET MVC views especially the partial views. The follow ...
  • 如果它不会干扰任何现有限制,您可以在页面中使用jQuery的.ajax()函数来进行ajax调用并在该调用中处理客户端通知( 粗略示例 ): // Notify the user about downloading. // Perform the download $.ajax({ type: "POST", url: '/Users/Download.ashx', success: function(data) { // Notify the user it's ...
  • 以下是一些基于ASP .NET的进度条控件: ASP.NET AJAX进度条控件 ASP .NET进度条 (ASP .NET控件库) ASP .NET静态进度条控件 JavaScript替代方案: jQuery ProgressBar jQuery.UI ProgressBar小部件 Here are some ASP .NET based Progress Bar controls: ASP.NET AJAX Progress Bar Control ASP .NET Progress Bar (ASP ...
  • 据我所知,当前线程被阻止,直到客户端浏览器收到服务器响应为止,显示默认加载面板。 所以用默认的方法实现你想要的东西是不可能的。 但我认为你应该能够进行自定义实现。 如果我是你,我会开始有一个计时器并定期轮询到服务器以获取当前任务。 而不是显示默认加载面板,您可以显示timer-poll的结果,并在弹出div中显示结果。 As far as I know, the default loading panel is shown while the current thread is blocked until ...

相关文章

更多

最新问答

更多
  • 您如何使用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)