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

streamWriter.SetRow() Write large amount of data:out of memory,App crashes #590

Closed
robinsoon opened this issue Feb 28, 2020 · 4 comments
Closed
Labels
duplicate This issue or pull request already exists

Comments

@robinsoon
Copy link

robinsoon commented Feb 28, 2020

runtime: out of memory: cannot allocate 609738752-byte block (62750720 in use)
fatal error: out of memory

Write Excel data 1:647 columns and 25000 rows is OK, Write successfully !41,463ms 49.1MB
Write Excel data 2:647 columns and 25501 rows is OK, Write successfully !42,901ms 50.1MB
Maximum data limit of normal operation reached !
Write Excel data 3:647 columns and 32750 rows Error : out of memory!App crashes

--USE CASE ---------------------------------------------------
xlsx := excelize.NewFile()
sheetname := "exp" + rowcount
xlsx.SetSheetName("Sheet1", sheetname)
streamWriter, err := xlsx.NewStreamWriter(sheetname)

--FOR LOOP SET CELL VALUES---------------------------------------------------
scolindex = fmt.Sprintf("%s%d", "A", count+1)
streamWriter.SetRow(scolindex, vals)
--END -------------------------------------------------
// Special treatment to avoid crash   Add 2020.2.29 by Robin
if lenBuf > 16499147 || count*len(cols) >= 25501*647 {
	//达到15.7Mb 或 25501*647数据规模,中断写入
	fmt.Println("警告:", count, " ROWS>", scolindex, "数据流超长: ", lenBuf, "byte 激活运行时保护!")
	break
	}


streamWriter.Flush() 
err2 := xlsx.SaveAs(filename)
@robinsoon
Copy link
Author

robinsoon commented Feb 28, 2020

runtime: out of memory: cannot allocate 609738752-byte block (62750720 in use)
fatal error: out of memory

runtime stack:
runtime.throw(0x782e42, 0xd)
	D:/Productivity/Go/src/runtime/panic.go:774 +0x64
runtime.largeAlloc(0x2457cd0f, 0x440101, 0x3635010)
	D:/Productivity/Go/src/runtime/malloc.go:1140 +0x108
runtime.mallocgc.func1()
	D:/Productivity/Go/src/runtime/malloc.go:1033 +0x39
runtime.systemstack(0x1df0558)
	D:/Productivity/Go/src/runtime/asm_386.s:399 +0x53
runtime.mstart()
	D:/Productivity/Go/src/runtime/proc.go:1146

goroutine 9 [running]:
runtime.systemstack_switch()
	D:/Productivity/Go/src/runtime/asm_386.s:360 fp=0x13c39af0 sp=0x13c39aec pc=0x44e3c0
runtime.mallocgc(0x2457cd0f, 0x741b40, 0x1bf71c01, 0x1d5ee10)
	D:/Productivity/Go/src/runtime/malloc.go:1032 +0x684 fp=0x13c39b44 sp=0x13c39af0 pc=0x40b234
runtime.makeslice(0x741b40, 0x2457cd0f, 0x2457cd0f, 0xcc7a4265)
	D:/Productivity/Go/src/runtime/slice.go:49 +0x4f fp=0x13c39b58 sp=0x13c39b44 pc=0x43b7cf
bytes.makeSlice(0x2457cd0f, 0x0, 0x0, 0x0)
	D:/Productivity/Go/src/bytes/buffer.go:229 +0x69 fp=0x13c39b8c sp=0x13c39b58 pc=0x4bd3f9
bytes.(*Buffer).grow(0x13c39bd4, 0x2457cd0f, 0x0)
	D:/Productivity/Go/src/bytes/buffer.go:142 +0x11c fp=0x13c39bb4 sp=0x13c39b8c pc=0x4bcebc
bytes.(*Buffer).Grow(...)
	D:/Productivity/Go/src/bytes/buffer.go:161
github.com/360EntSecGroup-Skylar/excelize/v2.(*bufferedWriter).Bytes(0x13ee21c0, 0x13e20080, 0x1423e040, 0x18, 0x1, 0x1423e040)
	D:/PJ/Go/pkg/mod/github.com/360!ent!sec!group-!skylar/excelize/[email protected]/stream.go:465 +0x1ce fp=0x13c39bec sp=0x13c39bb4 pc=0x53a87e
github.com/360EntSecGroup-Skylar/excelize/v2.(*StreamWriter).Flush(0x13ee21b0, 0x0, 0x0)
	D:/PJ/Go/pkg/mod/github.com/360!ent!sec!group-!skylar/excelize/[email protected]/stream.go:387 +0x1a6 fp=0x13c39c58 sp=0x13c39bec pc=0x53a126
main.doExcel(0x13c76180, 0x13c1a237, 0x5d, 0x13c0eb66, 0x12, 0x0)
	D:/PJ/Go/src/dbQExpTool2/dbQExpTool2.go:640 +0x153f fp=0x13c39fd8 sp=0x13c39c58 pc=0x56631f
runtime.goexit()
	D:/Productivity/Go/src/runtime/asm_386.s:1325 +0x1 fp=0x13c39fdc sp=0x13c39fd8 pc=0x44fd21
created by main.main
	D:/PJ/Go/src/dbQExpTool2/dbQExpTool2.go:334 +0xff2

goroutine 1 [chan receive, locked to thread]:
main.main()
	D:/PJ/Go/src/dbQExpTool2/dbQExpTool2.go:336 +0x1021

goroutine 6 [syscall]:
github.com/andlabs/ui._Cfunc_uiMain()
	_cgo_gotypes.go:2516 +0x33
github.com/andlabs/ui.Main(0x79b9c4, 0x0, 0x0)
	D:/PJ/Go/pkg/mod/github.com/andlabs/[email protected]/main.go:41 +0xd0
main.openWindow()
	D:/PJ/Go/src/dbQExpTool2/dbQExpTool2.go:1055 +0x23
created by main.main
	D:/PJ/Go/src/dbQExpTool2/dbQExpTool2.go:69 +0x86

goroutine 7 [select]:
database/sql.(*DB).connectionOpener(0x13c76180, 0x7cbd60, 0x13c9e8e0)
	D:/Productivity/Go/src/database/sql/sql.go:1052 +0xa1
created by database/sql.OpenDB
	D:/Productivity/Go/src/database/sql/sql.go:722 +0x11e

goroutine 8 [select]:
database/sql.(*DB).connectionResetter(0x13c76180, 0x7cbd60, 0x13c9e8e0)
	D:/Productivity/Go/src/database/sql/sql.go:1065 +0xb1
created by database/sql.OpenDB
	D:/Productivity/Go/src/database/sql/sql.go:723 +0x14c

@robinsoon
Copy link
Author

robinsoon commented Feb 28, 2020

Add Run Logs:println()
————————————————————————————————
18000 ROWS> A18001 18 数据串流分段写入: 1000 ./1XLS_201801.xlsx
19000 ROWS> A19001 19 数据串流分段写入: 1000 ./1XLS_201801.xlsx
20000 ROWS> A20001 20 数据串流分段写入: 1000 ./1XLS_201801.xlsx
21000 ROWS> A21001 21 数据串流分段写入: 1000 ./1XLS_201801.xlsx
22000 ROWS> A22001 22 数据串流分段写入: 1000 ./1XLS_201801.xlsx
23000 ROWS> A23001 23 数据串流分段写入: 1000 ./1XLS_201801.xlsx
24000 ROWS> A24001 24 数据串流分段写入: 1000 ./1XLS_201801.xlsx
25000 ROWS> A25001 25 数据串流分段写入: 1000 ./1XLS_201801.xlsx
26000 ROWS> A26001 26 数据串流分段写入: 1000 ./1XLS_201801.xlsx
27000 ROWS> A27001 27 数据串流分段写入: 1000 ./1XLS_201801.xlsx
28000 ROWS> A28001 28 数据串流分段写入: 1000 ./1XLS_201801.xlsx
29000 ROWS> A29001 29 数据串流分段写入: 1000 ./1XLS_201801.xlsx
30000 ROWS> A30001 30 数据串流分段写入: 1000 ./1XLS_201801.xlsx
31000 ROWS> A31001 31 数据串流分段写入: 1000 ./1XLS_201801.xlsx
32000 ROWS> A32001 32 数据串流分段写入: 1000 ./1XLS_201801.xlsx
32750 ROWS> A32751 数据串流结束,保存 ./1XLS_201801.xlsx

runtime: out of memory: cannot allocate 609738752-byte block (62717952 in use)
fatal error: out of memory

@xuri xuri added the enhancement New feature or request label Feb 28, 2020
@robinsoon
Copy link
Author

robinsoon commented Feb 29, 2020

@xuri
Copy link
Member

xuri commented Mar 6, 2020

This issue similar to #487. I close this and merge it into issue #487 is still discussing this issue.

@xuri xuri closed this as completed Mar 6, 2020
@xuri xuri added duplicate This issue or pull request already exists and removed enhancement New feature or request labels Mar 6, 2020
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
Projects
None yet
Development

No branches or pull requests

2 participants