On Friday, May 12, 2017 at 1:19:26 AM UTC+2, Kameron Berget wrote:
>
>
> Should the require('mssql'), config and connect statements really be
> inside the GET? That would mean that I have to repeat the config
> (connection) settings in each method on each endpoint. Where would be the
> best place to put this? Also, are simple sql.connect calls ok for large
> loads or do I need to consider connection pools, etc? My GET method is
> below.
>
>
Well, for one thing, the *require* itself is cached, on process level. So
no matter how many times you call require('mssql'), it'll only read it
once, at that first require in the first module that actually calls it.
But that is, as you seem to suspect, most likely *not* the perf problem,
but the fact that on each API request, you have to create a new connection.
How it is usually done is to have a *db* module somewhere. Then you export
a *db.bootstrap* or *db.initialize* function, and possibly a *db.client* from
that module and other db-querying modules use that client. You call the
init once when your server is starting, and than all other actual calls to
the db do not have to do this step. Just make sure that before the server
started serving
One of the exceptions to this would be when you're using something like
Azure Functions, or AWS lambda or similar. Usually you cannot persist
database connections there so you have to connect on each request. But
that's probably something you ask later.
One small disclaimer is that I didn't work with Azure, but I've worked with
other bigger infra/platform providers and they usually share those concepts
so I'm pretty sure the above should apply to Azure App service.
--
Job board: http://jobs.nodejs.org/
New group rules:
https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules:
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
---
You received this message because you are subscribed to the Google Groups
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/nodejs/cdc779d3-56a3-4c23-a985-c6d9388c2671%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.