Threaded Server Question

Everything else that doesn't fall into one of the other PB categories.
Karbon
PureBasic Expert
PureBasic Expert
Posts: 2010
Joined: Mon Jun 02, 2003 1:42 am
Location: Ashland, KY
Contact:

Threaded Server Question

Post by Karbon »

Is there any way with PB to create a thread for each connection to the server? The biggest problem I see with this is the ability to do event handling within the thread for just the single connection.. I don't have a clue if it's even possible..

Does anyone have any ideas?

Thanks!
-Mitchell
Check out kBilling for all your billing software needs!
http://www.k-billing.com
Code Signing / Authenticode Certificates (Get rid of those Unknown Publisher warnings!)
http://codesigning.ksoftware.net
Tranquil
Addict
Addict
Posts: 952
Joined: Mon Apr 28, 2003 2:22 pm
Location: Europe

Post by Tranquil »

Why do you want this? Why dont you handle all requests in a mainloop? Actions that takes more time I create a thread from the mainloop. But I set up a maximum- threads-value to avoid server hang up due to less CPU capacitis.

Are you using event-based networking or pooling? If you are using pooiling you should use threads, otherwise a mainloop with some threads (if needed) should be okay or?

Mike
Tranquil
Karbon
PureBasic Expert
PureBasic Expert
Posts: 2010
Joined: Mon Jun 02, 2003 1:42 am
Location: Ashland, KY
Contact:

Post by Karbon »

Ahh.. My socket buddy Mike... Hi Mike :-)

My concern is that the server blocks while processing each request from a user. Some of the requests users send will take a little while to process (some will grab info from the database etc etc). With the current model the server will only serve 1 request at a time - this could be a big problem when we get more and more users connecting... Each users would have to wait for every other user's request to complete before they got any response form the server.. I'm really worried about that totally trashing the speed of this thing as a multi-user server!

I thought about just spinning off threads for certain kinds of requests and that seems possible, though a little messy. I'm used to fork()ing or creating a thread for each connection from my previous UNIX socket programming experience so that's why I ask :-)

To answer your question of events or polling, I'm using the events right now. That might just have to change - which means I'll probably go ahead and write the server in C unless you can using the polling method from within PB easily.. I'll have to get out the windows socket reference and look around!
-Mitchell
Check out kBilling for all your billing software needs!
http://www.k-billing.com
Code Signing / Authenticode Certificates (Get rid of those Unknown Publisher warnings!)
http://codesigning.ksoftware.net
Tranquil
Addict
Addict
Posts: 952
Joined: Mon Apr 28, 2003 2:22 pm
Location: Europe

Post by Tranquil »

Server-Tasks on different users which takes many CPU time (eg searching a database etc) will be prozessed in a thread. Thats the best you can do but becomes hard to realize if strings are needed.

That makes server-coding in PB very very difficult. I'm still waiting for string-save threads since version 3.30 to complete our file-sharing tool. Our client is completely finished we only need to code the server which is atm not possible in PB. :-(

Mike
Tranquil
Karbon
PureBasic Expert
PureBasic Expert
Posts: 2010
Joined: Mon Jun 02, 2003 1:42 am
Location: Ashland, KY
Contact:

Post by Karbon »

Yes, the thread safety issues are a concern..

Check out this code and see what you think. It's based on the code you sent me forever ago - same basic flow and function. I used memory buffers instead of string type vars so it would be thread safe.. It is more of a pain but at least its a step in the right direction!

http://www.purebasic.org/comments.php?id=P20_0_1_0
-Mitchell
Check out kBilling for all your billing software needs!
http://www.k-billing.com
Code Signing / Authenticode Certificates (Get rid of those Unknown Publisher warnings!)
http://codesigning.ksoftware.net
Tranquil
Addict
Addict
Posts: 952
Joined: Mon Apr 28, 2003 2:22 pm
Location: Europe

Post by Tranquil »

Thanks for this source. I noticed your source in the Tipps and tricks section.

But in my server source its not possible to implement couse there are to much datas to handle and I dont want to rewrite all. I will wait for the next PB Version which hopefully supports thread save strings.

Mike
Tranquil
Karbon
PureBasic Expert
PureBasic Expert
Posts: 2010
Joined: Mon Jun 02, 2003 1:42 am
Location: Ashland, KY
Contact:

Post by Karbon »

Yes, thread safe strings will make things a lot easier!

*grins at Fred*

:-)
-Mitchell
Check out kBilling for all your billing software needs!
http://www.k-billing.com
Code Signing / Authenticode Certificates (Get rid of those Unknown Publisher warnings!)
http://codesigning.ksoftware.net
Holborn
New User
New User
Posts: 4
Joined: Wed Nov 12, 2003 4:06 pm

Post by Holborn »

I beg of you, please make thread-safe strings a reality. I beg of you.
Paul Dwyer
User
User
Posts: 44
Joined: Wed Nov 05, 2003 4:34 am
Location: Tokyo, Japan

Post by Paul Dwyer »

Why stop at strings? :roll:
Paul Dwyer
Network Engineer
Aussie in Tokyo
Post Reply