Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to read data in batches?? #515

Closed
codedart2018 opened this issue Nov 11, 2019 · 5 comments
Closed

how to read data in batches?? #515

codedart2018 opened this issue Nov 11, 2019 · 5 comments
Labels
duplicate This issue or pull request already exists enhancement New feature or request

Comments

@codedart2018
Copy link

1c,2G sever reads 200000 excel,memory is full.

f.GetRows("Sheet1")
error:
fatal error: runtime: out of memory

i want to read the data in batches and return an array to me.

i really hope

row, err:=f.GetRows("Sheet1", 1000)

thank you all

@xuri
Copy link
Member

xuri commented Nov 21, 2019

Hi @codedart2018, thanks for your issue. I close this and merge it into issue #146 is still discussing this feature.

@xuri xuri closed this as completed Nov 21, 2019
@xuri xuri added duplicate This issue or pull request already exists enhancement New feature or request labels Nov 21, 2019
@xuri
Copy link
Member

xuri commented Nov 22, 2019

Hi @codedart2018, I have made the function GetRows and Rows read data as streaming. You can get all the data in the worksheet at once through GetRows, or read the data row by row using Rows and Next like this:

// read top 10 rows
rows, err := f.Rows("Sheet1")
if err != nil {
    fmt.Println(err)
    return
}
for rows.Next() {
    count++
    if count > 10 {
        break
    }
    row, _ := rows.Columns()
    for _, colCell := range row {
        fmt.Print(colCell, "\t")
    }
    fmt.Println()
}

@codedart2018
Copy link
Author

@xuri 旭日你好!这个方法我之前已经试过了!
在f.rows(“”)cpu拉满 内存就已经就爆
以下附点图
未启动服务前
1
启动服务后
1
目前我测试服务器是 1核2G,就算最终生产服务器4核8g我认为也会出现这个问题!真实我们可能一次性传30-50万数据到服务器上处理。如果多用户同一时间操作连续的cpu内存消耗 一样会导致cpu拉满 内存挤爆。

@xuri
Copy link
Member

xuri commented Nov 26, 2019

Hi @codedart2018, I have refactored the Rows function, please try to upgrade the library with the master branch code.

@codedart2018
Copy link
Author

think you! try on monday.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants