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
最满意答案
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 ...
-
MVC进度条线程(MVC Progress Bar Threading)[2022-05-15]
不要打电话 _progressBar.setValue(_model.getStatus()); 从你的SwingWorker中,因为这是从后台线程调用Swing代码,并且是PropertyChangeListener的作用。 相反,只需设置进度属性即可。 此外,不要从doInBackground方法内调用done(),因为这需要由SwingWorker从EDT调用。 所以,当SwingWorker实际完成时调用这个方法。 此外,完成()应完成() - 第一个字母不应该大写,并且您应该在此代码中使用@Ov ... -
ASP.NET文件上传进度条(ASP.NET file upload progress bar)[2022-01-24]
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中以某种方式显示它。 无论 ...
-
asp.net网页上的进度条(Progress Bar on asp.net web page)[2022-10-06]
为了显示更新过程的进度,您需要发送部分更新,指示到目前为止已完成的总百分比。 所以更适用的解决方案是使用类似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 ...
-
在asp.net中下载Excelfile时等待进度条?(Waiting progress bar while downloading Excelfile in asp.net?)[2022-04-06]
如果它不会干扰任何现有限制,您可以在页面中使用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 ...