High-volume network server ?

Just starting out? Need help? Post your questions and find answers here.
User avatar
USCode
Addict
Addict
Posts: 912
Joined: Wed Mar 24, 2004 11:04 pm
Location: Seattle, USA

High-volume network server ?

Post by USCode »

Using the PB Network library to develop a server, how best to handle a high-volume of client requests (e.g. REST) to a server? At a high-level, what is the best architecture?

Should I have one server process with CreateNetworkServer() which receives all the initial requests, but which then hands off the processing of each client request to an new process OR thread? How is that done?
Seems like handing the work off to a new separate process would be ideal in case the original process with CreateNetworkServer() in it fails, then it won't bring everything else down as would happen with just a bunch of separate threads handling the requests? How do I get the network events between the client and server re-directed to the new server process/thread?

Please let me know if that all doesn't make sense and I will try to clarify. Thanks!
Last edited by USCode on Thu Oct 26, 2017 9:55 pm, edited 1 time in total.
infratec
Always Here
Always Here
Posts: 6874
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: High-volume network server ?

Post by infratec »

Only for clarification:

Do you want to write server which handles a lot of client requests,
or do you want o write a client which generates a lot of server requests :?:

Because in your first line you wrote 'to a server'

REST ? Why you don't use nodejs?

Bernd
User avatar
fsw
Addict
Addict
Posts: 1572
Joined: Tue Apr 29, 2003 9:18 pm
Location: North by Northwest

Re: High-volume network server ?

Post by fsw »

infratec wrote:REST ? Why you don't use nodejs?
Because the ones that need to handle a high-volume of requests are flocking to Go :P
Sorry couldn't resist :oops:

I am to provide the public with beneficial shocks.
Alfred Hitshock
User avatar
USCode
Addict
Addict
Posts: 912
Joined: Wed Mar 24, 2004 11:04 pm
Location: Seattle, USA

Re: High-volume network server ?

Post by USCode »

infratec wrote:... Do you want to write server which handles a lot of client requests ...
Correct, I want to write a server in PB which handles a lot of client requests.
Thanks Bernd!
infratec
Always Here
Always Here
Posts: 6874
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: High-volume network server ?

Post by infratec »

Hi,

You described the right way.
Create a server thread.
If y connection comes in, store the incoming connection in a map and start a client thread.
If data comes in, use FindmapElement() to find the client, then set the RX flag in the map structure.
The client thread then gets the data via Receivenetworkdata()

I'm not allowed to show the code.

Here are my used structures:

Code: Select all

Structure ClientStructure
  Client.i
  Time.i
  Thread.i
  RxFlag.i
  Exit.i
EndStructure
  
  
Structure ServerStructure
  Directory$
  Port.i
  Bind$
  Server.i
  Thread.i
  Exit.i
  Map ClientMap.ClientStructure()
EndStructure
You have to check inside the server thread if a client connection is to old (time is filled with the last access)
Because not all clients use a correct disconnect.

I create also multiple servers with a list of ServerStructure.
Of course on different ports :wink:

Hope this helps.

Bernd
cas
Enthusiast
Enthusiast
Posts: 597
Joined: Mon Nov 03, 2008 9:56 pm

Re: High-volume network server ?

Post by cas »

If you will have large number of connections then you must learn IOCP (windows), epoll (linux) or kqueue (osx). These APIs are more complicated than simple PB network functions but they scale great with multi core systems and are very efficient with system resources. Try searching forum, maybe there are already some examples of them.
User avatar
USCode
Addict
Addict
Posts: 912
Joined: Wed Mar 24, 2004 11:04 pm
Location: Seattle, USA

Re: High-volume network server ?

Post by USCode »

infratec wrote:...Hope this helps.
Very helpful, thanks Bernd!

What made you choose to write your server in PB vs. something like node.js?
Did you find anything in particular missing in PB for writing this kind of server? e.g. Built-in SSL/TLS support.
Post Reply