Click here to Skip to main content
16,004,587 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am converting 200000 records converting from data table to csv in my local VM(Azure Cluster) server it's taken 36 seconds and after deployed to Azure server it's taken 1 min 20 sec ..

Can you please suggest on this

How to resolve this.

What I have tried:

StringBuilder stringBuilder = new StringBuilder();
// Only return Null if there is no structure.
if (dataTable.Columns.Count == 0)
return null;

foreach (object col in dataTable.Columns)
{
if (col == null)
stringBuilder.Append(",");
else
stringBuilder.Append("\"" + col.ToString().Replace(@"""", @"""""") + "\",");
}
stringBuilder.Replace(",", Environment.NewLine, stringBuilder.Length - 1, 1);
foreach (DataRow dr in dataTable.Rows)
{
foreach (object column in dr.ItemArray)
{
if (column == null)
stringBuilder.Append(",");
else
stringBuilder.Append("\"" + column.ToString().Replace(@"""", @"""""") + "\",");
}
stringBuilder.Replace(",", Environment.NewLine, stringBuilder.Length - 1, 1);
}
Posted
Updated 12-Nov-18 16:23pm
v2
Comments
MadMyche 12-Nov-18 13:01pm    
How about showing your code?
srinualluri 12-Nov-18 22:24pm    
StringBuilder stringBuilder = new StringBuilder();
// Only return Null if there is no structure.
if (dataTable.Columns.Count == 0)
return null;

foreach (object col in dataTable.Columns)
{
if (col == null)
stringBuilder.Append(",");
else
stringBuilder.Append("\"" + col.ToString().Replace(@"""", @"""""") + "\",");
}
stringBuilder.Replace(",", Environment.NewLine, stringBuilder.Length - 1, 1);
foreach (DataRow dr in dataTable.Rows)
{
foreach (object column in dr.ItemArray)
{
if (column == null)
stringBuilder.Append(",");
else
stringBuilder.Append("\"" + column.ToString().Replace(@"""", @"""""") + "\",");
}
stringBuilder.Replace(",", Environment.NewLine, stringBuilder.Length - 1, 1);
}
Maciej Los 12-Nov-18 14:59pm    
Suggest what?
srinualluri 12-Nov-18 22:26pm    
I am using above code for generating CSV file from datatable . in my local pc its taken 36 secs and after deployed to Development server its taken 1 Min 20 sec

Can you please suggest on this ..Please provide if required any code changes
F-ES Sitecore 13-Nov-18 6:06am    
Use a faster server.

Without the code or any idea of how you are doing that, we can have no idea how to help you - and you need to do some preparatory work before we could begin to help anyway.

This first thing you need to do is establish a baseline. Use the Stopwatch class[^] to time accurately the actual code, and do teh same job three or four times to get a good avaerage value. You now have a value to work from to evaluate any changes.

Now add more Stopwatch instances to narrow down which part(s) of the code are taking time, so you can concentrate on those. For example, if one loop takes 0.75 seconds and another takes 0.001, it's pointless looking at the second at all!
Continue adding Stopwatches until you have a solid base of data about where you code is slow, and it may be obvious what you need to do. If not, you know which section(s) to show us and explain just how slow it is ...

But the chances are the server is busy doing other things and your dev machine isn't.
 
Share this answer
 
Hi,
I totally agree with the solution that OrginalGriff provided and in addition, I recommend you to:

1- Read this article in order to have a clear understanding of the performance overhead of famous .Net collections/data structures. Large Collections in C# (Managed Code) - Part II[^].
2- Do not forget that if you run your code on none real-time operating system you will always end up in an uncertain situation especially when you deal with server-side performance. Thus, having a good performance logging mechanism to keep tracking your code execution time is critical to find the bottlenecks.

Cheers,
Aydin
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900