cuncurrent access to file on network

F

Fabio R.

To support a webfarm scenario, I'd like to store a global array (serialized)
in a file on a network share.
In this array there is a list of pages "locked" by other users so I need to
read this array at every page access to detect if the page is "free" so the
user can access it; when the user can access the page, the page is added to
the array so the next user can't access.
What's the best way to lock this (network) file so when 2 users access the
same page, the first user changes the array (writing to file) and the second
user can only read the file after the first user has finished the task?
FileShare.None throw an error if the filestream is already open...
Thanks in advance for support and sorry for my not-so-good english language
:)
Fabio
 
G

Guest

I'm not 100% sure I understood but..
Are you saying you keep the pages that are "locked" in a text file and read
this in all the time? If so you have bigger issues. How do you clear a
"lock"? If the person closes their browser how do you release this?

Sounds like you may need to rethink things a little at a bigger level.
 
F

Fabio R.

It works very fine, the array contains userid, pageid and the lock datetime:
locked pages are removed from array every time the same user access another
page while other pending lock are removed if older than session timeout.
For now I use a try / catch, when an IO Exception occur ("file is used by
another process") I use a Threading.Sleep to wait 10 milliseconds before
reading the file again.
Works locally, but I don't know if it will be stable when the application
will have 10-20 cuncurrent users reading/writing the file ( but a webserver
log file doesn't do the same? )...
Any suggestion / other methods?
Fabio
 
G

Guest

DB may be better to track the locks (using the same cleanup practices) but if
what you have works then give it a shot I guess. I'm a bit concerned that the
file is opened/closed/read so much (every page load) that it may have issues
with scaling.

--
Curt Christianson
site: http://www.darkfalz.com
blog: http://blog.darkfalz.com
 
F

Fabio R.

Mmm... DB probably (but I'm not sure) is more solid, but it's not slower
than reading the file? If it can be a better choice, how to lock the table
as I do with file?
Thanks,
Fabio
 

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

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top