RTC Forums
May 18, 2024, 06:24:27 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
 
   Home   Help Login Register  
Pages: [1]
  Print  
Author Topic: Question about sessions and multi threaded server  (Read 4424 times)
HelgeLange
RTC Expired
*
Posts: 100


« on: January 06, 2018, 12:39:26 AM »

Hello (again),

a small question :

My server is multi threaded and all works fine with sessions, I now want to give every session a data object with a database connection and let them do some stuff within the thread of the event

Now the question is, since it is multi threaded and non-blocking on client side : what happens if I send a job and before it finishes on the server another job.  Will there be 2 events with the same session running, maybe in different threads ? Or does RTC work same sessions in sequence ?

Thanks for your clarifications,
Helge
Logged
D.Tkalcec (RTC)
Administrator
*****
Posts: 1881


« Reply #1 on: January 06, 2018, 08:48:01 AM »

This question has already been answered - here.

PS. RTC Sessions are nothing more than local storage objects. Their behavior is the same, regardless of the MultiThreaded property.

Best Regards,
Danijel Tkalcec
Logged
HelgeLange
RTC Expired
*
Posts: 100


« Reply #2 on: January 06, 2018, 03:23:52 PM »

The topic you're linking talks about the client side. I wanted to be sure, that for the server side that applies too or not.
I know, that the session object is "just" a data storage, but the question remains a bit unclear still :

Can I be sure, that in a multi threaded server only I can have access in my event to "my" session that was given me ? Or could it be that multiple events from the same connection and session are executed simultaneously and use the same session object ?

Sorry for  my persistence but I have to make sure, that I start developing in the right direction Smiley

Helge
Logged
D.Tkalcec (RTC)
Administrator
*****
Posts: 1881


« Reply #3 on: January 06, 2018, 04:43:39 PM »

No matter how the MultiThreaded property is set (TRUE or FALSE), a single TCP/IP connection will never trigger more than one event at the same time. This applies to the Client as well as the Server.

Also, to access a Session object, you need to acquire a lock for that Session by using the Session ID on the Server. By acquiring a lock on a Session, that Session is removed from the global Sessions pool and can NOT be locked from any other thread, until a lock is released again and the Session returned to the global Session pool.

When using RTC Remote Functions, a lock on a Session is acquired automatically by the TRtcServerModule component when a remote function call is received from a Client with a valid Session ID and released automatically before a result is sent back to the Client. Unless there are connection problems between a Client and the Server, provided you only use a single TRtcHttpClient component on the Client, you can rest assured that the Server will never have more than one event active from each Client, regardless of the MultiThreaded property on the Client and/or the Server.

On the other hand, if you have some longer running code on the Server and there are connection problems, it is possible for the same Client to close one connection, open a new connection and send a new request to the Server using the new connection, before the Server has finished executing the request previously received through the old connection (from that same Client). If that happens, you could end up with more than one event running on the Server for the same Client (one per TCP/IP connection opened by the Client to the Server), but ... as long as the last component (or event, or thread) using a Session keeps a lock on the Session object (IOW, the Session is still in use), no other components (or events, or threads) will be able to access that same Session.

Best Regards,
Danijel Tkalcec
Logged
HelgeLange
RTC Expired
*
Posts: 100


« Reply #4 on: January 06, 2018, 11:53:04 PM »

Thanks, that explains everything in detail. No more questions on that matter Cheesy
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!
Page created in 0.024 seconds with 15 queries.