Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 8 of 8

Thread: Theory/Question,

  1. #1
    Member
    Join Date
    May 2010
    Posts
    39
    Thanks
    4
    Thanked 3 Times in 3 Posts

    Lightbulb Theory/Question,

    This isn't really a help topic, Im just looking for opinions

    If you needed to send 4,000,000 bytes (4 million), as quick as possible, assuming the client was not on your localhost.

    Would you use standard i/o or new i/o?, some sort of compression?

    All ideas welcomed

  2. #2
    Member
    Join Date
    May 2010
    Posts
    39
    Thanks
    4
    Thanked 3 Times in 3 Posts

    Default Re: Theory/Question,

    Well since no one is posting my idea is hosting multiple sockets on different ports similar to a torrent client, sending the blocks then mashing them together.

    Any other ideas?

  3. #3
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,327
    Thanks
    181
    Thanked 828 Times in 771 Posts
    Blog Entries
    5

    Default Re: Theory/Question,

    Interesting question. Compression may shave some off the top (depending upon the data format and how frequently it will change it could shave quite a bit off). Not sure how much the multiple ports option will speed things up, but you could try and benchmark it if you have the capability.

  4. #4
    Member
    Join Date
    May 2010
    Posts
    39
    Thanks
    4
    Thanked 3 Times in 3 Posts

    Default Re: Theory/Question,

    Ill have the port method benched soon, (Wrapping up some loose ends).

    As for compression, I've attempted various methods including that of the Deflater, and Inflater class but the time the compression took, and the inflation it was nearly if not worse. I've been looking into LZMA SDK, and that family of compression utils but haven't actually made a sample program with it (I plan to soon).

  5. #5
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: Theory/Question,

    If you're only sending it between 2 locations, I believe you'll only benefit from having 1 socket open (well, two, one for sending data and the other for receiving it).

    If you have multiple locations/multiple sources, then you could potentially benefit from having multiple sockets open (again, limited to 1 socket pair per unique location).

    An analogy of this would be multi-threading. While many operating systems operate using multi-threading, you don't actually get any performance benefits unless you have a multi-core CPU (granted, there are other benefits to using multi-threading other than pure performance). The same would probably apply to sockets. Unless you're talking to multiple destinations, it makes no sense to open up multiple sockets if the only thing you're looking for is performance. The exception would be if you literally had multiple connections between two locations. In this case, I'm not sure if opening multiple sockets would help still, it'd be something you'd have to experiment with.

    Compression will help reduce the amount of data you have to send, but won't speed up how quickly the data is sent. Almost always the network connection speed is considerable slower than a computer's ability to compress/decompress data, making data compression generally a good idea if you're sending a lot of data. That being said, some data doesn't compress well while others compress extremely well, so the benefits of compression is dependent on what data you're actually sending rather than just the amount.

    Also, 4 million bytes isn't really that big That's roughly 4 Mb, which with a decent internet connection can be downloaded within a minute or less.

  6. #6
    Member
    Join Date
    May 2010
    Posts
    39
    Thanks
    4
    Thanked 3 Times in 3 Posts

    Default Re: Theory/Question,

    Quote Originally Posted by helloworld922 View Post
    Also, 4 million bytes isn't really that big That's roughly 4 Mb, which with a decent internet connection can be downloaded within a minute or less.
    I know it's 4mb, I can send it within a minute or less, Im trying to get it sent within a fraction of a second

    Quote Originally Posted by helloworld922 View Post
    Unless you're talking to multiple destinations, it makes no sense to open up multiple sockets if the only thing you're looking for is performance.
    Aren't 2+ socket's on different ports possessive of their own input-stream?,
    ^So in theory wouldn't multiple threads processing different sockets, and packing chunks together improve performance? (* Presuming a equivalent client is sending in sync*)

    With that said I'm still not seeing why the multiple port theory would not improve overall speed of sending

  7. #7
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: Theory/Question,

    Yes and no. Deep down, your computer probably only has 1 connection to the internet via your ISP. They'll probably have some local router which will limit the speed you can upload/download data from the internet. This is almost always the bottleneck in uploading/downloading from the internet, regardless of how many sockets you try to open (usually it's the upload limit which gets reached first).

    Opening multiple sockets essentially has the same effect as running multiple threads/processes on a single core CPU: Each thread/process must share the CPU time, and the more threads/processes you run, the less time each thread/processes gets.

    You may be able to squeeze out a little performance boost depending on how you're sending information, but more likely you're network performance will decrease as the overhead for sending data via multiple sockets becomes more and more significant with more sockets.

    The one case I can think of where you may get significant speed bonuses is if your server has a software limit on how much network resources to commit to each connection. Opening up multiple sockets with that server may allow you to stream data faster than the software limit, thus giving the appearance that you've "sped up" the network speed. This is analogous to increasing the priority of a certain process. That process will receive a speed bonus, but this is at the expense of other processes receiving a speed drop. Be aware that there is some server software which is written to prevent this effect from happening (particularly on file hosting sites).
    Last edited by helloworld922; November 8th, 2010 at 11:23 PM.

  8. The Following User Says Thank You to helloworld922 For This Useful Post:

    Time (November 9th, 2010)

  9. #8
    Member
    Join Date
    May 2010
    Posts
    39
    Thanks
    4
    Thanked 3 Times in 3 Posts

    Lightbulb Re: Theory/Question,

    Oh wow, now I understand what you mean. Thanks for clearing that up

Similar Threads

  1. Some Theory based questions
    By Bacon n' Logic in forum File I/O & Other I/O Streams
    Replies: 6
    Last Post: October 1st, 2010, 06:23 PM
  2. Theory Inquiry
    By b_jones10634 in forum JavaServer Pages: JSP & JSTL
    Replies: 2
    Last Post: August 19th, 2010, 08:21 AM
  3. Problem with loop theory
    By Lord eMO in forum Loops & Control Statements
    Replies: 0
    Last Post: February 11th, 2010, 01:34 PM
  4. Theory behind 2d Game making?
    By DarrenReeder in forum Java Theory & Questions
    Replies: 3
    Last Post: January 28th, 2010, 01:54 AM
  5. type substitution - whats the theory behind it
    By mds1256 in forum Java Theory & Questions
    Replies: 0
    Last Post: January 20th, 2010, 06:40 PM