Got System.OutOfMemoryException when migration big data
Hi,
We're currently trying to migrate some external data to our Umbraco8 website, we used contentService to achieve that, but we had some issues in the migration and we couldn't migrate all the data.
We use this code to migrate:
public class MigrationController : SurfaceController
{
public void CreateNode()
{
IMediaService ms = Services.MediaService;
IContentService contentService = Services.ContentService;
string imagePath = "C:\\Users\\Admin\\Desktop\\Galaxy.jpg";
string imageName = Path.GetFileName(imagePath);
var imagesNode = Umbraco.Content(1063);
List<string> mediaUDIS = new List<string>(1);
var parentUDI = new GuidUdi("images", imagesNode.Key);
for (int j = 0; j < 270000; j++)
{
var contentTypeBaseServiceProvider = Services.ContentTypeBaseServices;
IMedia mediaFile = ms.CreateMedia(imageName, 1057, "Image");
using (var fs = new FileStream(imagePath, FileMode.Open))
{
string nodeName = Path.GetFileName(imagePath) + j.ToString();
mediaFile.SetValue(contentTypeBaseServiceProvider, "umbracoFile", imageName, fs);
mediaUDIS.Add(mediaFile.GetUdi().ToString());
ms.Save(mediaFile);
IContent content = contentService.CreateContent(nodeName, parentUDI, "imageItem");
content.SetValue("images", string.Join(",", mediaUDIS.Select(i => i.ToString())).Trim(new char[] { ' ', ',' }));
content.SetValue("text", "Lorem Ipsum is simply dummy text of the printing and typesetting industry.");
contentService.SaveAndPublish(content);
mediaFile = null;
mediaUDIS.Clear();
}
}
}
}
We got this exception :
> $exception {{System.ArgumentOutOfRangeException: capacity was
less than the current size.
> Parameter name: requiredLength
at System.Text.StringBuilder.ExpandByABlock(Int32 minBlockCharCount)
at System.Text.StringBuilder.Append(Char value, Int32 repeatCount)
at System.Text.StringBuilder.Append(Char value)
at System.Text.StringBuilder.AppendFormatHelper(IFormatProvider
provider, String format,
ParamsArray args)
at System.String.FormatHelper(IFormatProvider provider, String format,
ParamsArray args)
at System.String.Format(IFormatProvider provider, String format,
Object[] args)
at System.Environment.GetResourceString(String key, Object[] values)
at System.Exception.get_Message()}} System.OutOfMemoryException
Here is a snapshot of memory usage we have taken after we got the exception :
We noticed that the memory usage of the SQL server is extremely high as shown below :
Also we noticed that the Examine files (internal&external) have become 6GB and the Nucache file: 1.3GB
Please advice in this matter of the best practices in migrating data..
Got System.OutOfMemoryException when migration big data
Hi,
We're currently trying to migrate some external data to our Umbraco8 website, we used contentService to achieve that, but we had some issues in the migration and we couldn't migrate all the data.
We use this code to migrate:
We got this exception :
Here is a snapshot of memory usage we have taken after we got the exception :
We noticed that the memory usage of the SQL server is extremely high as shown below :
Also we noticed that the Examine files (internal&external) have become 6GB and the Nucache file: 1.3GB
Please advice in this matter of the best practices in migrating data..
I'm curious, how many nodes were you able to create before the exception happened?
We have almost 70,000 nodes created before the exception happened
is working on a reply...