Client Server Application - Design issue - Writing to a file sequentialy during a session
-
The client server application, is a simple purchase order application I wish to write each order received by the server sequentially to a file. What would be best practise? (1) Keep the file open whilst the program is running, then write each order received during the server session, then close the file when the program ends. (2) Open then write the record then close the file for each order received What would be the pros and cons for the above mentioned? Thanks in advance Simon
-
The client server application, is a simple purchase order application I wish to write each order received by the server sequentially to a file. What would be best practise? (1) Keep the file open whilst the program is running, then write each order received during the server session, then close the file when the program ends. (2) Open then write the record then close the file for each order received What would be the pros and cons for the above mentioned? Thanks in advance Simon
Which one is more attractive? Well, number 2 is more flexible in case someone else has to edit/archive orders... unless you are running into performance problems, which would make number 1 the more attractive contender in this battle of designs.
Chat in Europe :java: Now with 24% more Twitter
-
The client server application, is a simple purchase order application I wish to write each order received by the server sequentially to a file. What would be best practise? (1) Keep the file open whilst the program is running, then write each order received during the server session, then close the file when the program ends. (2) Open then write the record then close the file for each order received What would be the pros and cons for the above mentioned? Thanks in advance Simon
No. 1 is better in terms of performance. You could give it read share access if any other program wishes to read the same file when it is kept open.
«_Superman_»
I love work. It gives me something to do between weekends. -
The client server application, is a simple purchase order application I wish to write each order received by the server sequentially to a file. What would be best practise? (1) Keep the file open whilst the program is running, then write each order received during the server session, then close the file when the program ends. (2) Open then write the record then close the file for each order received What would be the pros and cons for the above mentioned? Thanks in advance Simon
simon alec smith wrote:
(2) Open then write the record then close the file for each order received
I always prefer (2) one, because if there is any crash, chances of data-loss is very much. Secondly it also depend how frequently is data coming, if it quite fast, then option 1 also stands good.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
Never mind - my own stupidity is the source of every "problem" - Mixturecheers, Alok Gupta VC Forum Q&A :- I/IV Support CRY- Child Relief and You
-
The client server application, is a simple purchase order application I wish to write each order received by the server sequentially to a file. What would be best practise? (1) Keep the file open whilst the program is running, then write each order received during the server session, then close the file when the program ends. (2) Open then write the record then close the file for each order received What would be the pros and cons for the above mentioned? Thanks in advance Simon
As the others have mentioned keeping the file open will be faster but second will be more secure if something goes wrong. You might be able to get some of the the performance of keeping the file open with opening and closing it every time by opening the file unbuffered. This[^] has got loads of useful info about the pain in the neck this is to sector align buffers if you're on windows. You can do something similar on Linux with the open() system call. It all depends on how much money's involved if something goes wrong and how much the customer is willing to pay for security. Another solution might be to open and close the file every transaction and make sure the powers that be spend the money they'd have spent on you engineering a software solution on more memory for the server to reduce the impact of repeated opens and closes. Another option might be to try the double open trick that used to work years ago on some Unixen and DOS. You'll have to see if this does any good, I've not used it on any version of windows since Windows '95. What you do is open the file when the program starts. This makes a second opening really quick when you write a transaction. when you finish writing the transaction you close the file which flushes it to disk. Finally when the program terminates you close the original opening. Cheers, Ash