hannes / MonetDBLite

MonetDB reconfigured as a library
108 stars 10 forks source link

low RAM embedded vs external mserver behavior on linux #114

Open ajdamico opened 7 years ago

ajdamico commented 7 years ago

@hannesmuehleisen is this what you expect to happen on linux? seems to make sense given your malloc() explanation. thanks

on rocks010

needed installs:

# devtools::install_github( "hannesmuehleisen/MonetDBLite" )
# devtools::install_github( "krlmlr/ulimit" )

2.5gb ulimit external mserver. anything lower than that, mserver does not open

> ulimit -v 2500000
> R

library(DBI)
library(MonetDBLite)

dbdir <- tempdir()

startscript <- monetdb.server.setup(dbdir,"/usr/local/monetdb/", "mydb", 50000)
# monetdb path for me on rocks010 #
# startscript <- monetdb.server.setup(dbdir,"/export/scratch1/home/damico/MonetDB/bin/", "mydb", 50000)

pid <- monetdb.server.start(startscript)
con <- dbConnect(MonetDB.R(), "monetdb://localhost:50000/mydb" , wait = TRUE )

# 5,000 record tables, 100,000 times
for( i in seq( 100000 ) ) { cat( i , "\r\n" ) ; dbWriteTable( con , 'x' , mtcars[ rep( 1:10 , 500 ) , ] , append = TRUE ) }

    # 2048
    # 2049
    # 2050
    # 2051
    # Error in .local(conn, statement, ...) :
      # Unable to execute statement 'COMMIT'.
    # Server says 'ERROR: MT_mremap: mremap(0x7ff9fc850000,82051072,98500608) failed' [#GDKerror:].
    # >
    # > traceback()
    # 9: stop("Unable to execute statement '", statement, "'.\nServer says '",
           # errmsg, "' [#", errno, "].")
    # 8: .local(conn, statement, ...)
    # 7: dbSendQuery(conn, "COMMIT")
    # 6: dbSendQuery(conn, "COMMIT")
    # 5: dbCommit(conn)
    # 4: dbCommit(conn)
    # 3: .local(conn, name, value, ...)
    # 2: dbWriteTable(con, "x", mtcars[rep(1:10, 500), ], append = TRUE)
    # 1: dbWriteTable(con, "x", mtcars[rep(1:10, 500), ], append = TRUE) at #1
    # >

    # 2050
    # 2051
    # Error in .local(conn, statement, ...) :
      # Unable to execute statement 'COMMIT'.
    # Server says 'ERROR: MT_mremap: mremap(0x7f7aeee00000,82051072,98500608) failed' [#GDKerror:].
    # >

2.5gb ulimit embedded mserver: does not pass i=1800

> ulimit -v 2500000
> R

library(DBI)
library(MonetDBLite)

dbdir <- tempdir()

con <- dbConnect(MonetDBLite(), dbdir )

# 5,000 record tables, 100,000 times
for( i in seq( 100000 ) ) { cat( i , "\r\n" ) ; dbWriteTable( con , 'x' , mtcars[ rep( 1:10 , 500 ) , ] , append = TRUE ) }

    # 1708
    # 1709
    # Error in .local(conn, name, value, ...) :
      # Failed to insert data: MALException:embedded:Could not convert column 9 gear to type 9
    # > traceback()
    # 4: stop("Failed to insert data: ", insres)
    # 3: .local(conn, name, value, ...)
    # 2: dbWriteTable(con, "x", mtcars[rep(1:10, 500), ], append = TRUE)
    # 1: dbWriteTable(con, "x", mtcars[rep(1:10, 500), ], append = TRUE) at #1
    # >

    # 1702
    # 1703
    # Error in .local(conn, statement, ...) :
      # Unable to execute statement 'select schemas.name as sn, tables.name as tn from sys.tables join sys.schemas on tables.schema_id=sc...'.
    # Server says 'GDKerror:!ERROR: GDKreallocmax: failed for 40016 bytes !ERROR: MT_mmap: mmap(/tmp/Rtmp5mtmJx/bat/05/40/54061.tail,65536) failed !OS: Cannot allocate memory !ERROR: GDKmallocmax: failed for 40000 bytes !ERROR: GDKmallocmax: failed for 40000 bytes !ERROR: HEAPextend: failed to extend to 40000 for 05/40/54061.tail: h->storage == STORE_MEM && can_map && fd >= 0 && HEAPload_intern() != GDK_SUCCEED !ERROR: GDKreallocmax: failed for 40016 bytes !ERROR: MT_mmap: mmap(/tmp/Rtmp5mtmJx/bat/05/40/54062.tail,65536) failed !OS: Cannot allocate memory !ERROR: GDKmallocmax: failed for 40000 bytes !ERROR: GDKmallocmax: failed for 40000 bytes !ERROR: HEAPextend: failed to extend to 40000 for 05/40/54062.tail: h->storage == STORE_MEM && can_map && fd >= 0 && HEAPload_intern() != GDK_SUCCEED '.
    # >

    # 1421
    # 1422
    # 1423
    # 1424
    # 1425
    # 1426
    # Error in .local(conn, statement, ...) :
      # Unable to execute statement 'select schemas.name as sn, tables.name as tn from sys.tables join sys.schemas on tables.schema_id=sc...'.
    # Server says 'GDKerror:!ERROR: MT_mremap: mremap(0x7f169cc80000,57016320,68419584) failed !OS: Cannot allocate memory !ERROR: HEAPextend: failed to extend to 68419584 for 03/346.tail: GDKmremap() failed '.
    # > traceback()
    # 14: stop("Unable to execute statement '", statement, "'.\nServer says '",
            # env$message, "'.")
    # 13: .local(conn, statement, ...)
    # 12: dbSendQuery(conn, statement, ...)
    # 11: dbSendQuery(conn, statement, ...)
    # 10: dbGetQuery(conn, q)
    # 9: dbGetQuery(conn, q)
    # 8: .local(conn, ...)
    # 7: dbListTables(conn, sys_tables = T)
    # 6: dbListTables(conn, sys_tables = T)
    # 5: dbExistsTable(conn, qname)
    # 4: dbExistsTable(conn, qname)
    # 3: .local(conn, name, value, ...)
    # 2: dbWriteTable(con, "x", mtcars[rep(1:10, 500), ], append = TRUE)
    # 1: dbWriteTable(con, "x", mtcars[rep(1:10, 500), ], append = TRUE) at #1
    # >

random strangeness enforcing ulimit with library(ulimit) rather than ulimit -v

300mb embedded lite error

# out of memory (error, not crash)
library(DBI)
ulimit::memory_limit( 300 )
db <- dbConnect( MonetDBLite::MonetDBLite() )
for( i in seq( 1000 ) ) { cat( i , "\r\n" ) ; dbWriteTable( db , 'x' , mtcars , append = TRUE ) }
    # Error in .local(conn, statement, ...) :
      # Unable to execute statement 'select schemas.name as sn, tables.name as tn from sys.tables join sys.schemas on tables.schema_id=sc...'.
    # Server says 'MALException:bat.new:GDK reported error. !ERROR: GDKmallocmax: failed for 10240 bytes !ERROR: GDKmallocmax: failed for 40 bytes !ERROR: GDKmallocmax: failed for 40 bytes !ERROR: HEAPalloc: Insufficient space for HEAP of 10240 bytes. '.

200mb embedded lite crash

# segfault (crash)
library(DBI)
ulimit::memory_limit( 200 )
db <- dbConnect( MonetDBLite::MonetDBLite() )
 # *** caught segfault ***
# address 0x6498, cause 'memory not mapped'

# Traceback:
 # 1: .Call("monetdb_startup_R", dir, quiet, getOption("monetdb.squential",     sequential), PACKAGE = libfilename)
 # 2: monetdb_embedded_startup(embedded, !getOption("monetdb.debug.embedded",     FALSE), getOption("monetdb.sequential", FALSE))
 # 3: .local(drv, ...)
 # 4: dbConnect(MonetDBLite::MonetDBLite())
 # 5: dbConnect(MonetDBLite::MonetDBLite())

# Possible actions:
# 1: abort (with core dump, if enabled)
# 2: normal R exit
# 3: exit R without saving workspace
# 4: exit R saving workspace
# Selection:
# Selection:
hannes commented 7 years ago

Ok if it throws an error thats fine by me. It should not crash however.

ajdamico commented 7 years ago

thanks. i'll hold onto this issue and keep thinking, and write a similar one for windows. opening separate issue for you for the crash

hannes commented 7 years ago

still an issue? there have been various checks added to monetdb to avoid this.