Optimize server

This is a discussion on Optimize server within the C++ Programming forums, part of the General Programming Boards category; Hi there again Well i have written some code already for my own server, but I want to get it ...

  1. #1
    Registered User
    Join Date
    Mar 2011
    Posts
    69

    Optimize server

    Hi there again

    Well i have written some code already for my own server, but I want to get it working all as it should work from beginning. So I have couple questions

    Is that good idea to make dll's for most parts of code?
    Is that good idea to make dll for functions which would be used in many of threads?
    Is that good idea to make an interpretor for incoming data?
    - How should it be done to work fastest and be reliable all time?
    - I've made it as class and create own class for each thread, isn't that waste of RAM?
    - Should I move it to dll as well?
    Actually I'm creating new threads for every one new clients.
    Is that good idea to create threads from thread level? Like I need to server data, but not to block incoming new when I'm serving last one.
    Is that good idea to make classes for most important groups of functions and for each thread create their own class at beginning?

    Uff, If I had some more questions or I forgot about something I post it later

  2. #2
    Registered User C_ntua's Avatar
    Join Date
    Jun 2008
    Posts
    1,853
    Eh, you probably are better posting the code. Or at least the structure, meaning classes without implementation. Or simply an explanation of the overview

  3. #3
    Registered User
    Join Date
    Mar 2011
    Posts
    69
    Hehe, I'm not talented graphic

    http://img844.imageshack.us/img844/3894/workc.png

    So the first class which is created is NetworkHandler. It starts sockets, listening etc.
    Whenever new connection coming, it is served by thread which is listening for it and creating new own thread for connected client (let's call it 'clienthandler' or just 'CH'). So when CH thread is starting it creates some classes which will be used later for incoming data. One of those classes is PacketProcessor which is creating new thread for each packet. Every packet has their ID so PP is just running those functions as threads. Whenever there is needed to answer client it would insert new data for client structures and send one, after that thread exit. And round and round.

    My anxiety is that there will be many many threads at once and I don't know if its good idea, but other hand if I serve it in clienthandler it would block new incoming data till its done with last one.

    Server have to be fast and capability, 5-10k connections at time and even 10-20 packets per second in critical moments.

  4. #4
    Registered User
    Join Date
    Aug 2010
    Location
    Poland
    Posts
    682
    How can we answer these questions without any knowledge about your software. It's you, the programmer, who shall know what is the best solution.

    It's like asking "should I use blocking or non-blocking socket?". How can we know it?

    And this is not related to C++.
    I never put signature, but I decided to make an exception.

  5. #5
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,308
    Yeah I think there's very little at all we can do for you with this.

    One thing you said though was that you were "creating new threads for every one new clients". And you also said "5-10k connections at time".
    If that means that you have 5000 or more threads at once then you're design is bad. Thread pools FTW!
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  6. #6
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,823
    Also means you have to be careful with memory usage. 5000 threads at once means a lot of stack space, so you have to restrictive.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  7. #7
    Registered User
    Join Date
    Sep 2010
    Posts
    90
    Nice diagram. The idea deserve some serious thought. I hope you are not in a rush, but I do have one question. You said dll, so which windows server are you using or have you force XP to do the job? It's all about freeBSD for me when it comes to servers. I will be doing some research, using your graphics. WoW!

    For now I think it's windows server:

    Is that good idea to make dll's for most parts of code?
    COM vs. DLL/C++ wrapper vs. ? - GameDev.net ... COM vs DLL.

    Is that good idea to make dll for functions which would be used in many of threads?
    I like jesterlecodeur idea. I play with com before and it seem like something best for you use in special places. Where, I don't know... Test.. Test ...test

    Is that good idea to make an interpretor for incoming data?
    I don't know. Ask these guys: flat assembler - Index and PC-BSD Forums - Powered by vBulletin

    - How should it be done to work fastest and be reliable all time?
    If it C++, hard-code it using algorithms as much as possible.

    - I've made it as class and create own class for each thread, isn't that waste of RAM?
    I don't know, but I had such an implementation I would test both ways as I monitor and benchmark CPU usage and RAM with pleasure.

    - Should I move it to dll as well?
    Maybe or maybe not. It depends on your program created to do your custom monitoring and benchmarking.

    The Tensor Field: Windows vs. Linux vs. FreeBSD vs. OSX - 12 dimensional analysis


    Other than that ... I don't have a clue...

    Good luck
    Last edited by sharris; 03-26-2011 at 02:56 PM.

  8. #8
    Registered User
    Join Date
    Aug 2010
    Location
    Poland
    Posts
    682
    Is that good idea to make dll's for most parts of code?
    Is that good idea to make dll for functions which would be used in many of threads?
    You miss the point of DLLs probably. Why would you want to separate code this way? Even if you want to separate code (to, let's say, portable and non-portable modules) use static libraries.
    I never put signature, but I decided to make an exception.

  9. #9
    Registered User
    Join Date
    Sep 2010
    Posts
    90
    Elysia wrote:
    Also means you have to be careful with memory usage. 5000 threads at once means a lot of stack space, so you have to restrictive.
    Not to change the subject but I never understood what made all of that possible during my Network+ class last year, and to think it took a full year to FINALLY find the answer. Just for that, i'm going for 100,000 connections per machine since it's more about stacks and memory. My C++ class is talking about that this coming week. Fear-not, I already completed the project and now simply trying to get fancy with-it. Anyway, soon every system will come with 1-Terabyte of RAM out the box at any Walgreens store. Bandwidth should be less than a tank of gas (per month) by than running on pure fibers. Technology since the 90's has really advanced it's so UNBELIEVABLE given the fact that it took the boob-tube sixty years to turn into flat-screen TV.

  10. #10
    Registered User
    Join Date
    Mar 2011
    Posts
    69
    Ye, I have to read some more about that.

    However, I've made a tester application which is running new threads for connect to server. When I reach number of about 900 connections I got this error on server "This application has requested the Runtime to terminate it in an unusual way. Please contact the application's support team for more information.". I read somewhere it's Msvcirt.dll fault, how can I fix it in CodeBlocks?

  11. #11
    Registered User
    Join Date
    May 2009
    Posts
    2,703
    When you say creating "class" do you mean "object" or is it really a new class per each connection? I did not know you can create dynamic classes at run-time.


    Quote Originally Posted by kargo View Post
    Ye, I have to read some more about that.

    However, I've made a tester application which is running new threads for connect to server. When I reach number of about 900 connections I got this error on server "This application has requested the Runtime to terminate it in an unusual way. Please contact the application's support team for more information.". I read somewhere it's Msvcirt.dll fault, how can I fix it in CodeBlocks?
    I would say your question might be compiler version or OS version dependent; note, I have no idea what the answer is for any compiler/OS.

    Tim S.
    C++ Student

  12. #12
    Registered User
    Join Date
    Mar 2011
    Posts
    69
    You can do that with boost c++, actually I'm testing it on win7 64bit with codeblocks 10.05.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Socket ( server client Get pid )
    By Syd in forum C Programming
    Replies: 0
    Last Post: 02-15-2011, 07:00 AM
  2. INT 15 to return memory size
    By pole1080 in forum C Programming
    Replies: 49
    Last Post: 06-23-2010, 09:28 AM
  3. Where's the EPIPE signal?
    By marc.andrysco in forum Networking/Device Communication
    Replies: 0
    Last Post: 12-23-2006, 07:04 PM
  4. IE 6 status bar
    By DavidP in forum Tech Board
    Replies: 15
    Last Post: 10-23-2002, 05:31 PM
  5. socket question
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 07-19-2002, 01:54 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21