Results 1 to 6 of 6

Thread: fastest way to load multi sockets and threads?

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2010
    Posts
    12

    fastest way to load multi sockets and threads?

    I'm trying to figure out the best way to go about loading and using thousands of sockets at the same time.

    Loading a new class for each instance would just destroy memory.
    I'm assuming aysnc the sockets, my heads not straight at the moment.
    plus it'd have to be on a seperate thread from freezing up the UI thread.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: fastest way to load multi sockets and threads?

    Quote Originally Posted by mystical.net View Post
    I'm assuming aysnc the sockets, my heads not straight at the moment.
    plus it'd have to be on a seperate thread from freezing up the UI thread.
    That's exactly what "async" means. You create as many objects as your app requires. You call the appropriate asynchronous method of your Socket or whatever and then you get notified when data is received. It uses the TcpClient class rather than the Socket class but you might like to follow the CodeBank link in my signature and check out my Asynchronous thread. It should give you some ideas.

    Any app that needs to open thousands of sockets is going to be resource intensive whether you like it or not. I hope you don't plan on running much else on the system at the same time.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    Re: fastest way to load multi sockets and threads?

    You're going to destroy more than memory, but memory is cheap, so don't worry about that aspect. I would be much more concerned about dealing with thousands of sockets. Do they HAVE to be opened at the same time? If you get reads on all of them at the same time, performance will be approaching zero. You may, effectively, DOS yourself. How about having a pool of active sockets with a maximum size, and only open more as active sockets close.
    My usual boring signature: Nothing

  4. #4

    Thread Starter
    New Member
    Join Date
    Jan 2010
    Posts
    12

    Re: fastest way to load multi sockets and threads?

    Yeah, I'm not quite sure how i want to go about it, I'll give the general concept key word of it'd be doing which would be "Scanning", Last night i tried using a small class for each "Scan socket" worked out well, except loading a new instance of a class was just huge memory fail + slow loading of each class @ 2000 sockets, which is what i have the programmed set for max. as for when they started to scan they scanned real fast and well, about 700 address per second.

    I use a track bar to determine how many you'd want loaded from 1-2000.

    Now if i want to load as a socket array, that takes no more then 1 second to load 2000, but if they are all on the UI thread freezing may occur or they'll slowly go in order 1 by 1 to connect. Best i can assume is they almost all need there own thread to start connecting right away.

    The sources in the code bank that I've looked at can't quite handle this case.
    If it was a few sockets like 20, I'd have no problems, I'd prefer not to use TCPClient if i don't have to.

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: fastest way to load multi sockets and threads?

    The description of your app is still a bit vague but it might be that your best bet is to use the ThreadPool directly. Just queue up all your operations and let the system optimise it.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6

    Thread Starter
    New Member
    Join Date
    Jan 2010
    Posts
    12

    Re: fastest way to load multi sockets and threads?

    okay actual definition would be proxy scanner

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width