Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I'm building an multi processes application and I need to save session ID, the sessions ID is 32 bit, and of course it can't be used twice in its lifetime, I'm currently using DB that saves all the ID in a table, and I do the following,

ID table is (int key, char used(1)) //1 is used, 0 is not 1. lock table 2. get one key for one sessions 3. update used field in it to used 4. unlock

After the session is finished the process use below to free key, 1. lock table 2. update used field in it to not used 4. unlock

I'm really wondering whether this is a good/fast implementation. and please note it's multi processes application.

share|improve this question

2 Answers 2

up vote 1 down vote accepted

Did you try memcached? It's fast, it has atomic updates, it does not have all the rest of database overhead. Not as fast as raw shared memory, but probably session registration is not your bottleneck anyway?

share|improve this answer

By definition database access is no the fastest repository. I need more details about the process to tell you something more useful, but keep in mind that using a database to do what you want is the simplest way but not the fastest. This link shows how Voltdb generates its unique transaction ID in a distributed environment : http://voltdb.com/company/blog/lifecycle-transaction.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.