如何提高将 clob 数据写入文件的速度
我们使用 C# oracleDataReader 将数据从 Oracle 数据库提取到文件,我们使用多个线程,我发现读取除 clob 之外的数据非常快,比如 4 分钟读取 1 GB。但是当数据包含 clob 时,速度非常非常慢,即使是 12 MB 的 clob 数据也需要大约 3 个小时。
我尝试将缓冲区从 64 KB 增加到 5 MB。
请建议如何提高将 clob 写入文件的速度。
源代码
我们使用 2 个 ,其中 1 个用于实际 csv,1 个用于 clob。我们在 csv 文件中编写记录指针来代替 clob,并在 clob 文件中编写记录指针、clob 值。
else if (objVal is OracleClob)
{
OracleClob oraVal = (OracleClob)objVal;
if (oraVal.IsEmpty)
sw.Write("");
else
{
// using (StreamWriter writer = new StreamWriter(fileName, true))
{
Interlocked.Increment(ref recordPointer);
if (recordPointer == 1)
{
string fileName = outputFileName.Remove(outputFileName.LastIndexOf("."));
fileName = fileName + ".clobcsv";
clobWriter = new StreamWriter(fileName, true);
log.Info("CLOB data is found in this file " + outputFileName + " and clob data is stored in " + fileName + " file");
clobWriter.WriteLine("Id," + cols[i]);
}
StringBuilder sb = new StringBuilder("\"");
StringBuilder value = new StringBuilder();
value.Append(oraVal.Value);
//CsvEscape(value.ToString());
value.Replace("\"", "\"\"");
sb.Append(recordPointer);
sb.Append("\"");
sb.Append(delimiter);
sb.Append("\"");
//sb.Append(oraVal.Value.Replace("\"", "\"\""));
sb.Append(value);
value.Clear();
sb.Append("\"");
clobWriter.WriteLine(sb);
//clobWriter.WriteLine("\"" + recordPointer + "\"" + delimiter + "\"" + oraVal.Value.Replace("\"", "\"\"") + "\"");
}
sw.Write(recordPointer);
}
}
We are extracting data from an oracle database to a file using C# oracleDataReader, we are using multiple threads and I found that reading data other than clob is very fast say say 4 min for 1 GB. But when data contains clob it is very very slow, even a 12 MB clob data is taking some 3 hours.
I tried increasing the buffer from 64 KB to 5MB.
Please suggest how to increase the speed to write clob to a file.
Source code
we are using 2 files 1 for actual csv and 1 for clob. we write recordpointer in place of clob in csv file and in clob file we write recordpointer, clob value.
else if (objVal is OracleClob)
{
OracleClob oraVal = (OracleClob)objVal;
if (oraVal.IsEmpty)
sw.Write("");
else
{
// using (StreamWriter writer = new StreamWriter(fileName, true))
{
Interlocked.Increment(ref recordPointer);
if (recordPointer == 1)
{
string fileName = outputFileName.Remove(outputFileName.LastIndexOf("."));
fileName = fileName + ".clobcsv";
clobWriter = new StreamWriter(fileName, true);
log.Info("CLOB data is found in this file " + outputFileName + " and clob data is stored in " + fileName + " file");
clobWriter.WriteLine("Id," + cols[i]);
}
StringBuilder sb = new StringBuilder("\"");
StringBuilder value = new StringBuilder();
value.Append(oraVal.Value);
//CsvEscape(value.ToString());
value.Replace("\"", "\"\"");
sb.Append(recordPointer);
sb.Append("\"");
sb.Append(delimiter);
sb.Append("\"");
//sb.Append(oraVal.Value.Replace("\"", "\"\""));
sb.Append(value);
value.Clear();
sb.Append("\"");
clobWriter.WriteLine(sb);
//clobWriter.WriteLine("\"" + recordPointer + "\"" + delimiter + "\"" + oraVal.Value.Replace("\"", "\"\"") + "\"");
}
sw.Write(recordPointer);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可能需要考虑使用 Oracle 工具导出数据。执行文件 IO 的方法有很多种,其中一些方法可能比您正在执行的方法快得多。例如,我刚刚使用 dbms_xslprocessor.clob2file 在一台速度较慢的 PC 上用 16 秒写入了一个 12 MB 的 CLOB。 以下是部分选项列表.
You may want to consider using an Oracle tool for exporting data. There are a many ways to perform file IO, and some of them would probably be much faster than what you're doing. For example, I just used dbms_xslprocessor.clob2file to write a 12 MB CLOB in 16 seconds on a slow PC. Here's a partial list of options.
尝试将
LOBFetchSize
设置为 -1。http://www.stanford.edu /dept/itss/docs/oracle/10g/win.101/b10117/features003.htm
Try setting
LOBFetchSize
to -1.http://www.stanford.edu/dept/itss/docs/oracle/10g/win.101/b10117/features003.htm