在数组(10)中拆分列表(字符串) [英] Splitting List(Of String) In Array(10)

查看:63
本文介绍了在数组(10)中拆分列表(字符串)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我一直在努力尝试将大约200,000个List(Of Strings)的列表拆分成均匀分割的数组以进行线程处理。



用户指定线程数(显然上限)以确定其机器的最佳处理速度。



如果我输出记录在主列表中:(忽略了周围的代码)

Hi
I have been struggling to try and split a list of approx 200,000 List(Of Strings) into evenly split arrays for thread processing.

The user is specifying the number of threads (capped obviously) to determine best processing speed for their machine.

If i output the records in the main list: (left out surrounding code)

Console.Write(SQLStrings.Count)



它给了我


It Gives me

Preperation of SQL Now Complete: 183096 Records to Process



当我跑以下代码给出了以下代码:




Yet When i run the below code it gives me the following:

Pool: 18311
Pool: 18311
Pool: 18311
Pool: 18311
Pool: 18311
Pool: 18311
Pool: 18311
Pool: 18311
Pool: 18311
Pool: 18297





总计为18309 7 这是1条记录,并为我的生活我无法弄清楚为什么我结束了(尝试了几个d ifferent循环并且我一直得到相同的结果。



是否有更多结构方法将List(Of String)拆分为Array(10)以便均衡平衡因为这些将进入线程池进行处理。



原因是它目前的处理速度比它应该慢得多,所以我调整了可能达到1mil记录的记录插入(数据)从几个来源收集)在一个连接上需要相当长的时间。







The Total of which is 183097 which is 1 records over, and for the life of me i cannot figure out why i am 1 over (tried several different loops and i keep getting the same result.

Is there a more structure way of splitting a List(Of String) into Array(10) for example to evenly balance it out as these will go into a thread pool for processing.

The reason for this is that is it currently processing much slower than it should be so i am tweaking the insertion of the records which could be up to 1mil records (data gathering from several sources) takes quite some time on a single connection.


'Instantiate Pools
        Dim ThreadPoolSql(MaxThreadPoolSize - 1) As List(Of String)
        For tmp As Integer = 0 To MaxThreadPoolSize - 1
            ThreadPoolSql(tmp) = New List(Of String)
        Next

        Dim PerPoolCount As Integer = SQLStrings.Count / MaxThreadPoolSize + 1
        Dim RunningLoop As Integer = 0, RunningCount As Integer = 0
        For ListItm As Integer = 0 To SQLStrings.Count - 1
            'Add SqlString to ThreadPool List
            ThreadPoolSql(RunningLoop).Add(SQLStrings(ListItm))

            'Incrememnt Run Counter
            RunningCount += 1

            If (RunningCount = PerPoolCount) Then
                RunningLoop += 1
                RunningCount = 0
            End If
        Next

推荐答案

在最后一次代码更改后,值已更改,它曾经是8,我没有意识到它已更改。
Value changed after the last code change, it used to be 8 and i didnt realise it had changed.


这篇关于在数组(10)中拆分列表(字符串)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆