threads questions

hi

i am developing an application that includes reading from a large file into a buffer and processing the read data then writing it to another file and the process is repeated unil the file ends

this process takes so much time so would using several threads to work in parallel and synchronizing their operation would cause this process to speed up or the opposite?

what's ur advice to speed up this operation?

thanks in advance

[461 byte] By [el3oriana] at [2007-11-27 2:44:13]
# 1
> from a large fileWhat is the size?and,Are processes on parts of the file independent each other?
hiwaa at 2007-7-12 3:10:38 > top of Java-index,Java Essentials,Java Programming...
# 2

using multiple threads will at best not affect performance at all, and probably actually slow things down. think about a file that would take 10 seconds to read in one thread. now think of using 10 threads to do that work. they would (grossly oversimplified) take about a second each. but they couldn't be working concurrently, because they need access to the same resource anyway, so you'd have 10 threads that took a 1/10th of a second each to do their work, but they'd do it consecutively, and you'd have the overhead of thread management, too. so no gain at all

georgemca at 2007-7-12 3:10:38 > top of Java-index,Java Essentials,Java Programming...
# 3
... and what about that "Multi Core" Intel's been bragging about lately?kind regards,Jos
JosAHa at 2007-7-12 3:10:39 > top of Java-index,Java Essentials,Java Programming...
# 4
> ... and what about that "Multi Core" Intel's been> bragging about lately?> > kind regards,> > Josthey're still all accessing the same resource on disk, though, aren't they?
georgemca at 2007-7-12 3:10:39 > top of Java-index,Java Essentials,Java Programming...
# 5

> > ... and what about that "Multi Core" Intel's been bragging about lately?

> >

> > kind regards,

> >

> > Jos

>

> they're still all accessing the same resource on disk, though, aren't they?

In this case: yes, but I was just wondering whether or not different

threads got scheduled over different cores on a processor like that.

Personally I don't trust that mutliple core thingie one bit ...

kind regards,

Jos

JosAHa at 2007-7-12 3:10:39 > top of Java-index,Java Essentials,Java Programming...
# 6

> > > ... and what about that "Multi Core" Intel's been

> bragging about lately?

> > >

> > > kind regards,

> > >

> > > Jos

> >

> > they're still all accessing the same resource on

> disk, though, aren't they?

>

> In this case: yes, but I was just wondering whether

> or not different

> threads got scheduled over different cores on a

> processor like that.

> Personally I don't trust that mutliple core thingie

> one bit ...

>

> kind regards,

>

> Jos

I'm pretty sure JVMs divides threads between multiple cores and processors. AFAIK the JVM doesn't see multiple cores on one chip any diffently to multiple cores on multiple chips

why don't you trust multiple cores?

georgemca at 2007-7-12 3:10:39 > top of Java-index,Java Essentials,Java Programming...
# 7

I use channel I/O into two 512K byte buffers to verify two files, and it is fairly fast, much faster than any other method. Wrote my own compare though, Sun's is hopelessly inefficient. If I did it again, I would experiment to see if direct allocation of the byte buffer helps.

Intel's Core 2 Duo is fast. It processes Set@Home workunits 3 times faster than any other CPU I own and w/o error, and I have spent bankruptcy-scale amounts on computers.

vze29tvda at 2007-7-12 3:10:39 > top of Java-index,Java Essentials,Java Programming...
# 8

> I'm pretty sure JVMs divides threads between multiple

> cores and processors. AFAIK the JVM doesn't see

> multiple cores on one chip any diffently to multiple

> cores on multiple chips

That's interesting because that implies that the OS itself can schedule

different threads in one process over multiple cores.

> why don't you trust multiple cores?

See above: I'm a bit itchy when it comes to scheduling multiple threads

over those cores; what does the OS know about those threads and

how (in)dependent are these cores?

kind regards,

Jos

JosAHa at 2007-7-12 3:10:39 > top of Java-index,Java Essentials,Java Programming...
# 9

> > I'm pretty sure JVMs divides threads between

> multiple

> > cores and processors. AFAIK the JVM doesn't see

> > multiple cores on one chip any diffently to

> multiple

> > cores on multiple chips

>

> That's interesting because that implies that the OS

> itself can schedule

> different threads in one process over multiple

> cores.

>

that's my understanding, yes. wouldn't swear on it though, I'll have to look into it

> why don't you trust multiple cores?

>

> See above: I'm a bit itchy when it comes to

> scheduling multiple threads

> over those cores; what does the OS know about those

> threads and

> how (in)dependent are these cores?

>

> kind regards,

>

> Jos

AFAIK the OS sees cores as cores, and is largely uninterested in where they are, physically. don't honestly know much about it. you're right to have concerns, seeing how little we seem to know about this, though. nice way to spend a sunday, though, reading about this. no, wait....

edit: not so sure that the OS can split threads this way, but [url=http://developers.sun.com/sunstudio/articles/overview_concurrent.html]this article[/url] seems to suggest that certain Sun VMs do the work themselves

Message was edited by:

georgemc

georgemca at 2007-7-12 3:10:39 > top of Java-index,Java Essentials,Java Programming...