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

High memory usage in getting s2 cell covering #79

Open
shubh0508 opened this issue Aug 13, 2021 · 3 comments
Open

High memory usage in getting s2 cell covering #79

shubh0508 opened this issue Aug 13, 2021 · 3 comments

Comments

@shubh0508
Copy link

shubh0508 commented Aug 13, 2021

Hello there!!

I have a use case, where I need to convert 2D polygons to S2 cells.
For some polygons, I am observing very high memory usage(~20GB) or so.
I am fetching cells with levels between 10 to 15 for a small region(<1Km^2 or so).

After creating RegionCoverer for a polygon, I am using CellUnion function call to get the cell covering of the given polygon.
On checking the issue, I found that the length of RegionCoverer PriorityQueue containing intersecting or concerning cells keeps increasing.

High memory usage leads to the docker container getting killed in my application.
Can someone please help me with this?

Example geoJSON of one of the polygons:
"""{
"type": "Polygon",
"coordinates": [
[
[
55.491351226746794,
25.421007109833486
],
[
55.493892523236426,
25.42236515986828
],
[
55.493006607451655,
25.421891733268737
],
[
55.49234900420578,
25.421906989899732
],
[
55.491351226746794,
25.421007109833486
]
]
]
}"""

@shubh0508
Copy link
Author

shubh0508 commented Aug 13, 2021

On observing the length of the Priority queue for around 100K polygons, I found that its max value for a polygon was less than 1000 for almost all the polygons, except the ones which were having memory issues.

For polygons that were having issues, the maximum length of the Priority queue went up to 1,5000,000 and higher, thus causing memory issues.

@shubh0508
Copy link
Author

shubh0508 commented Aug 13, 2021

Sample Code snippet for the idea(not working):
"""
cellUnion := s2.CellUnion{}
cu, err := getCellUnionForPolygon(polygon, minCellLevel, maxCellLevel, maxNumCells)
if !err.IsNil() {
fmt.Println("err: ", err)
}
cellUnion = s2.CellUnionFromUnion(cellUnion, cu)

// divide all merged cells to minCellLevel
cellUnion.Denormalize(minCellLevel, 0)

// convert []cellID to []unit64
cellIDs := make([]uint64, 0)
for _, cellID := range cellUnion {
cellIDs = append(cellIDs, uint64(cellID))
}
fmt.Println("cell_ids", cellIDs)

func getCellUnionForPolygon(polygon [][][]float64, minCellLevel int, maxCellLevel int, maxNumCells int) (s2.CellUnion) {

if minCellLevel > maxCellLevel {
	temp := maxCellLevel
	maxCellLevel = minCellLevel
	minCellLevel = temp
}

region, err := getS2RegionForPolygon(polygon)
if !err.IsNil() {
	return nil
}
rc := &s2.RegionCoverer{MaxLevel: maxCellLevel, MinLevel: minCellLevel, MaxCells: maxNumCells}
cellUnion := rc.Covering(region)
return cellUnion

}

"""

@luchenedu
Copy link

Found same problem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants