0

我正在编写一个查询以向表中插入 300k 行,在执行插入期间我收到 404 File or Directory not found 错误。我是天蓝色的菜鸟,所以我可能写了一些愚蠢的代码

我在这里创建 DynamicTableEntity 对象:

       Test t = new Test();
       t.CreateTable("table2");
        Dictionary<string, EntityProperty> dic;
        Random random = new Random();

        ArrayList part1 = new ArrayList();
        ArrayList part2 = new ArrayList();
        ArrayList part3 = new ArrayList();
        ArrayList part4 = new ArrayList();
        ArrayList part5 = new ArrayList();
        ArrayList part6 = new ArrayList();
        DynamicTableEntity dte;
        Stopwatch sw = new Stopwatch();
        Guid guid;
        sw.Start();
        for (int i = 0; i < 300000; i++)
        {

            dic = new Dictionary<string, EntityProperty>();

            dic.Add("count", new EntityProperty(i));
            dic.Add("rand1", new EntityProperty(random.Next()));
            dic.Add("rand2", new EntityProperty(random.Next()));
            dic.Add("rand3", new EntityProperty(random.Next()));
            if(i!=5)
            dic.Add("rand4", new EntityProperty(random.Next()));
            else
                dic.Add("rand4", new EntityProperty(1234561));


            if (i % 2 == 0)

                dic.Add("randInt", new EntityProperty(random.Next()));
            else
                dic.Add("String", new EntityProperty("This is a string" + i));

            guid = Guid.NewGuid();

            dte = new DynamicTableEntity("0" + (i % 3), DateTime.UtcNow.Ticks.ToString() + guid + i);

            dte.Properties = dic;

            if (i % 6 == 0)
                part1.Add(dte);
            else if (i % 6 == 1)
                part2.Add(dte);
            else if(i%6==2)
                part3.Add(dte);
            else if (i % 6 == 3)
                part4.Add(dte);
            else if (i % 6 == 4)
                part5.Add(dte);
            else if (i % 6 == 5)
                part6.Add(dte);


            if( (i + 1) % 600 == 0)
            {

                t.Insert("table2", part1, part2, part3, part4, part5, part6);
                part1.RemoveRange(0,100 );
                part2.RemoveRange(0, 100);
                part3.RemoveRange(0, 100);
                part4.RemoveRange(0, 100);
                part5.RemoveRange(0, 100);
                part6.RemoveRange(0, 100);
            }



        }

这是插入执行代码:

        CloudTable table = _tableClient.GetTableReference(tableName);
        TableBatchOperation tablebatchoperation;
        int i = 0, j = 0;
        if (created == false)
            table.CreateIfNotExists();

        foreach (ArrayList k in l)
        {
            tablebatchoperation = new TableBatchOperation();

            foreach (DynamicTableEntity dte in k)
            {
                tablebatchoperation.Insert(dte);
            }
            table.ExecuteBatch(tablebatchoperation);
        }

我感谢您的帮助

4

2 回答 2

1

我在这里看到的一个可能问题是您正在执行一个包含 100 多个项目的批处理操作。尝试这样的事情(代码没有优化,但你会得到图片):

    foreach (ArrayList k in l)
    {
        foreach (DynamicTableEntity dte in k)
        {
            if (tablebatchoperation == null)
               tablebatchoperation = new TableBatchOperation();
            tablebatchoperation.Insert(dte);
            if (tablebatchoperation.Count == 100)
            {
               table.ExecuteBatch(tablebatchoperation);
               tablebatchoperation = new TableBatchOperation();
            }
        }
    }

    if (tablebatchoperation.Count > 0)
        table.ExecuteBatch(tablebatchoperation);

另请记住,单个批处理操作中的所有实体都应属于同一分区。你在哪里设置分区和行键?

于 2013-01-02T07:40:27.693 回答
0

如果您查看以下问题,您可能会找到您需要的内容。这也是关于在插入方面实现出色的性能:如何使用 Azure 表存储实现每秒 10 次以上的插入

于 2013-01-01T23:11:59.420 回答