Permalink
Browse files

Build 8: BatchPutAttributes performance enhancement

  • Loading branch information...
1 parent 8aea446 commit a1f13e94f8dc3a020e9de2d9a61878199abe749b @robtweed committed Jun 9, 2011
Showing with 100 additions and 11 deletions.
  1. +59 −2 gtm/MDB.m
  2. +8 −6 gtm/zmwire.m
  3. +33 −3 lib/mdb.js
View
61 gtm/MDB.m
@@ -25,10 +25,10 @@
;
;
version()
- QUIT "42"
+ QUIT "43"
;
buildDate()
- QUIT "04 June 2011"
+ QUIT "09 June 2011"
;
indexLength()
QUIT 180
@@ -367,6 +367,63 @@ d getDomainMetaData(keyId,domainId,.metaData)
d updateDomainMetaData(keyId,domainId)
QUIT $$end(startTime,.boxUsage)
;
+batchPutItem(keyId,domainId,itemName,attributesJSON)
+ ;
+ n attribId,attributes,error,itemId,name,namex,no,replace,value,valueId,valuex,xvalue
+ ;
+ ;d trace^zmwire("batchPutItem: keyid="_keyId_"; domainId="_domainId_"; itemName="_itemName_"; attributes="_attributesJSON)
+ s itemName=$g(itemName)
+ i itemName="" QUIT 0
+ s itemId=$$getItemId(keyId,domainId,itemName)
+ i itemId="" d
+ . ; add Item to Domain if it's new
+ . n itemNamex
+ . s itemNamex=$e(itemName,1,$$indexLength())
+ . s itemId=$increment(^MDB(keyId,"domains",domainId,"items"))
+ . s ^MDB(keyId,"domains",domainId,"itemIndex",itemNamex,itemId)=""
+ . s ^MDB(keyId,"domains",domainId,"items",itemId)=itemName
+ . s ^MDB(keyId,"domains",domainId,"attribs",0)="itemName()"
+ . s ^MDB(keyId,"domains",domainId,"attribsIndex","itemName()",0)=""
+ . s ^MDB(keyId,"domains",domainId,"items",itemId,"attribs",0,"value")=1
+ . s ^MDB(keyId,"domains",domainId,"items",itemId,"attribs",0,"value",1)=itemName
+ . s ^MDB(keyId,"domains",domainId,"queryIndex",0,itemNamex,itemId)=""
+ ;
+ s error=$$parseJSON^zmwire(attributesJSON,.attributes,1)
+ ;
+ ; attributes(no,"name")=attribute name
+ ; attributes(no,"value")=attribute value
+ ; attributes(no,"replace")=1
+ ;
+ s no=""
+ f s no=$o(attributes(no)) q:no="" d
+ . s name=$g(attributes(no,"name"))
+ . s value=$g(attributes(no,"value"))
+ . i value="" s value=$c(31)
+ . s replace=+$g(attributes(no,"replace"))
+ . s namex=$e(name,1,$$indexLength())
+ . s valuex=$e(value,1,$$indexLength())
+ . s attribId=$$getAttributeId(keyId,domainId,name)
+ . i attribId="" d
+ . . ; add new attribute name to the domain
+ . . s attribId=$increment(^MDB(keyId,"domains",domainId,"attribs"))
+ . . s ^MDB(keyId,"domains",domainId,"attribs",attribId)=name
+ . . s ^MDB(keyId,"domains",domainId,"attribsIndex",namex,attribId)=""
+ . s valueId=$$getAttributeValueId(keyId,domainId,itemId,attribId,value)
+ . i 'replace,valueId'="" q ; Not allowed to have more than one attribute with the same name and value
+ . i replace d
+ . . ; first remove any existing values for this attribute name
+ . . f s valueId=$o(^MDB(keyId,"domains",domainId,"items",itemId,"attribs",attribId,"value",valueId)) q:valueId="" d
+ . . . s xvalue=^MDB(keyId,"domains",domainId,"items",itemId,"attribs",attribId,"value",valueId)
+ . . . k ^MDB(keyId,"domains",domainId,"items",itemId,"attribs",attribId,"valueIndex",xvalue,valueId)
+ . . . k ^MDB(keyId,"domains",domainId,"queryIndex",attribId,xvalue,itemId)
+ . . k ^MDB(keyId,"domains",domainId,"items",itemId,"attribs",attribId,"value")
+ . ; now add the new attribute name/value pair
+ . s valueId=$increment(^MDB(keyId,"domains",domainId,"items",itemId,"attribs",attribId,"value"))
+ . s ^MDB(keyId,"domains",domainId,"items",itemId,"attribs",attribId,"value",valueId)=value
+ . s ^MDB(keyId,"domains",domainId,"items",itemId,"attribs",attribId,"valueIndex",valuex,valueId)=""
+ . s ^MDB(keyId,"domains",domainId,"queryIndex",attribId,valuex,itemId)=""
+ QUIT 1
+ ;
getAttributes(keyId,domainName,itemName,attributes,requestId,boxUsage,suppressBoxUsage)
;
n attribId,attrNo,domainId,itemId,name,startTime,value,valueId,valueNo
View
14 gtm/zmwire.m
@@ -55,7 +55,7 @@
; Stop the Daemon process using ^RESJOB and restart it.
;
mwireVersion
- ;;Build 18
+ ;;Build 19
;
mwireDate
;;09 June 2011
@@ -216,6 +216,7 @@ i param(1)="COPYGLOBAL" d QUIT input
. . i space="" s space=" " q
. . i space=" " s space=$c(1)
i param(1)="EXECUTE" d QUIT input
+ . s param(3)=$$replaceAll(param(3),"\""","""""")
. i $e(param(3),1)="[" s input=param(1)_" "_param(2)_"("_$e(param(3),2,$l(param(3))-1)_")" q
. s input=param(1)_" "_param(2)
;
@@ -556,7 +557,7 @@ i param(1)="EXECUTE" d QUIT input
;]
;
;
- s error=$$parseJSON^%zewdJSON(input,.props,1)
+ s error=$$parseJSON(input,.props,1)
i error'="" s output="-"_error_crlf w output QUIT
;
s stop=0,error="",json="[",comma=""
@@ -668,7 +669,7 @@ i param(1)="EXECUTE" d QUIT input
;
n error,globalName,i,json,props,ref,result,stop,subscripts
;
- s error=$$parseJSON^%zewdJSON(input,.props,1)
+ s error=$$parseJSON(input,.props,1)
i error'="" s output="-"_error_crlf w output QUIT
;
s stop=0,error=""
@@ -755,7 +756,7 @@ i param(1)="EXECUTE" d QUIT input
s gloRef=gloName
i gloRef["^zmwire" s output="-No access allowed to this global"_crlf w output QUIT
i subs'="" s gloRef=gloRef_"("_subs_")"
- s error=$$parseJSON^%zewdJSON(json,.props,1)
+ s error=$$parseJSON(json,.props,1)
i error'="" s output="-Invalid JSON in setJSON: "_json_crlf w output QUIT
;
s ref=""
@@ -864,6 +865,7 @@ i param(1)="EXECUTE" d QUIT input
s $zt=""
s output="$"_$l(data)_crlf_data_crlf
w output
+ i $g(^mwire("logger"))=1 d logger("function")
QUIT
;
decr(input)
@@ -1342,7 +1344,7 @@ i param(1)="EXECUTE" d QUIT input
n fromGlo,killToFirst,p2,response,toGlo,x
;
; COPY fromGlobal["1","a"] toGlobal["x"] 1
- d trace^%zewdAPI("copy: input="_input)
+ d trace("copy: input="_input)
s $zt=$$zt()
s fromGlo=$p(input,$c(1),1)
s toGlo=$p(input,$c(1),2)
@@ -1360,7 +1362,7 @@ i param(1)="EXECUTE" d QUIT input
s x=x_"m "_toGlo_"="_fromGlo
x x
;
- d trace^%zewdAPI("x="_x)
+ d trace("x="_x)
s response="+ok"_crlf
i $g(^%zewd("trace"))=1 d trace("copy: response="_response)
w response
View
36 lib/mdb.js
@@ -1,7 +1,7 @@
/*
++++ node-mdb ++++
- ++++ Build 7 ++++
- ++++ 08 June 2011 ++++
+ ++++ Build 8 ++++
+ ++++ 09 June 2011 ++++
----------------------------------------------------------------------------
| node-mdb: Node.js version of M/DB |
@@ -113,6 +113,10 @@ var MDB = {
},
select: function(SDB, callback) {
db.clientPool[db.connection()].remoteFunction('externalSelect^MDB', [SDB.nvps.AWSAccessKeyId, SDB.nvps.SelectExpression], callback);
+ },
+ batchPutItem: function(domainId, itemName, attributes, SDB, callback) {
+ var attrsJSON = JSON.stringify(attributes);
+ db.clientPool[db.connection()].remoteFunction('batchPutItem^MDB', [SDB.nvps.AWSAccessKeyId, domainId, itemName, attrsJSON], callback);
}
};
@@ -1525,6 +1529,32 @@ var parseBatchPutAttributes = function(domainIndex, SDB) {
var batchPutAttributes = function(domainIndex, param, SDB) {
+ // remote M call version to avoid M/Wire overhead
+ var itemName;
+ var noOfItems = 0;
+ for (itemNo in param) noOfItems++;
+ ;
+ var attrs;
+ var attributes = [];
+ var count = 0;
+ for (itemNo in param) {
+ itemName = param[itemNo].itemName;
+ attrs = param[itemNo].attrs;
+ var attribNo = 0;
+ for (attrNo in attrs) {
+ attributes[attribNo] = attrs[attrNo];
+ attribNo++;
+ }
+ MDB.batchPutItem(domainIndex, itemName, attributes, SDB, function(error,results) {
+ count++;
+ if (count === noOfItems) okResponse(SDB);
+ });
+ }
+};
+
+/*
+
+var batchPutAttributes = function(domainIndex, param, SDB) {
var itemNos = [];
var count = 0;
for (itemNo in param) {
@@ -1580,7 +1610,7 @@ var putItem = function(domainIndex, itemNo, SDB) {
checkItemExists(domainIndex, itemName, invoke, SDB);
};
-
+*/
/*
***************** DeleteAttributes ***************************

0 comments on commit a1f13e9

Please sign in to comment.