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!
High-volume network server ?
High-volume network server ?
Last edited by USCode on Thu Oct 26, 2017 9:55 pm, edited 1 time in total.
Re: High-volume network server ?
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
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
Re: High-volume network server ?
Because the ones that need to handle a high-volume of requests are flocking to Goinfratec wrote:REST ? Why you don't use nodejs?
Sorry couldn't resist
I am to provide the public with beneficial shocks.
Alfred Hitshock
Re: High-volume network server ?
Correct, I want to write a server in PB which handles a lot of client requests.infratec wrote:... Do you want to write server which handles a lot of client requests ...
Thanks Bernd!
Re: High-volume network server ?
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:
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
Hope this helps.
Bernd
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
Because not all clients use a correct disconnect.
I create also multiple servers with a list of ServerStructure.
Of course on different ports
Hope this helps.
Bernd
Re: High-volume network server ?
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.
Re: High-volume network server ?
Very helpful, thanks Bernd!infratec wrote:...Hope this helps.
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.