{"_id":"shm","_rev":"6-9714f17a5cfc437d628ebd20db956901","name":"shm","description":"simple to use, PHP compatible shared memory for node.js","dist-tags":{"latest":"0.1.0"},"versions":{"0.1.0":{"author":{"name":"Jan Supuka","email":"sbmintegral@sbmintegral.sk","url":"http://www.sbmintegral.sk"},"name":"shm","description":"simple to use, PHP compatible shared memory for node.js","main":"./build/Release/shm","version":"0.1.0","repository":{"type":"git","url":"git://github.com/supipd/node-shm.git"},"keywords":["shm","shmop","shared","memory","ipc"],"scripts":{"install":"node-gyp rebuild","test":"node ./test/test.js"},"license":"MIT","engines":{"node":">=0.8.14"},"bugs":{"url":"https://github.com/supipd/node-shm/issues"},"readme":"nodejs-shm  (WORK IN PROGRESS)\r\n==========\r\n\r\nNode.js native addon for using shared memory compatible with PHP shmop\r\n\r\nDescription\r\n-----------\r\n\r\nWorking on bigger project with several autonomous long-running processes I need communication between them. \r\nThis processes ( workers, drivers ) need share relatively huge amount of data ( 10k - 100k bytes ) \r\nand I feel, that communication through TCP sockets is not so fast, as I want. \r\n\r\nI have PHP workers with shared memory used with shmop_XXXX commands as \"data sources\", and another workers, \r\nbased on node.js, which I need connect with them - that's why I started this work.  \r\n\r\nWorking with shared memory need some discipline, my solution of potential concurrency and race condition problem \r\nis simple (not included in sources, only for imagination) :\r\n\r\nMy shm system is based on one big (10 MB) allocated shared memory block, divided to sections, where can write \r\nonly exactly one worker. Information about sections (addressOffset, sectionSize, owner) are readed from database\r\nand saved in first - header section.\r\nSHM creates one process - centralManager, which writes header section.\r\nWorkers connects to SHM with well-known KEY, reads header section, finds info, where they have memory space\r\n(offset and size) and where are spaces of another workers, whose data they maybe need.\r\n\r\nAnd communication between processes can start.\r\n\r\n\r\nTODO: simple SHM manager. \r\n\r\n\r\nThe module is currently build on windows, linux not already tested. \r\n\r\n#####Because a newbie in nodejs, this native addon is maybe not very pretty ... any help invited\r\n\r\n\r\nInstalation\r\n--------------\r\n\r\nYou can install with `npm`:\r\n\r\n``` bash\r\n$ npm install -g nodejs-shm\r\n```\r\n\r\nHow to Use\r\n----------\r\n\r\nAPI\r\n---\r\n``` \r\n    C\r\n//\tint shmid  .... int shmop_open (int key, char* flags, int mode, int size)\r\n//\tint  shmop_size (int shmid)\r\n//\tint  shmop_write (int shmid, char * data, int offset, int data_len)\r\n//\tunsigned char*  shmop_read (int shmid, int start, int length)\r\n//\tint shmop_delete (int shmid)\r\n//\tint  shmop_close (int shmid)\r\n\r\n    Javascript\r\n        module \tshm\r\n        function openSHM ( key [Number], flags [String], mode [Number], size [Number]) ... returns shmid [Number]\r\n        function sizeSHM ( shmid [Number] ) ... returns allocated size [Number]\r\n        function writeSHM ( shmid [Number], data [Buffer], offset [Number], data_len [Number] ) ... returns written bytes [Number]\r\n        function readSHM ( shmid [Number], start [Number], length [Number] )  ... returns Buffer\r\n        function deleteSHM ( shmid [Number] ) ... return 0 or 1 [Number]\r\n        function closeSHM ( shmid [Number] ) ... return 0 or 1 [Number]\r\n```\r\n\r\nEXAMPLE (test/test.js)\r\n----------------------\r\n\r\n``` js\r\nvar shm = require('./build/Release/shm');\r\n\r\nconsole.log(\"Object:\\n\", shm); \r\n\r\nvar shmkey = 1236;\r\n\r\nvar shmid  = shm.openSHM(shmkey,'c',0,1024);\t\t\r\nconsole.log(\"opened shmkey:\",shmkey, \" shmid:\",shmid);\r\n\r\nvar bubu = new Buffer(\"1234567890\");\r\nconsole.log(\"writing '1234567890', written:\",shm.writeSHM(shmid,bubu,2,bubu.length));\t\t//10\r\n\r\nxxxx = shm.readSHM(shmid,2,10);\r\nconsole.log(\"readed(HEXA):\", buff2hex(xxxx));\r\n\r\nconsole.log(\"waiting 10 secs to detach and close\");\r\nvar timerD = setTimeout( function() {\r\n\tconsole.log(\"detatch retval:\", shm.deleteSHM(shmid) );\r\n\tconsole.log(\"close retval:\", shm.closeSHM(shmid) );\r\n}, 10000);\r\n```\r\n\r\nLicense\r\n-------\r\n\r\nCopyright (c) 2013 Jan Supuka sbmintegral.sk\r\n\r\nThe MIT License\r\n\r\n","readmeFilename":"README.md","_id":"shm@0.1.0","dist":{"shasum":"9a3b3de5fad834c7e55bdfff95095fc9af71e108","tarball":"https://registry.npmjs.org/shm/-/shm-0.1.0.tgz","integrity":"sha512-MiKPm3/hROIq4iMMGCOyS7lRfOFPt5xMZFK3HJq4k9O31SKB0P7AlZA3xffdVZzb+CnZtUOcFW2tr07kYpzYOw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIHgAezFcyVucqWV0SIp6T1UyD8zDczm+swctM0yAPsw+AiEAijgxd544sKvb5DBG83Vu2I9YeffS6mzBkH7BD1ELCYY="}]},"_npmVersion":"1.1.65","_npmUser":{"name":"supipd","email":"sbmintegral@sbmintegral.sk"},"maintainers":[{"name":"supipd","email":"sbmintegral@sbmintegral.sk"}]}},"readme":"nodejs-shm  (WORK IN PROGRESS)\r\n==========\r\n\r\nNode.js native addon for using shared memory compatible with PHP shmop\r\n\r\nDescription\r\n-----------\r\n\r\nWorking on bigger project with several autonomous long-running processes I need communication between them. \r\nThis processes ( workers, drivers ) need share relatively huge amount of data ( 10k - 100k bytes ) \r\nand I feel, that communication through TCP sockets is not so fast, as I want. \r\n\r\nI have PHP workers with shared memory used with shmop_XXXX commands as \"data sources\", and another workers, \r\nbased on node.js, which I need connect with them - that's why I started this work.  \r\n\r\nWorking with shared memory need some discipline, my solution of potential concurrency and race condition problem \r\nis simple (not included in sources, only for imagination) :\r\n\r\nMy shm system is based on one big (10 MB) allocated shared memory block, divided to sections, where can write \r\nonly exactly one worker. Information about sections (addressOffset, sectionSize, owner) are readed from database\r\nand saved in first - header section.\r\nSHM creates one process - centralManager, which writes header section.\r\nWorkers connects to SHM with well-known KEY, reads header section, finds info, where they have memory space\r\n(offset and size) and where are spaces of another workers, whose data they maybe need.\r\n\r\nAnd communication between processes can start.\r\n\r\n\r\nTODO: simple SHM manager. \r\n\r\n\r\nThe module is currently build on windows, linux not already tested. \r\n\r\n#####Because a newbie in nodejs, this native addon is maybe not very pretty ... any help invited\r\n\r\n\r\nInstalation\r\n--------------\r\n\r\nYou can install with `npm`:\r\n\r\n``` bash\r\n$ npm install -g nodejs-shm\r\n```\r\n\r\nHow to Use\r\n----------\r\n\r\nAPI\r\n---\r\n``` \r\n    C\r\n//\tint shmid  .... int shmop_open (int key, char* flags, int mode, int size)\r\n//\tint  shmop_size (int shmid)\r\n//\tint  shmop_write (int shmid, char * data, int offset, int data_len)\r\n//\tunsigned char*  shmop_read (int shmid, int start, int length)\r\n//\tint shmop_delete (int shmid)\r\n//\tint  shmop_close (int shmid)\r\n\r\n    Javascript\r\n        module \tshm\r\n        function openSHM ( key [Number], flags [String], mode [Number], size [Number]) ... returns shmid [Number]\r\n        function sizeSHM ( shmid [Number] ) ... returns allocated size [Number]\r\n        function writeSHM ( shmid [Number], data [Buffer], offset [Number], data_len [Number] ) ... returns written bytes [Number]\r\n        function readSHM ( shmid [Number], start [Number], length [Number] )  ... returns Buffer\r\n        function deleteSHM ( shmid [Number] ) ... return 0 or 1 [Number]\r\n        function closeSHM ( shmid [Number] ) ... return 0 or 1 [Number]\r\n```\r\n\r\nEXAMPLE (test/test.js)\r\n----------------------\r\n\r\n``` js\r\nvar shm = require('./build/Release/shm');\r\n\r\nconsole.log(\"Object:\\n\", shm); \r\n\r\nvar shmkey = 1236;\r\n\r\nvar shmid  = shm.openSHM(shmkey,'c',0,1024);\t\t\r\nconsole.log(\"opened shmkey:\",shmkey, \" shmid:\",shmid);\r\n\r\nvar bubu = new Buffer(\"1234567890\");\r\nconsole.log(\"writing '1234567890', written:\",shm.writeSHM(shmid,bubu,2,bubu.length));\t\t//10\r\n\r\nxxxx = shm.readSHM(shmid,2,10);\r\nconsole.log(\"readed(HEXA):\", buff2hex(xxxx));\r\n\r\nconsole.log(\"waiting 10 secs to detach and close\");\r\nvar timerD = setTimeout( function() {\r\n\tconsole.log(\"detatch retval:\", shm.deleteSHM(shmid) );\r\n\tconsole.log(\"close retval:\", shm.closeSHM(shmid) );\r\n}, 10000);\r\n```\r\n\r\nLicense\r\n-------\r\n\r\nCopyright (c) 2013 Jan Supuka sbmintegral.sk\r\n\r\nThe MIT License\r\n\r\n","maintainers":[{"name":"supipd","email":"sbmintegral@sbmintegral.sk"}],"time":{"modified":"2022-06-26T18:58:41.353Z","created":"2013-03-16T07:21:51.702Z","0.1.0":"2013-03-16T07:21:54.733Z"},"author":{"name":"Jan Supuka","email":"sbmintegral@sbmintegral.sk","url":"http://www.sbmintegral.sk"},"repository":{"type":"git","url":"git://github.com/supipd/node-shm.git"},"users":{"chunlin-li":true}}