|
Paul Conrad wrote: Yes, but this one and this other one are pretty right on the money.
I don't like their ideas because they say that you read the file 10000 lines and use the sqlBulkcopy to write that 10000 records and then again read 10000 records, but suppose if i read 10000 records from a file and successfully written them to table but on next time when i read next 10000 records and when in the time of writing records to table any exception occurs then my Table goes to inconsistent state, because 10000 records are in, but it should be like that either all data written or none of them should be written.
Then...........................
“You will never be a leader unless you first learn to follow and be led.”
–Tiorio
"Coming together is a beginning, staying together is progress, and working together is success." Henry Ford
|
|
|
|
|
There's this really neat thing in databases called "transactions". Start a transaction, perform your operations, if all goes well you commit the transaction, if not then you rollback the transaction.
|
|
|
|
|
SqlTransaction will only be used for current 10000 records not for next 10000 records..
Like this
step 1: //DataTable dt= ReadTenThousandLines();
Step 2: // Write_to_database (dt);
In Write_to_database() function, I will use sqlBulkCopy nad their i Use SqlTransaction Class, but suppose if i again passing 10000 Record containing datatable and if it fails then ??????????????
“You will never be a leader unless you first learn to follow and be led.”
–Tiorio
"Coming together is a beginning, staying together is progress, and working together is success." Henry Ford
|
|
|
|
|
Mogaambo wrote: SqlTransaction will only be used for current 10000 records not for next 10000 records..
That's a bit pointless.
Mogaambo wrote: In Write_to_database() function, I will use sqlBulkCopy nad their i Use SqlTransaction Class, but suppose if i again passing 10000 Record containing datatable and if it fails then ??????????????
My advice has not changed. You use a transaction. You start it, you do all your bulk copying then you commit the transaction. You do NOT create one transaction for each batch of data. You create ONE transaction to cover everything.
|
|
|
|
|
With your suggestion reading from file and writing to database should be done in 1 shot.
For eg.
WriteToDataBase(string filename)
{
//Begin SqlTransaction
Begin loop to read 10000 records at a time (While all the records are not read)
//write in a datatable
//End loop
//End SqlTransaction
}
// Some thing like this you want me to do
“You will never be a leader unless you first learn to follow and be led.”
–Tiorio
"Coming together is a beginning, staying together is progress, and working together is success." Henry Ford
|
|
|
|
|
You are not paying attention. Or you are not bothering to understand transactions.
Begin Transaction
Start File Loop
Start Data Chunk Loop
Read upto 10,000 records from file
Write those records to the database
End Data Chunk Loop
End File Loop
End Transaction
Each iteration around the Data Chunk Loop has one communication with the database (One "shot" per iteration)
If you have a million records you have 100 "shots" at writing to the database.
|
|
|
|
|
Thanks for your quick reply,
But,
Colin Angus Mackay wrote:
If you have a million records you have 100 "shots" at writing to the database.
Is this strategy fast enough , because to write 25 files it would take approx.
25 * 100= 2500 shots
Means 2500 iteration will be performed for writing 25 files.
“You will never be a leader unless you first learn to follow and be led.”
–Tiorio
"Coming together is a beginning, staying together is progress, and working together is success." Henry Ford
|
|
|
|
|
Well, your choice is going slightly slower, use SSIS (as someone else suggested) or running out of memory - You choose! I give up.
|
|
|
|
|
Well first of all thanks for your valuable suggestions but as you are MVP and you say
Colin Angus Mackay wrote: I give up.
But Something for you.
Sam Ewing: It's not the hours you put in your work that count, it's work you put in the hours.
F. Scott Fitzgerald: You don't write because you want to say something; you write because you've got something to say.
“You will never be a leader unless you first learn to follow and be led.”
–Tiorio
"Coming together is a beginning, staying together is progress, and working together is success." Henry Ford
|
|
|
|
|
He gave up because you're an asshat.
Be a programmer for god's sake, and implement a solution.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
John Simmons / outlaw programmer wrote: asshat
Thank you very very much A**Hole
“You will never be a leader unless you first learn to follow and be led.”
–Tiorio
"Coming together is a beginning, staying together is progress, and working together is success." Henry Ford
|
|
|
|
|
You're arguing with the guy that gave you a solution. Who here is the a**hole?
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
Tell me where do i argued, i say thanks to his valuable suggestions and is my questions are pointless , no not they are. if he doesn't say anything to me then y your azz is itching.
“You will never be a leader unless you first learn to follow and be led.”
–Tiorio
"Coming together is a beginning, staying together is progress, and working together is success." Henry Ford
|
|
|
|
|
Mogaambo wrote: Well first of all thanks for your valuable suggestions but as you are MVP and you say
Colin Angus Mackay wrote:
I give up.
But Something for you.
How about this. He's good at what he does because he recognizes that to keep working on a futile solution is a pointless.
|
|
|
|
|
|
Mogaambo wrote: more fast then previous one
Probably because you are not thrashing the virtual memory's page file.
|
|
|
|
|
Mogaambo wrote: Yes I did , but check yourself what answers i received, are they fruitful
no no no no
Uhhh, yes they are. And you were told exactly why your approach wouldn't work. You simply ARE running the machine out of memory trying to read and retain all that data at once. You have no choice but to either read and process the data in small chunks, or farm the entire job out to SQL Server to do it for you.
|
|
|
|
|
Hello everyone,
I am designing a library which client side could use it to retrieve content from a remote cache server, through Http/Web Services communication.
My current issues and concerns are,
- I want to let client side library to start multiple threads to work efficiently to request for multiple content at the same time other than a single thread pattern;
- But I do not want to hit the server too hard and I also do not want to the library to consume too much resources (memory/threads) on client side to block other work of the client. The library is delivered as a DLL, so loaded into client side process, and will compete for resources of the same process.
Are there any good design patterns for such issues?
thanks in advance,
George
|
|
|
|
|
George_George wrote: Are there any good design patterns for such issues?
Hello George. At this point it is difficult to believe that you even comprehend what Design Patterns are. If you are asking if there is some magical solution for using threads that will absolve you, the developer, from responsibility to ensure the very requirements you speak of, the answer is NO. The developer has to actually know what they are doing and do it in a way that will achieve the requirements.
That said, the history of your posts, as far as I can tell, does not indicate that you are prepared to undertake a multi-threaded project. However I imagine that you will do so none the less. Logically we can expect to see many many future threads from you wondering why your multi-threading code doesn't work.
led mike
|
|
|
|
|
Thanks led mike,
My current situation is,
1. I can create many threads on client side to get data from server as fast as possible, but it may hit server too hard -- like DoS attack;
2. I can limit the number of threads of client side, in this situation server is not hit too hard, but client may not get data very efficiently.
I want to find solution to balance such situation. Any ideas?
regards,
George
|
|
|
|
|
George_George wrote: I can create many threads on client side to get data from server as fast as possible
You can? Really? Why because your client machine has unlimited processors? What vendor did you buy that from? I really need to get me one of those!
George, pay attention. You cannot learn about multi-threading in 5 minutes. Furthermore people have written entire books on the subject because that's how large and difficult the subject is, so why would I, or anyone else, attempt to provide an explanation in an internet forum? Wouldn't the be illogical?
If you don't have access to such books, people have posted such writing on the internet and they are freely available. However to find and read them one has to not spend all one's time in internet forums. If you really are interested in reading what is known in the industry about multi-threading, load and scaling, I strongly suggest you stop typing questions into internet forums and start using Google to find what known leaders in the industry have to say about the subject.
The truth is out there
led mike
|
|
|
|
|
Thanks led mike,
Please trust me I understand multi-threading, and also IOCP concept.
It is appreciated if you could recommend some good tutorials or books for me to read -- not about multi-threading, but the issue I described in this question about data access pattern issues. Any suggestions?
regards,
George
|
|
|
|
|
George_George wrote: Please trust me I understand multi-threading, and also IOCP concept.
That's not going to happen.
led mike
|
|
|
|
|
Hi led mike,
You mean what is not going to happen? Any issues with IOCP or?
regards,
George
|
|
|
|
|
George_George wrote: You mean what is not going to happen?
I am not about to believe you understand those things, and as my post in the other thread states, I believe you are being deliberately obtuse. I'm not impressed.
led mike
|
|
|
|