Comments (4)
That is the expected behavior. Nodem relies upon the GT.M Call-in interface, which allows a process to open the database one time, and once it has closed its database connection, that process is no longer allowed to open it. So you should only open the connection to GT.M one time in any Node.js process, and you should only close the connection to GT.M one time in any Node.js process, unless you are finished accessing it in that process.
The initialization is what adds Nodem into your Node.js process. And that is something you only need to do one time as well. Initializing Nodem creates the appropriate Nodem object that gives you access to Nodem, using a constructor method which wraps a C++ class which exposes the various Nodem methods. If you require a module more than once, Node.js will only add that module to that process's image one time.
So you only need to require Nodem one time per process, and you only need to initialize Nodem one time per process, and you only need to open the database connection one time per process, and you should only close the connection to the database after you are done talking to GT.M, as you cannot close it and then re-open it in the same process, which is a limitation in the Call-in API of GT.M. Actually you don't even need to close the database connection, because all of its resources will be released whenever a process that is linked with GT.M ends anyway.
You should therefore not try requiring, initializing, opening, or closing the Nodem interface for each function or method in your Node.js code. I hope that helps.
from nodem.
As this is quite unusual from the normal practice with other db, I hope you do not mind I rehash it a bit. So the pattern found in the example is only for short term process. And for long running processes, we just need to open the connection, init but do not care to close it as it will be garbage collected if and when the process is terminated. And there is no memory leak as a result of not closing the db. Is my understanding correct? Thanks of your help.
from nodem.
Yes, that is basically correct. When the process is terminated, its resources will be cleaned up and not leaked. That is actually a function of the operating system. When a process dies, its virtual address space is removed and any physical memory mapped to it is freed. In addition, Nodem is using V8 C++ APIs, which themselves allocate memory that is cleaned up by a garbage collector (the JavaScript garbage collector in Node.js). And when I have to allocate dynamic memory on the heap in C code, to work with GT.M, I am careful (I believe) to deallocate it properly.
But, closing the database connection will ensure that the terminal is reset to the settings it had before it opened a connection to GT.M (which changes those settings in surprising ways), as well as explicitly allowing GT.M the chance to clean up its resources. I'd still advise that you use the close API in your code. Again, only close the database connection when you no longer need to access GT.M in that process.
from nodem.
For long-running Node.js processes, you should probably close the database in the handler code for stopping the Node process. E.g.
process.on('exit', function() {
db.close();
});
and
process.on('SIGINT', function() {
db.close();
});
Where you can put your own cleanup code right before or after closing the connection to GT.M.
from nodem.
Related Issues (13)
- Always getting error GTM-E-SYSCALL HOT 3
- Are lock and unlock needed for transaction commit? HOT 2
- GT.M bindings/drivers for AIX System HOT 2
- Create a HOT 1
- Error on ydb.open(); YottaDB database connection cannot be reopened HOT 2
- Link to Globals Node.js API Documentation is broken (in README.md) HOT 1
- Error: Module version mismatch. Expected 11, got 1. HOT 1
- error when trying to install with npm on Ubuntu 12.04 LTS 64bit server HOT 1
- SyntaxError: Unexpected token when using function with parameters HOT 5
- enconding problem HOT 2
- Easy install now that apt-get install fis-gtm exists? HOT 3
- function - error when passing argument with quotes HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nodem.