Session state

A

Alex

I have a WS that contains multiple classes and web methods. We need to keep
track of execution times. To do this, I created a class with two properties,
one of them is a unique "ThreadId" which is a simple random string. The
reason for this is that we need to keep track of execution times through all
methods. E.g. GetUser() calls a Login() method, and then calls the GetUser
data access method, then calls a DataSetToJSON method etc, so the theory is
that when we query the execution times, we can see the stack trace and group
it by the ThreadId.

The problem is that when we have multiple hits to the WS, the ThreadId is
being "shared" among different connections. I assumed that each new WS call
will get it's own ThreadId, but this is not the case.

How can I create this object containing the threadId for each specific
connection?

Thanks
 
A

Alex

An Example is when User1 calls a web method, I generate a "ThreadId" string
and log that in the database. When User2 calls a web method in the same
class, it too generates a different ThreadId. But in some cases, when traffic
is high, it looks like the same ThreadId is being used by different users.
 
P

Patrice

Hello,
I have a WS that contains multiple classes and web methods. We need to
keep
track of execution times. To do this, I created a class with two
properties,
one of them is a unique "ThreadId" which is a simple random string. The
reason for this is that we need to keep track of execution times through
all
methods. E.g. GetUser() calls a Login() method, and then calls the GetUser
data access method, then calls a DataSetToJSON method etc, so the theory
is
that when we query the execution times, we can see the stack trace and
group
it by the ThreadId.

How do you create those "thread id" ? You could likely unit test your thread
id generator to see if you get duplicates...

AFAIK the session state module creates session ids by creating a guid that
is then turned into a string (base 64 encoded ?). You could perhaps use
something similar. Strictly speaking, uniqueness is not enforced but if you
ever come accross a collision you are really out of luck (i.e. something
like getting the same value twice when you have 10 power 36 possible
values)...

Also it is still possible that you have some kind of programming error
(notably using C# static or VB shared data). How do you keep this thread id
accross calls ?
 
A

Alex

The string generation is pretty unique. But I think the issue is in the code.
I'm using InvokeMember to execute methods (used for version control) and I
think it's none-managed code, and coupled with the fact that I'm using a
static data object, the results are that some "connections" use the same
object.

I'm about to test this and will update the thread.

Thanks for the reply.
 
A

Alex

That was it. InvokeMember makes the class loose state. There goes a day that
I'll never get back...
 
P

Patrice

Yes, static data are shared by the whole application. The point to keep in
mind is that a web application is a *single* application used by multiple
users at the same time so all static data are shared accross those users...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,989
Messages
2,570,207
Members
46,783
Latest member
RickeyDort

Latest Threads

Top