搜索类似于生产者 - 消费者的算法(Searching an algorithm similar to producer-consumer)
我想问一下是否有人会对以下场景的最佳 (最快)算法有所了解:
- X进程生成一个非常大的文件列表。 每个进程一次生成一个文件
- 正在通知Y进程文件已准备好。 每个Y进程都有自己的队列来收集通知
- 在给定时间,1 X进程将通过具有Round Rubin算法的Load Balancer通知1 Y进程
- 每个文件都有一个大小,当然,更大的文件会使X和Y更加忙碌
限制
- 一旦文件进入Y进程,删除它并将其移动到另一个Y进程是不切实际的 。
我现在想不出其他限制。
这种方法的缺点
- 有时X落后(不再推文件)。 它并没有受到排队系统的影响,无论我是否改变它,它仍然会有慢/好的时间。
- 有时Y落后(很多文件聚集在队列中)。 再次,像以前一样。
- 1 Y进程忙于处理非常大的文件。 它的队列中还有几个小文件可供其他Y进程使用。
- 通知本身是通过HTTP,有时似乎不可靠。 通知失败,调试没有透露任何内容。
还有一些细节可以帮助更清楚地看到图片。
- Y进程是数据库线程/作业
- X进程是Web应用程序
- 一旦文件到达X进程,这些进程也会通过查询来从数据库端刻录资源。 它对生产部分有影响
现在我考虑了以下方法:
- X将生成像以前一样的文件,但不会通知Y.它将保存一个缓冲区(表)来填充文件列表
- Y将不断搜索缓冲区中的文件并自行检索它们并将它们存储在自己的队列中。
现在这种变化是否切合实际? 就像我说的,每个Y进程都有自己的队列,保持它似乎没有效率。 如果是这样,那么下一点我还是犹豫不决:
如何确定要获取的文件
我已经阅读了背包问题,我认为如果我从一开始就拥有整个文件列表,那么它就有应用程序。 实际上,我确实有每个文件的列表和大小,但我不知道何时可以准备好每个文件。
我已经解决了生产者 - 消费者问题,但是它以固定缓冲区为中心并进行了优化,但在这种情况下,缓冲区是无限的,我不关心它是大还是小。
下一个最佳选择是贪婪的方法,其中每个Y进程锁定最小的文件并接受它。 起初它似乎是最快的方法,我目前正在建立一个模拟来验证,但第二个意见将是太棒了。
更新只是为了确保每个人都能了解全局,我在这里链接一个快速完成的图表。
- 工作独立于流程。 它们将以一定的速度运行并处理可能的文件数量。
- 当作业完成文件时,它将向LB发送HTTP请求
- 每个进程对来自LB的请求(文件)进行排队
- LB适用于循环规则
I would like to ask if someone would have an idea on the best(fastest) algorithm for the following scenario:
- X processes generate a list of very large files. Each process generates one file at a time
- Y processes are being notified that a file is ready. Each Y process has its own queue to collect the notifications
- At a given time 1 X process will notify 1 Y process through a Load Balancer that has the Round Rubin algorithm
- Each file has a size and naturally, bigger files will keep both X and Y more busy
Limitations
- Once a file gets on a Y process it would be impractical to remove it and move it to another Y process.
I can't think of other limitations at the moment.
Disadvantages to this approach
- sometimes X falls behind(files are no longer pushed). It's not really impacted by the queueing system and no matter if I change it it will still have slow/good times.
- sometimes Y falls behind(a lot of files gather in the queues). Again, the same thing like before.
- 1 Y process is busy with a very large file. It also has several small files in its queue that could be taken on by other Y processes.
- The notification itself is through HTTP and seems somehow unreliable sometimes. Notifications fail and debugging has not revealed anything.
There are some more details that would help to see the picture more clearly.
- Y processes are DB threads/jobs
- X processes are web apps
- Once files reach the X processes, these would also burn resources from the DB side by querying it. It has an impact on the producing part
Now I considered the following approach:
- X will produce files like it has before but will not notify Y. It will hold a buffer (table) to populate the file list
- Y will constantly search for files in the buffer and retrieve them itself and store them in its own queue.
Now would this change be practical? Like I said, each Y process has its own queue, it doesn't seem to be efficient to keep it anymore. If so, then I'm still undecided on the next bit:
How to decide which files to fetch
I've read through the knapsack problem and I think that has application if I would have the entire list of files from the beginning which I don't. Actually, I do have the list and the size of each file but I wouldn't know when each file would be ready to be taken.
I've gone through the producer-consumer problem but that centers around a fixed buffer and optimising that but in this scenario the buffer is unlimited and I don't really care if it is large or small.
The next best option would be a greedy approach where each Y process locks on the smallest file and takes it. At first it does appear to be the fastest approach and I'm currently building a simulation to verify that but a second opinion would be fantastic.
Update Just to be sure that everyone gets the big picture, I'm linking here a fast-done diagram.
- Jobs are independent from Processes. They will run at a speed and process how many files are possible.
- When a Job finishes with a file it will send a HTTP request to the LB
- Each process queues requests (files) coming from the LB
- The LB works on a round robin rule
原文:https://stackoverflow.com/questions/15585304
最满意答案
iOS UIAutomation,apple为在目标主机上运行任务提供了api。
performTaskWithPathArgumentsTimeout
使用这个,我们可以使用bash脚本打印出我们想要在第一种情况下获取的文件的内容。
对于此要求,Bash脚本可以像这样简单。
#! /bin/bash FILE_NAME="$1" cat $FILE_NAME
将其另存为FileReader.sh文件。
在您的自动化脚本中,
var target = UIATarget.localTarget(); var host = target.host(); var result = host.performTaskWithPathArgumentsTimeout(executablePath,[filePath,fileName], 15); UIALogger.logDebug("exitCode: " + result.exitCode); UIALogger.logDebug("stdout: " + result.stdout); UIALogger.logDebug("stderr: " + result.stderr);
where in,executablePath是需要执行命令的地方。
var executablePath = "/bin/sh";
filePath是创建的FileReader.sh文件的位置。 执行时,将内容输出到标准输出(在我们的要求中)。 [给出文件的完整绝对路径]
fileName是从中获取内容的实际文件。 [给出文件的完整绝对路径]在我的情况下,我有一个Contents.csv文件,我必须阅读。
最后一个参数是以秒为单位的超时。
希望这有助于其他人,尝试获取内容(阅读文件)以执行iOS UIAutomation。
参考文献:
iOS UIAutomation, apple provides an api for running a task on the target's host.
performTaskWithPathArgumentsTimeout
Using this, we can have a bash script to printout the contents of a file that we wanted to fetch in the first case.
Bash script can be as simple as this for this requirement.
#! /bin/bash FILE_NAME="$1" cat $FILE_NAME
Save it as for example FileReader.sh file.
And in your automation script,
var target = UIATarget.localTarget(); var host = target.host(); var result = host.performTaskWithPathArgumentsTimeout(executablePath,[filePath,fileName], 15); UIALogger.logDebug("exitCode: " + result.exitCode); UIALogger.logDebug("stdout: " + result.stdout); UIALogger.logDebug("stderr: " + result.stderr);
where in, executablePath is where the command need to be executed.
var executablePath = "/bin/sh";
filePath is the location of the created FileReader.sh file. When executed, outputs the content to standard output (in our requirement). [give full absolute path of the file]
fileName is the actual file to fetch contents from. [give full absolute path of the file] In my case I had a Contents.csv file, which I had to read.
and the last parameter is the timeout in seconds.
Hope this helps others, trying to fetch contents (reading files) for performing iOS UIAutomation.
References:
相关问答
更多-
我忘了将accessibilityLabel设置为某种东西。 这是用于使其可访问的属性 I forgot to set the accessibilityLabel to something. This is the property which is used to make it accessible
-
如何在iOS UIAutomation中获得按钮突出显示状态?(How to get Button Highlighted status in iOS UIAutomation?)[2022-08-11]
UIAutomation仅公开其参考文献中描述的一组有限属性 开箱即用,您可以检查isEnabled,isVisible等内容 您可以查看此SO帖子以调整内容如何检查iOS gui自动化中的元素属性? UIAutomation exposes only a limited set of properties as described in their reference Out of the box, you can check stuff like isEnabled, isVisible, etc Yo ... -
UIAutomation iOS调试(UIAutomation iOS debugging)[2021-09-12]
首先,如果你不介意无耻的插件,你可能会发现我的UI AutoMonkey项目很有用。 它是一个随机生成具有各种可配置性的事件的工具,可以执行您所谓的“霰弹枪”测试。 因此,对于您的问题,有可能让仪器在崩溃发生时突破。 它没有使用完整的调试器,但通过使用Allocations仪器,我们可以告诉它启用NSZombie检测。 打开自动化模板后,请确保关闭应用程序并且不记录跟踪。 打开仪器库并将Allocations仪器拖到时间线中。 单击该仪器上的“i”,确保选中“启用NSZombie Detection”复选框 ... -
在Xcode Instruments中,如何导入UIAutomation脚本?(In Xcode Instruments, how to import a UIAutomation script?)[2023-03-17]
选择自动化 - >添加 - >导入并从文件系统导入脚本文件。 这样做会将Instruments文档链接到您的脚本文件,因此当您使用#import关键字时,它将查找相对于脚本文件所在位置的目录。 请注意,您必须将两个js文件导入到Instruments才能正常工作。 Choose Automation -> Add -> Import and import your script file from the file system. Doing like so will link the Instrument ... -
我找到了解决方案: 我在javascript文件中使用#import指令来导入我不断更改的文件。 我将Instruments指向这个javascript文件的shell,其唯一目的是在活动开发中导入我的实际测试文件。 然后,我在另一个编辑器中修改我正在积极开发的文件,而Instruments不会抱怨 I found a solution: I use an #import directive in a javascript file to import the file that I'm constantl ...
-
乐器+来自shell脚本的UIAutomation [复制](instruments + UIAutomation from shell script [duplicate])[2022-12-12]
听起来像我不得不很快潜入的东西。 我很好奇如果你将你的仪器命令添加到/ etc / sudoers然后尝试运行会发生什么。 可能会避免你看到的auth提示。 尝试一下: “sudo visudo”在一个终端 添加此行(将“yourargs”替换为其余的乐器命令) yourUserName ALL = NOPASSWD:/ usr / bin / instruments yourargs 然后尝试运行Jenkins代理尝试运行的命令,在其前面添加“sudo”,例如“sudo instruments ..... ... -
是否可以使用Javascript从本地文本文件中读取内容?(Is it possible to read content from a local text file using Javascript?)[2023-08-20]
不,如果没有用户交互,就无法从浏览器中读取文件。 那将是一个严重的安全问题。 想象一下,任何网站都可以在您的计算机上阅读他们想要的内容。 这为滥用打开了一扇巨大的门。 No, it is not possible to read a file from the browser without user interaction. That would be a serious security issue. Imagine that any website could read whatever they w ... -
使用Xcode 6从命令行调用UIAutomation测试(UIAutomation test invocation from the command line with Xcode 6)[2022-03-02]
我看到完全相同的问题,在明确提供-w $ DEVICE参数后,我的测试终于开始了 instruments -t /Applications/Xcode6.app/Contents/Applications/Instruments.app/Contents/PlugIns/AutomationInstrument.xrplugin/Contents/Resources/Automation.tracetemplate -w "iPhone 5s (8.0 Simulator)" /path/to/my/Te ... -
iOS8 - 代码中是否有UIAutomation框架的示例?(iOS8 - is there an example of UIAutomation framework from code?)[2023-06-28]
我相信UIAutomation仍然是一个仅限JavaScript的测试框架。 如果支持任何其他语言,我们本可以在WWDC或发行说明中听到。 然而,具体的证据是,在分析应用程序时使用的“自动化”工具没有语言下拉来指示另一种语言是可能的(比如说,你在Xcode中创建一个新类时会这样做,并且有一个Swift的下拉列表)和目标-C)。 如果您使用自动化仪器内置的自动录制功能,您看到的代码就是JavaScript。 缺乏选择另一种语言的选择。 乐器也确实通过Xcode 6获得了一个小的视觉调整,这一事实没有改变。 可 ... -
iOS UIAutomation,apple为在目标主机上运行任务提供了api。 performTaskWithPathArgumentsTimeout 使用这个,我们可以使用bash脚本打印出我们想要在第一种情况下获取的文件的内容。 对于此要求,Bash脚本可以像这样简单。 #! /bin/bash FILE_NAME="$1" cat $FILE_NAME 将其另存为FileReader.sh文件。 在您的自动化脚本中, var target = UIATarget.localTarget ...