Solved

LockFile() delays

Posted on 2002-07-03
14
272 Views
Last Modified: 2010-04-01
We have a proprietary database application running over a network.  If the network is good, everything runs fine.  However, many of our customers have (for one reason or another) considerable latency in their networks.  On those networks, there sometimes is a serious delay whenever we call FileLock(), and this is causing application errors.

Does anyone know of a way to make FileLock() more tolerant of network delays?
0
Comment
Question by:DanR
  • 5
  • 4
  • 3
  • +1
14 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 7128014
Do you mean 'LockFile()'? If so, 'LockFileEx()' might help...
0
 
LVL 32

Expert Comment

by:jhance
ID: 7128051
I'm not sure I understand how solving a network letency issue with LockFile() is going to help.  Assuming the underlying problem remains and by some means you got LockFile() to happen immediately, you're still going to be faced with the same latency for any subsequent read or write operation over that same network.

So by solving a problem with LockFile() you are only postponing the problem to a more in-opportune time.

It my opinion that a networked application such as this needs a solid network to support it.  Otherwise, it like building a house with a foundation made of rotten wood.  It's not going to hold up...
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7133298
You should not be locking files in a database application.  Instead, you should use the DBMS's record locking capability.  Could you describe your problem in more depth?  Thanks!

-- Dan
0
 
LVL 3

Author Comment

by:DanR
ID: 7137569
I have to say that I agree with jhance, however the application is ours, while the networks belong to our clients.  So their response is: "Everything else works fine over the network."  In most cases, they aren't running any other applications else over the network, but they just don't want to hear it.  When it comes right down to it, their network is what it is, and if our application won't run on it, then they'll look for something else.

DanRollins
This application was not built using a DBMS.  It's built from the ground up in C++.

jkr
You're right, of course, that it's LockFile().  I took a look at LockFileEx(), but I couldn't see that it's behavior would be different in any way that might help.
0
 
LVL 32

Expert Comment

by:jhance
ID: 7137589
I guess I just don't see HOW you're going to resolve this.  

You have an application that is dependent on a balky network, but you can't fix the network.

Basically you're asking how to reliably get from point A to point B when there is only one road between the two and there is a bridge on the road that is often closed.

Options:

1) Build a new road that has a reliable bridge or choose a different mode of transportation that does not depend on the bridge.
2) Duplicate everything you have at A at B also so you don't have to move stuff in a hurry.
3) Move everything to B so you don't have to travel the road.

In terms of your problem:

1) Put in a dedicated network between your system and the DB.
2) Have redundant copies of the database and synchronize them when the network is good.
3) Don't run over the network at all, make the database local to the application.
0
 
LVL 3

Author Comment

by:DanR
ID: 7137631
jhance
I agree.  What I was hoping was that someone knew of a way to redesign the vehicle to be better able to cross a shaky bridge.  Or maybe amphibious code...  Yeah...

Seriously, though, we can't stop the delay, but I'd like to have the application a little more tolerant of delays.
0
 
LVL 32

Expert Comment

by:jhance
ID: 7138205
Sometimes we are faced with problems for which there are no simple answers.  

If getting networked apps running smoothly over a balky network was simple, there would be little need for creating programmers like us, right?

Somehow you're going to have to reduce or eliminate the dependency on a responsive network.  I'm not sure it's going to be simple and it will certainly be a compromise.  But that is the essence of software engineering in general, isn't it?
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 3

Author Comment

by:DanR
ID: 7138807
I agree.  Anyone have any suggestions for making LockFile() more tolerant of slow network response times?
0
 
LVL 86

Accepted Solution

by:
jkr earned 100 total points
ID: 7138817
Have you tried 'LockFileEx()' with overlapped IO? This *should* work, as the completion event is only fired when the lock is granted...
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7138871
>> there sometimes is a serious delay whenever we call FileLock(), and this
>> is causing application errors.

You need to write your code to be more tolerant of the errors; that is, when it fails you need to retry rather than pushing on.  Or do the file locking on a separate thread and have the main thread monitor its completion status.  I suggest avoiding jkr's suggestion of using LockFileEx() with overlapped I/O because that would solve your problem too easily, and then you might be out of a job.

-- Dan
0
 
LVL 3

Author Comment

by:DanR
ID: 7147295
Thanks all.  The advice was good, but jkr was the closest to a solution (even though we couldn't implement it).
0
 
LVL 86

Expert Comment

by:jkr
ID: 7147828
Thanks! Out of curiosity, why couldn't you implement it?
0
 
LVL 3

Author Comment

by:DanR
ID: 7147849
The main developer nixed the idea since it would require to much of a rewrite, and this is a legacy product that we're just trying to keep on it's feet for another year to give clients a chance to move to our Web app.
0
 
LVL 86

Expert Comment

by:jkr
ID: 7147855
Ok, I *do* know that :o)

Thanx for the info...
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now