removed inlines from benchmark.factor
added call( and execute( statements to make code compiledb4
parent
e9551ab78e
commit
449f677ad8
|
@ -1,6 +1,7 @@
|
||||||
USING: calendar math fry kernel assocs math.ranges bson.reader io.streams.byte-array
|
USING: calendar math fry kernel assocs math.ranges bson.reader io.streams.byte-array
|
||||||
sequences formatting combinators namespaces io tools.time prettyprint io.encodings.binary
|
sequences formatting combinators namespaces io tools.time prettyprint io.encodings.binary
|
||||||
accessors words mongodb.driver strings math.parser tools.walker bson.writer ;
|
accessors words mongodb.driver strings math.parser tools.walker bson.writer
|
||||||
|
tools.continuations ;
|
||||||
|
|
||||||
IN: mongodb.benchmark
|
IN: mongodb.benchmark
|
||||||
|
|
||||||
|
@ -106,25 +107,25 @@ CONSTANT: DOC-LARGE H{ { "base_url" "http://www.example.com/test-me" }
|
||||||
: set-doc ( name -- )
|
: set-doc ( name -- )
|
||||||
[ result ] dip '[ _ >>doc ] change ; inline
|
[ result ] dip '[ _ >>doc ] change ; inline
|
||||||
|
|
||||||
: small-doc ( -- )
|
: small-doc ( -- quot )
|
||||||
"small" set-doc ; inline
|
"small" set-doc [ ] ; inline
|
||||||
|
|
||||||
: medium-doc ( -- )
|
: medium-doc ( -- quot )
|
||||||
"medium" set-doc ; inline
|
"medium" set-doc [ ] ; inline
|
||||||
|
|
||||||
: large-doc ( -- )
|
: large-doc ( -- quot )
|
||||||
"large" set-doc ; inline
|
"large" set-doc [ ] ; inline
|
||||||
|
|
||||||
: small-doc-prepare ( -- quot: ( i -- doc ) )
|
: small-doc-prepare ( -- quot: ( i -- doc ) )
|
||||||
small-doc
|
small-doc drop
|
||||||
'[ "x" DOC-SMALL clone [ set-at ] keep ] ; inline
|
'[ "x" DOC-SMALL clone [ set-at ] keep ] ;
|
||||||
|
|
||||||
: medium-doc-prepare ( -- quot: ( i -- doc ) )
|
: medium-doc-prepare ( -- quot: ( i -- doc ) )
|
||||||
medium-doc
|
medium-doc drop
|
||||||
'[ "x" DOC-MEDIUM clone [ set-at ] keep ] ; inline
|
'[ "x" DOC-MEDIUM clone [ set-at ] keep ] ;
|
||||||
|
|
||||||
: large-doc-prepare ( -- quot: ( i -- doc ) )
|
: large-doc-prepare ( -- quot: ( i -- doc ) )
|
||||||
large-doc
|
large-doc drop
|
||||||
[ "x" DOC-LARGE clone [ set-at ] keep
|
[ "x" DOC-LARGE clone [ set-at ] keep
|
||||||
[ now "access-time" ] dip
|
[ now "access-time" ] dip
|
||||||
[ set-at ] keep ] ;
|
[ set-at ] keep ] ;
|
||||||
|
@ -132,17 +133,17 @@ CONSTANT: DOC-LARGE H{ { "base_url" "http://www.example.com/test-me" }
|
||||||
: (insert) ( quot: ( i -- doc ) collection -- )
|
: (insert) ( quot: ( i -- doc ) collection -- )
|
||||||
[ trial-size ] 2dip
|
[ trial-size ] 2dip
|
||||||
'[ _ call( i -- doc ) [ _ ] dip
|
'[ _ call( i -- doc ) [ _ ] dip
|
||||||
result get lasterror>> [ save ] [ save-unsafe ] if ] each-integer ; inline
|
result get lasterror>> [ save ] [ save-unsafe ] if ] each-integer ;
|
||||||
|
|
||||||
: (prepare-batch) ( i b quot: ( i -- doc ) -- batch-seq )
|
: (prepare-batch) ( i b quot: ( i -- doc ) -- batch-seq )
|
||||||
[ [ * ] keep 1 range boa ] dip
|
[ [ * ] keep 1 range boa ] dip
|
||||||
'[ _ call( i -- doc ) ] map ; inline
|
'[ _ call( i -- doc ) ] map ;
|
||||||
|
|
||||||
: (insert-batch) ( quot: ( i -- doc ) collection -- )
|
: (insert-batch) ( quot: ( i -- doc ) collection -- )
|
||||||
[ trial-size batch-size [ / ] keep ] 2dip
|
[ trial-size batch-size [ / ] keep ] 2dip
|
||||||
'[ _ _ (prepare-batch) [ _ ] dip
|
'[ _ _ (prepare-batch) [ _ ] dip
|
||||||
result get lasterror>> [ save ] [ save-unsafe ] if
|
result get lasterror>> [ save ] [ save-unsafe ] if
|
||||||
] each-integer ; inline
|
] each-integer ;
|
||||||
|
|
||||||
: bchar ( boolean -- char )
|
: bchar ( boolean -- char )
|
||||||
[ "t" ] [ "f" ] if ; inline
|
[ "t" ] [ "f" ] if ; inline
|
||||||
|
@ -152,16 +153,16 @@ CONSTANT: DOC-LARGE H{ { "base_url" "http://www.example.com/test-me" }
|
||||||
result get doc>>
|
result get doc>>
|
||||||
result get index>> bchar
|
result get index>> bchar
|
||||||
"%s-%s-%s" sprintf
|
"%s-%s-%s" sprintf
|
||||||
[ [ result get ] dip >>collection drop ] keep ; inline
|
[ [ result get ] dip >>collection drop ] keep ;
|
||||||
|
|
||||||
: prepare-collection ( -- collection )
|
: prepare-collection ( -- collection )
|
||||||
collection-name
|
collection-name
|
||||||
[ "_x_idx" drop-index ] keep
|
[ "_x_idx" drop-index ] keep
|
||||||
[ drop-collection ] keep
|
[ drop-collection ] keep
|
||||||
[ create-collection ] keep ; inline
|
[ create-collection ] keep ;
|
||||||
|
|
||||||
: prepare-index ( collection -- )
|
: prepare-index ( collection -- )
|
||||||
"_x_idx" H{ { "x" 1 } } ensure-index ; inline
|
"_x_idx" H{ { "x" 1 } } ensure-index ;
|
||||||
|
|
||||||
: insert ( doc-quot: ( i -- doc ) -- quot: ( -- ) )
|
: insert ( doc-quot: ( i -- doc ) -- quot: ( -- ) )
|
||||||
prepare-collection
|
prepare-collection
|
||||||
|
@ -170,14 +171,14 @@ CONSTANT: DOC-LARGE H{ { "base_url" "http://www.example.com/test-me" }
|
||||||
[ '[ _ _ (insert-batch) ] ] [ '[ _ _ (insert) ] ] if ;
|
[ '[ _ _ (insert-batch) ] ] [ '[ _ _ (insert) ] ] if ;
|
||||||
|
|
||||||
: serialize ( doc-quot: ( i -- doc ) -- quot: ( -- ) )
|
: serialize ( doc-quot: ( i -- doc ) -- quot: ( -- ) )
|
||||||
'[ trial-size [ _ call( i -- doc ) assoc>bv drop ] each-integer ] ; inline
|
'[ trial-size [ _ call( i -- doc ) assoc>bv drop ] each-integer ] ;
|
||||||
|
|
||||||
: deserialize ( doc-quot: ( i -- doc ) -- quot: ( -- ) )
|
: deserialize ( doc-quot: ( i -- doc ) -- quot: ( -- ) )
|
||||||
[ 0 ] dip call( i -- doc ) assoc>bv
|
[ 0 ] dip call( i -- doc ) assoc>bv
|
||||||
'[ trial-size [ _ binary [ H{ } stream>assoc 2drop ] with-byte-reader ] times ] ; inline
|
'[ trial-size [ _ binary [ H{ } stream>assoc 2drop ] with-byte-reader ] times ] ;
|
||||||
|
|
||||||
: check-for-key ( assoc key -- )
|
: check-for-key ( assoc key -- )
|
||||||
CHECK-KEY [ swap key? [ "ups... where's the key" throw ] unless ] [ 2drop ] if ; inline
|
CHECK-KEY [ swap key? [ "ups... where's the key" throw ] unless ] [ 2drop ] if ;
|
||||||
|
|
||||||
: (check-find-result) ( result -- )
|
: (check-find-result) ( result -- )
|
||||||
"x" check-for-key ; inline
|
"x" check-for-key ; inline
|
||||||
|
@ -185,24 +186,28 @@ CONSTANT: DOC-LARGE H{ { "base_url" "http://www.example.com/test-me" }
|
||||||
: (find) ( cursor -- )
|
: (find) ( cursor -- )
|
||||||
[ find [ (check-find-result) ] each (find) ] when* ; inline recursive
|
[ find [ (check-find-result) ] each (find) ] when* ; inline recursive
|
||||||
|
|
||||||
: find-one ( -- quot: ( -- ) )
|
: find-one ( quot -- quot: ( -- ) )
|
||||||
|
drop
|
||||||
[ trial-size
|
[ trial-size
|
||||||
collection-name
|
collection-name
|
||||||
trial-size 2 / "x" H{ } clone [ set-at ] keep
|
trial-size 2 / "x" H{ } clone [ set-at ] keep
|
||||||
'[ _ _ <query> 1 limit (find) ] times ] ;
|
'[ _ _ <query> 1 limit (find) ] times ] ;
|
||||||
|
|
||||||
: find-all ( -- quot: ( -- ) )
|
: find-all ( quot -- quot: ( -- ) )
|
||||||
|
drop
|
||||||
collection-name
|
collection-name
|
||||||
H{ } clone
|
H{ } clone
|
||||||
'[ _ _ <query> (find) ] ;
|
'[ _ _ <query> (find) ] ;
|
||||||
|
|
||||||
: find-range ( -- quot: ( -- ) )
|
: find-range ( quot -- quot: ( -- ) )
|
||||||
|
break
|
||||||
|
drop
|
||||||
[ trial-size batch-size /i
|
[ trial-size batch-size /i
|
||||||
collection-name
|
collection-name
|
||||||
trial-size 2 / "$gt" H{ } clone [ set-at ] keep
|
trial-size 2 / "$gt" H{ } clone [ set-at ] keep
|
||||||
[ trial-size 2 / batch-size + "$lt" ] dip [ set-at ] keep
|
[ trial-size 2 / batch-size + "$lt" ] dip [ set-at ] keep
|
||||||
"x" H{ } clone [ set-at ] keep
|
"x" H{ } clone [ set-at ] keep
|
||||||
'[ _ _ <query> find [ "x" check-for-key ] each drop ] times ] ;
|
'[ _ _ <query> (find) ] times ] ;
|
||||||
|
|
||||||
: batch ( -- )
|
: batch ( -- )
|
||||||
result [ t >>batch ] change ; inline
|
result [ t >>batch ] change ; inline
|
||||||
|
@ -221,7 +226,7 @@ CONSTANT: DOC-LARGE H{ { "base_url" "http://www.example.com/test-me" }
|
||||||
trial-size ] dip
|
trial-size ] dip
|
||||||
1000000 / /i
|
1000000 / /i
|
||||||
"%-18s: {batch:%s,index:%s;errchk:%s} %10s docs/s"
|
"%-18s: {batch:%s,index:%s;errchk:%s} %10s docs/s"
|
||||||
sprintf print flush ; inline
|
sprintf print flush ;
|
||||||
|
|
||||||
: print-separator ( -- )
|
: print-separator ( -- )
|
||||||
"----------------------------------------------------------------" print flush ; inline
|
"----------------------------------------------------------------" print flush ; inline
|
||||||
|
@ -236,45 +241,44 @@ CONSTANT: DOC-LARGE H{ { "base_url" "http://www.example.com/test-me" }
|
||||||
sprintf print flush
|
sprintf print flush
|
||||||
print-separator-bold ;
|
print-separator-bold ;
|
||||||
|
|
||||||
: with-result ( quot: ( -- ) -- )
|
: with-result ( options quot -- )
|
||||||
[ <result> ] prepose
|
'[ <result> _ call( options -- time ) print-result ] with-scope ;
|
||||||
[ print-result ] compose with-scope ; inline
|
|
||||||
|
|
||||||
: [bench-quot] ( feat-seq op-word -- quot: ( doc-word -- ) )
|
: [bench-quot] ( feat-seq op-word -- quot: ( doc-word -- ) )
|
||||||
'[ _ swap _
|
'[ _ swap _
|
||||||
'[ [ [ _ execute( -- quot: ( i -- doc ) ) ] dip
|
'[ [ [ _ execute( -- quot ) ] dip
|
||||||
[ execute( -- ) ] each _ execute( -- quot: ( -- ) ) benchmark ] with-result ] each
|
[ execute( -- ) ] each _ execute( quot -- quot ) benchmark ] with-result ] each
|
||||||
print-separator ] ; inline
|
print-separator ] ;
|
||||||
|
|
||||||
: run-serialization-bench ( doc-word-seq feat-seq -- )
|
: run-serialization-bench ( doc-word-seq feat-seq -- )
|
||||||
"Serialization Tests" print
|
"Serialization Tests" print
|
||||||
print-separator-bold
|
print-separator-bold
|
||||||
\ serialize [bench-quot] each ; inline
|
\ serialize [bench-quot] '[ _ call( doc-word -- ) ] each ;
|
||||||
|
|
||||||
: run-deserialization-bench ( doc-word-seq feat-seq -- )
|
: run-deserialization-bench ( doc-word-seq feat-seq -- )
|
||||||
"Deserialization Tests" print
|
"Deserialization Tests" print
|
||||||
print-separator-bold
|
print-separator-bold
|
||||||
\ deserialize [bench-quot] each ; inline
|
\ deserialize [bench-quot] '[ _ call( doc-word -- ) ] each ;
|
||||||
|
|
||||||
: run-insert-bench ( doc-word-seq feat-seq -- )
|
: run-insert-bench ( doc-word-seq feat-seq -- )
|
||||||
"Insert Tests" print
|
"Insert Tests" print
|
||||||
print-separator-bold
|
print-separator-bold
|
||||||
\ insert [bench-quot] each ; inline
|
\ insert [bench-quot] '[ _ call( doc-word -- ) ] each ;
|
||||||
|
|
||||||
: run-find-one-bench ( doc-word-seq feat-seq -- )
|
: run-find-one-bench ( doc-word-seq feat-seq -- )
|
||||||
"Query Tests - Find-One" print
|
"Query Tests - Find-One" print
|
||||||
print-separator-bold
|
print-separator-bold
|
||||||
\ find-one [bench-quot] each ; inline
|
\ find-one [bench-quot] '[ _ call( doc-word -- ) ] each ;
|
||||||
|
|
||||||
: run-find-all-bench ( doc-word-seq feat-seq -- )
|
: run-find-all-bench ( doc-word-seq feat-seq -- )
|
||||||
"Query Tests - Find-All" print
|
"Query Tests - Find-All" print
|
||||||
print-separator-bold
|
print-separator-bold
|
||||||
\ find-all [bench-quot] each ; inline
|
\ find-all [bench-quot] '[ _ call( doc-word -- ) ] each ;
|
||||||
|
|
||||||
: run-find-range-bench ( doc-word-seq feat-seq -- )
|
: run-find-range-bench ( doc-word-seq feat-seq -- )
|
||||||
"Query Tests - Find-Range" print
|
"Query Tests - Find-Range" print
|
||||||
print-separator-bold
|
print-separator-bold
|
||||||
\ find-range [bench-quot] each ; inline
|
\ find-range [bench-quot] '[ _ call( doc-word -- ) ] each ;
|
||||||
|
|
||||||
|
|
||||||
: run-benchmarks ( -- )
|
: run-benchmarks ( -- )
|
||||||
|
|
|
@ -19,8 +19,9 @@ TUPLE: mdb-connection instance node handle remote local ;
|
||||||
|
|
||||||
CONSTRUCTOR: mdb-connection ( instance -- mdb-connection ) ;
|
CONSTRUCTOR: mdb-connection ( instance -- mdb-connection ) ;
|
||||||
|
|
||||||
: check-ok ( result -- ? )
|
: check-ok ( result -- errmsg ? )
|
||||||
[ "ok" ] dip at >integer 1 = ; inline
|
[ [ "errmsg" ] dip at ]
|
||||||
|
[ [ "ok" ] dip at >integer 1 = ] bi ; inline
|
||||||
|
|
||||||
: <mdb-db> ( name nodes -- mdb-db )
|
: <mdb-db> ( name nodes -- mdb-db )
|
||||||
mdb-db new swap >>nodes swap >>name H{ } clone >>collections ;
|
mdb-db new swap >>nodes swap >>name H{ } clone >>collections ;
|
||||||
|
@ -87,7 +88,7 @@ CONSTRUCTOR: mdb-connection ( instance -- mdb-connection ) ;
|
||||||
|
|
||||||
: perform-authentication ( -- )
|
: perform-authentication ( -- )
|
||||||
cmd-collection build-auth-query send-query-1result
|
cmd-collection build-auth-query send-query-1result
|
||||||
dup check-ok [ drop ] [ [ "errmsg" ] dip at throw ] if ; inline
|
check-ok [ drop ] [ throw ] if ; inline
|
||||||
|
|
||||||
: authenticate-connection ( mdb-connection -- )
|
: authenticate-connection ( mdb-connection -- )
|
||||||
[ mdb-connection get instance>> auth?
|
[ mdb-connection get instance>> auth?
|
||||||
|
|
|
@ -86,7 +86,7 @@ M: mdb-collection create-collection ( mdb-collection -- )
|
||||||
] 2bi
|
] 2bi
|
||||||
] keep <mdb-query-msg> 1 >>return# send-query-plain
|
] keep <mdb-query-msg> 1 >>return# send-query-plain
|
||||||
objects>> first check-ok
|
objects>> first check-ok
|
||||||
[ "could not create collection" throw ] unless ;
|
[ drop ] [ throw ] if ;
|
||||||
|
|
||||||
: load-collection-list ( -- collection-list )
|
: load-collection-list ( -- collection-list )
|
||||||
namespaces-collection
|
namespaces-collection
|
||||||
|
@ -101,7 +101,6 @@ M: mdb-collection create-collection ( mdb-collection -- )
|
||||||
USE: tools.continuations
|
USE: tools.continuations
|
||||||
|
|
||||||
: (ensure-collection) ( collection -- )
|
: (ensure-collection) ( collection -- )
|
||||||
break
|
|
||||||
mdb-instance collections>> dup keys length 0 =
|
mdb-instance collections>> dup keys length 0 =
|
||||||
[ load-collection-list
|
[ load-collection-list
|
||||||
[ [ "options" ] dip key? ] filter
|
[ [ "options" ] dip key? ] filter
|
||||||
|
@ -170,7 +169,7 @@ M: mdb-query-msg count
|
||||||
[ collection>> "count" H{ } clone [ set-at ] keep ] keep
|
[ collection>> "count" H{ } clone [ set-at ] keep ] keep
|
||||||
query>> [ over [ "query" ] dip set-at ] when*
|
query>> [ over [ "query" ] dip set-at ] when*
|
||||||
[ cmd-collection ] dip <mdb-query-msg> find-one
|
[ cmd-collection ] dip <mdb-query-msg> find-one
|
||||||
[ check-ok ] keep '[ "n" _ at >fixnum ] [ f ] if ;
|
[ check-ok nip ] keep '[ "n" _ at >fixnum ] [ f ] if ;
|
||||||
|
|
||||||
: lasterror ( -- error )
|
: lasterror ( -- error )
|
||||||
cmd-collection H{ { "getlasterror" 1 } } <mdb-query-msg>
|
cmd-collection H{ { "getlasterror" 1 } } <mdb-query-msg>
|
||||||
|
@ -180,8 +179,8 @@ GENERIC: validate. ( collection -- )
|
||||||
M: string validate.
|
M: string validate.
|
||||||
[ cmd-collection ] dip
|
[ cmd-collection ] dip
|
||||||
"validate" H{ } clone [ set-at ] keep
|
"validate" H{ } clone [ set-at ] keep
|
||||||
<mdb-query-msg> find-one [ check-ok ] keep
|
<mdb-query-msg> find-one [ check-ok nip ] keep
|
||||||
'[ "result" _ at print ] when ;
|
'[ "result" _ at print ] [ ] if ;
|
||||||
M: mdb-collection validate.
|
M: mdb-collection validate.
|
||||||
name>> validate. ;
|
name>> validate. ;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue