RTC Forums
November 24, 2024, 05:34:40 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
 
   Home   Help Login Register  
Pages: [1]
  Print  
Author Topic: About optimizations and thread safety  (Read 6510 times)
agsoft
Newbie
*
Posts: 15


« on: February 23, 2010, 10:15:50 AM »

I have some penetrating questions,Let's sit down and have a calm and sensible talk.

1.There are two TRtcClientModules in the RTC Messager Client(ClientModule and TimerModule),
SO the RTC Messager Server have to create double sessions(AutoSesstion) info,it Will consume more memory and more pc resource.
I want to one client has only one session with two TRtcClientModules,how to do?

2.Under the large chat connection,i think Write_File/rename_file method will lead to inefficiency because it write to hard disk repeatedly.
  And TRtcCritSec will lead to inefficiency because of writing tRtcRecord repeatedly.I want to send the message data immediately int the memory.  Is it safety thread method that if i only append/update TRtcRecord not delete() TRtcRecord SO I can give up TRtcCritSec.Enter/leave in the multi thread?


3.PrepareDelayedCall like a timer in the multi thread,It is timer Event,i think it is inefficiency and more memory,more cpu usage.
  Do you think SO?  But Remobjects SDK CallBACK function,it register events only once and trigger client immediately.

4.From Above logs,it is very nice that I think only call PrepareDelayedCall ones,dont call repeatedly.

Thank you very much!
Logged
D.Tkalcec (RTC)
Administrator
*****
Posts: 1881


« Reply #1 on: February 23, 2010, 10:35:11 AM »

You really should learn about thread-safe programming before you start making "improvement suggestions". Here is a simple explanation which should get you started:
http://en.wikipedia.org/wiki/Thread_safety

In short, sometimes you need to sacrifice some performance (use critical sections) or memory (use separate object instances) to gain thread-safety. I do not know what kind of load you are expecting from your Server, but if you make changes you are suggesting, you will most definitely make your code unsafe for use in a multi-threaded environment.

Best Regards,
Danijel Tkalcec
Logged
agsoft
Newbie
*
Posts: 15


« Reply #2 on: February 24, 2010, 01:39:12 AM »

yes,I know thread safety,I offten use TCriticalSection.
Logged
D.Tkalcec (RTC)
Administrator
*****
Posts: 1881


« Reply #3 on: February 24, 2010, 01:57:24 AM »

Looking at your questions, I doubt you really understand that it takes to make your code thread-safe.

1. You are suggesting to use a single Session object from two independent connections, which either means that you want your Server to run in single-threaded mode, or that you do not understand why you can not use a single Session object from multiple threads at the same time.

2. You are suggesting that the use of critical sections, in particular the enter and leave methods, will make your code run slow, and then ... you are suggesting to use a single TRtcRecord object from multiple threads without using a critical section, with the explanation that this should be OK because you would "only" be appending and updating data. But append as well update are WRITE operations which will not only modify a single variable state but in case of a dynamic record (which TRtcRecord is) mean re-balancing the field name search tree and increasing the name and value arrays. And doing that from more than one thread would most definitely break the structure apart.

Best Regards,
Danijel Tkalcec
Logged
agsoft
Newbie
*
Posts: 15


« Reply #4 on: February 24, 2010, 02:18:20 AM »

I am sorry ,I have this idea because the RTCRecord can not readlly delete(or use extract method ) node name,it always remain the nodename .So I have to judge node is null or not. The question is finished!



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.025 seconds with 17 queries.