AWestEng
asked on
Remoting (client/server): Writing to remote object ,(synclock)
Hi!
I have a question regarding writing to a remote object.
I have a server that receives information from a client, this client execute several rows of code, each row sends data to the server and each call is to the same function on the server.
So on the client side I have this.
Private sub SendData
Server.WriteData = 10
Server.WriteData = 11
Server.WriteData = 12
Server.WriteData = 13
Server.WriteData = 14
Server.WriteData = 15
Server.WriteData = 16
and so on&.
End sub
So we call the same function several times but each write takes some time, the WriteData function on the server is pretty large.
So my question is, is this going to work? Or must I have a synclock on the server function or does the remoting stuff takes care of that?
I have a question regarding writing to a remote object.
I have a server that receives information from a client, this client execute several rows of code, each row sends data to the server and each call is to the same function on the server.
So on the client side I have this.
Private sub SendData
Server.WriteData = 10
Server.WriteData = 11
Server.WriteData = 12
Server.WriteData = 13
Server.WriteData = 14
Server.WriteData = 15
Server.WriteData = 16
and so on&.
End sub
So we call the same function several times but each write takes some time, the WriteData function on the server is pretty large.
So my question is, is this going to work? Or must I have a synclock on the server function or does the remoting stuff takes care of that?
ASKER
ok, let's take this instead,
If I have a object in the server 1 and server 2 and server 3 is both trying to write to this object in server 1, do I need a syncklock on the object for server 1 then?
If I have a object in the server 1 and server 2 and server 3 is both trying to write to this object in server 1, do I need a syncklock on the object for server 1 then?
Synclock I usually use in multitreading environment of a single app, and needs a lot of attention for deadlocks
if you are confortable with Synclock then it is ok. Synclock tell the code to treat each request separatelly. Its hard to debug thought (especially in remoting)
I'd recoment using Queue function of vb.net so you put your .WriteData to first-come-first-served
if you are confortable with Synclock then it is ok. Synclock tell the code to treat each request separatelly. Its hard to debug thought (especially in remoting)
I'd recoment using Queue function of vb.net so you put your .WriteData to first-come-first-served
ASKER
oki. have you any example on the Queue function.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
nice thx n8,
I'm not sure how this works in remoting and calling the same function at the same time. I register the interface that all the other servers and clients can communicate with. all ok there..
Iif 3 other servers calls the same function via the registerd interface how does the remote stuff works then. Does it Queue it up self or must I do that? and if I not Queue it up what happens when 3 other servers calls the main server at the same time?
I'm not sure how this works in remoting and calling the same function at the same time. I register the interface that all the other servers and clients can communicate with. all ok there..
Iif 3 other servers calls the same function via the registerd interface how does the remote stuff works then. Does it Queue it up self or must I do that? and if I not Queue it up what happens when 3 other servers calls the main server at the same time?
Let's see the statment
Dim X as Integer
X = 1
X = X + 1 'a programmer thinks that this line is a single operation
From the computers perpective is not: It is: 1.-Move the value x into a register, 2.-move the value 1 into another register, 3.-add the values to a third register and at the end 4.-copy the added value to memory address of value x
Now if a single user is performing the task, everything is ok.
If 2 users (or more) are requesting the same task from the same function the computer could stop the operation at any step point of the 1 user to serve the 2 user, so there is a good chance that values will mess up
Your question "at the same time?" has different meaning for humans and different for computers.
If your function takes 1/10 of a second to complete then it is very difficult for 2 users to hit a button at the same time, e.g. from 2 workstations.
-but- if your function takes 2sec to complete then it is more likely that 2 users can hit a button at the same time and then the computer has to stop the first request at some point to give the 2nd request priority. So public or global variables will probably mess up
As for the queue
You create it. As I wrote before, instead of calling the main function (at the remote computer) call a function lets call it addJob(parameters as the params of your main function)
At this point add the job to the queue. (Enqueue)
When finished proceess the queue with Dequeue
MyString = MyQueue.Dequeue
finally loop the queue using GetEnumerator method to see if all jobs are finished
I can understand your question "Does it Queue it up self?" the answer is no:you fill it up AND the answer is also yes: when a second request comes the queue is the same memory (Just like when to computer send a print job to a printer)
I hope I did not confuse you!
Dim X as Integer
X = 1
X = X + 1 'a programmer thinks that this line is a single operation
From the computers perpective is not: It is: 1.-Move the value x into a register, 2.-move the value 1 into another register, 3.-add the values to a third register and at the end 4.-copy the added value to memory address of value x
Now if a single user is performing the task, everything is ok.
If 2 users (or more) are requesting the same task from the same function the computer could stop the operation at any step point of the 1 user to serve the 2 user, so there is a good chance that values will mess up
Your question "at the same time?" has different meaning for humans and different for computers.
If your function takes 1/10 of a second to complete then it is very difficult for 2 users to hit a button at the same time, e.g. from 2 workstations.
-but- if your function takes 2sec to complete then it is more likely that 2 users can hit a button at the same time and then the computer has to stop the first request at some point to give the 2nd request priority. So public or global variables will probably mess up
As for the queue
You create it. As I wrote before, instead of calling the main function (at the remote computer) call a function lets call it addJob(parameters as the params of your main function)
At this point add the job to the queue. (Enqueue)
When finished proceess the queue with Dequeue
MyString = MyQueue.Dequeue
finally loop the queue using GetEnumerator method to see if all jobs are finished
I can understand your question "Does it Queue it up self?" the answer is no:you fill it up AND the answer is also yes: when a second request comes the queue is the same memory (Just like when to computer send a print job to a printer)
I hope I did not confuse you!
ASKER
I really appreciate that you helping me. thx man. :)
I read in a blog about remoting that if you use singelton server that the remoting suff will queue up the request that other server/clients calls, but this is not true then?
sorry for all the question, I just trying to get the hole picture. :)
I read in a blog about remoting that if you use singelton server that the remoting suff will queue up the request that other server/clients calls, but this is not true then?
sorry for all the question, I just trying to get the hole picture. :)
I have no knowledge of 'singelton server'
I shall create a Queue example and post it back. It will take me some time because I'm working on a project with dead end sunday
I shall create a Queue example and post it back. It will take me some time because I'm working on a project with dead end sunday
ASKER
thx man, that would be great if you could
ASKER
I tink the Queue methods will be best as you said..
I'll try to make some code,
I'll try to make some code,
I have not forgot the queue project...
It will take some time. -but- I haven't finished my dead line (past already) of the proj Im working on.
If you make some code, post it so I can take a look
It will take some time. -but- I haven't finished my dead line (past already) of the proj Im working on.
If you make some code, post it so I can take a look
ASKER
AkisC:
do you know anything about process, I really need someone that knows what he's talking about.
http://www.experts-exchang e.com/Prog ramming/La nguages/.N ET/Q_23810 766.html
do you know anything about process, I really need someone that knows what he's talking about.
http://www.experts-exchang
ASKER
I'm going to start working on this next week,, so then I will probably need some help. :)
ASKER
Hi AkisC!
Now it's time for the Queue stuff, So if you have any time left I really would appreciate if you have any examples,
Now it's time for the Queue stuff, So if you have any time left I really would appreciate if you have any examples,
ASKER
Hi
I have a question, the remoting stuff I use will add to the queue and another thread will dequeue so I must protect the queue in some way or don't I? so the remoting is not adding at the same time as the other thread is removing,
I found this code
http://www.codeguru.com/co lumns/dotn et/article .php/c4609
I have a question, the remoting stuff I use will add to the queue and another thread will dequeue so I must protect the queue in some way or don't I? so the remoting is not adding at the same time as the other thread is removing,
I found this code
http://www.codeguru.com/co
''' <summary>
''' Add items to the queue.
''' </summary>
Public Sub Enqueue()
Dim counter As Integer = 0
Monitor.Enter(Me._queue)
While counter < MAX_QUEUE_SIZE
' Wait while the queue is busy
Monitor.Wait(Me._queue)
' Add one item to the queue
Console.WriteLine("Adding item {0} to queue", counter.ToString())
Me._queue.Enqueue(System.Math.Max(System.Threading.Interlocked.Increment(counter),counter - 1))
' Release the queue
Monitor.Pulse(Me._queue)
End While
Monitor.[Exit](Me._queue)
End Sub
''' <summary>
''' Remove items from the queue.
''' </summary>
Public Sub Dequeue()
Monitor.Enter(Me._queue)
' Release the queue because we just locked it
' setting up the region lock
Monitor.Pulse(Me._queue)
' Wait while the queue is busy
' and exit on the timeout when the first thread stopped
While Monitor.Wait(Me._queue, 500)
' Remove the first item and display it
Dim counter As Integer = CInt(Me._queue.Dequeue())
Console.WriteLine("Removed item {0} from queue", counter.ToString())
' Release the queue
Monitor.Pulse(Me._queue)
End While
Monitor.[Exit](Me._queue)
End Sub
ASKER
Hi AkisC!
Do have time to check the code? :)
Do have time to check the code? :)
Maybe you can get some idea from my answer at https://www.experts-exchange.com/questions/23692399/Problem-with-events-in-NET-Remoting.html
I use this approach with success for 40 concurrent users.