thezog has asked for the wisdom of the Perl Monks concerning the following question:
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Gtk2 w/ concurrent tasks
by jethro (Monsignor) on May 17, 2008 at 04:39 UTC | |
Do you only copy the files or are you processing the data? Simple copying is best delegated to 'cp', i.e. system("cp $from $to") If you still want to do it in parallel, you might just use fork(). See also http://www.perlmonks.org/?node_id=686182, a similar question just a few days ago. You might provide some more detail next time and preferably some relevant parts of your code. Otherwise the monks have to guess a lot and write answers to questions you never asked.
| [reply] [d/l] |
|
Re: Gtk2 w/ concurrent tasks
by mr_mischief (Monsignor) on May 17, 2008 at 10:37 UTC | |
You have one HD from which your copying, and you're copying to up to 49 others. The target drives are on seven seven-port USB hubs plugged into a single seven-port USB hub which is plugged into a single USB port on the PC-class machine. You're wanting to speed up the copying, but for some reason you're not going to be using IO::AIO as was suggested. You can't use dedicated drive duplication equipment because your software is supposed to be part of a package product with the machines and USB hubs. If that's about right, that background information may help the monks come up with useful suggestions sooner rather than spending a bunch of time figuring out your specific situation. It's always good to let the people helping you know if you're dealing with particular unusual circumstances and constraints so that they don't waste their time and can help you and other Seekers of Perl Wisdom better with less burnout. | [reply] |
|
Re: Gtk2 w/ concurrent tasks
by zentara (Cardinal) on May 17, 2008 at 13:32 UTC | |
If you are filling your ram after a few runs, you are not running the threads properly. Crashes shouldn't happen if joined properly, but you may need to reuse your threads. Although it is probably the same idea as IO::AIO , you could open multiple pipes for writing with opens. This is untested, but should open 7 fh's in parallel. If you can get this to work, then you can integrate it into a Gtk2 program, with a single thread. 7 fh's will probably be faster that 7 threads, because the 7-threaded process will all share the same execution pointer since they are in the same pid. If you integrate it into Gtk2, you can setup Glib::IO->add_watch (fileno $fh, qw/out/, \&watch_callback, $fh); to watch for errors and completion of the writes. But if I were you, I would get it working from the commandline first, before adding gui complexities. It may be that to improve writing speed to each filehandle, you may need to spawn a piped open to the filelocation, and "cat the_file" to each location. That would relieve your Gtk2 app from the actual copying, by handing it off to cat. So instead of writing to the filhandles, you could fork and exec 7 times and exec "cat $infile > $outfile".
I'm not really a human, but I play one on earth. Cogito ergo sum a bum | [reply] [d/l] |
|
Re: Gtk2 w/ concurrent tasks
by jethro (Monsignor) on May 17, 2008 at 13:42 UTC | |
A single usb port on the pc has a transfer rate of about 40 Mbyte/s (source wikipedia). The slowest hard drives in hard drive tests in a PC magazine I could find had minimal 29 Mbyte/s write transfer rate, including notebook drives. Only Solid State disks got lower, the slowest was down to 17 Mbyte/s. Now these were recent tests, older hard drives would be somewhat slower. But if you didn't especially look for slow drives yours probably will be faster than this minimum So without buying an internal PCI USB card with a few ports the speedup you get is minimal to non-existant.
| [reply] [d/l] |
|
Re: Gtk2 w/ concurrent tasks
by BrowserUk (Patriarch) on May 18, 2008 at 05:39 UTC | |
First, if you haven't already, please produce a simple testcase demonstrating the failure and raise a bug report against threads. If the testcase demonstrates the problem with the latest cpan version of that module in conjunction with 5.10 so much the greater chance of getting some action on it. Next a few possibilities. For more useful help than this, you would need to post some code showing what you are doing. Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
| [reply] [d/l] [select] |
by thezog (Initiate) on May 21, 2008 at 20:05 UTC | |
| [reply] |
by BrowserUk (Patriarch) on May 22, 2008 at 01:00 UTC | |
I ended up going with the separate script which handles the threads and copies. It works great! Glad to have helped. Perhaps you could return the favour. Did you produce a minimal testcase that demonstrated the problem and raise a bug report against threads? If not, could you please do so, because it won't get fixed unless they know the problem exists. Late additionI just went looking for the GTK equivalent of Tk::fileevent and noticed something that I don't recall seeing before. Maybe you missed it too? In the pod for the top-level GTK2 package which is generally just an index to the rest of the documentation, so you may well have skipped over it, there is this:
Which kinda sounds like it might be a solution to your original problem? Now you may be happy with your current route, but if you haven't already seen and tried this option, then it might be as well to, before raising the bug-report I encouraged you to do. I'd try this myself, but I remember installing GTK2 was non-trivial the last time I did it, and I then broke my Perl/GTK2 bindings by installing OCaml/GTK2 bindings. Since I don't use Perl/GTK2 for anything, I've never got around to trying fixing it, and don't really have the motivation to go through the pain again. Anyway, if you've tried it and it didn't help, please raise the bug-report. If you try it now and it fixes your problem, then a) it gives you choices; b) please report back here so that anyone coming along later can see the solution. End of late additionNow I just need to finish getting the IPC::Open2 stuff working so I can retrieve the success/failure results back from the copy processes, umount the drives, notify the user, etc. Do you need bi-directional comms after the child processes are running? Or just to pass some startup information on the spawn and retrieve status/results? If you can get away with the latter, then passing the startup info as command line arguments and retrieving ongoing status and results from stdout using a simple piped open
Might be easier than IPC::Open2 which I've had problems with in the past. Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
| [reply] [d/l] [select] |