All Projects → alexellis → Mongodb Function

alexellis / Mongodb Function

Licence: mit
OpenFaaS Function that makes use of a connection pool to access MongoDB

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Mongodb Function

Graphql Serverless
GraphQL (incl. a GraphiQL interface) middleware for the webfunc serverless web framework.
Stars: ✭ 124 (+181.82%)
Mutual labels:  serverless, faas, functions
Faas Netes
Serverless on Kubernetes with OpenFaaS
Stars: ✭ 1,875 (+4161.36%)
Mutual labels:  serverless, faas, functions
Composer
Composer is a new programming model for composing cloud functions built on Apache OpenWhisk.
Stars: ✭ 131 (+197.73%)
Mutual labels:  serverless, faas, functions
Gofn
Function process via docker provider (serverless minimalist)
Stars: ✭ 134 (+204.55%)
Mutual labels:  serverless, faas, functions
Microcule
SDK and CLI for spawning streaming stateless HTTP microservices in multiple programming languages
Stars: ✭ 454 (+931.82%)
Mutual labels:  serverless, faas, functions
Fission
Fast and Simple Serverless Functions for Kubernetes
Stars: ✭ 6,646 (+15004.55%)
Mutual labels:  serverless, faas, functions
Openwhisk Devtools
Development tools for building and deploying Apache OpenWhisk
Stars: ✭ 141 (+220.45%)
Mutual labels:  serverless, faas, functions
Openwhisk Cli
Apache OpenWhisk Command Line Interface (CLI)
Stars: ✭ 73 (+65.91%)
Mutual labels:  serverless, faas, functions
Nuclio
High-Performance Serverless event and data processing platform
Stars: ✭ 4,213 (+9475%)
Mutual labels:  serverless, faas, functions
Faas
OpenFaaS - Serverless Functions Made Simple
Stars: ✭ 20,820 (+47218.18%)
Mutual labels:  serverless, faas, functions
Openwhisk
Apache OpenWhisk is an open source serverless cloud platform
Stars: ✭ 5,499 (+12397.73%)
Mutual labels:  serverless, faas, functions
Openwhisk Runtime Php
Apache OpenWhisk Runtime PHP supports Apache OpenWhisk functions written in PHP
Stars: ✭ 26 (-40.91%)
Mutual labels:  serverless, faas, functions
Openwhisk Deploy Kube
The Apache OpenWhisk Kubernetes Deployment repository supports deploying the Apache OpenWhisk system on Kubernetes and OpenShift clusters.
Stars: ✭ 231 (+425%)
Mutual labels:  serverless, faas, functions
Dispatch
Dispatch is a framework for deploying and managing serverless style applications.
Stars: ✭ 529 (+1102.27%)
Mutual labels:  serverless, faas, functions
Openwhisk Runtime Nodejs
Apache OpenWhisk Runtime NodeJS supports Apache OpenWhisk functions written in JavaScript for NodeJS
Stars: ✭ 43 (-2.27%)
Mutual labels:  serverless, faas, functions
Functional Typescript
TypeScript standard for rock solid serverless functions.
Stars: ✭ 600 (+1263.64%)
Mutual labels:  serverless, faas
Octo Cli
CLI tool to expose data from any database as a serverless web service.
Stars: ✭ 653 (+1384.09%)
Mutual labels:  serverless, faas
Ssr
A most advanced ssr framework support React/Vue2/Vue3 at the same time on Earth that implemented serverless-side render specification for faas and traditional web server.
Stars: ✭ 576 (+1209.09%)
Mutual labels:  serverless, faas
Derek
Reduce maintainer fatigue by automating GitHub
Stars: ✭ 714 (+1522.73%)
Mutual labels:  serverless, faas
Kotless
Kotlin Serverless Framework
Stars: ✭ 721 (+1538.64%)
Mutual labels:  serverless, faas

OpenFaaS with MongoDB

This is a simple example of how to use connection pooling in MongoDB with OpenFaaS on Kubernetes.

  1. In the first sequence we've had no calls made to the function, so the connection pool is not yet initialized. prepareDB() was never called.

  2. In the second sequence prepareDB() has been called and since there was no instance of a connection in memory, we create one and you see the dotted line shows the connection being established. This will then open a connection to MongoDB in the network.

  3. In the third sequence we see that subsequent calls detect a connection exists and go straight to the connection pool. We have one active connection and two shown with dotted lines which are about to be closed due to inactivity.

Pre-requisites

Before we can build and deploy the example we'll set up OpenFaaS on Kubernetes or Swarm followed by MongoDB. This configuration is suitable for development and testing.

  1. Start by cloning the Github repository:
$ git clone https://github.com/alexellis/mongodb-function

Kubernetes

  1. Install OpenFaaS with helm

https://docs.openfaas.com/deployment/kubernetes/

  1. Install the OpenFaaS CLI
curl -sL https://cli.openfaas.com | sudo sh
  1. Set your OPENFAAS_URL variable
$ export OPENFAAS_URL=127.0.0.1:31112

If you're using minikube or a remote machine then replace 127.0.0.1 with that IP address.

  1. Install mongodb via helm
$ helm install stable/mongodb --name openfaas-db \
  --namespace openfaas-fn \
  --set persistence.enabled=false

Note down the name of the MongoDB instance i.e. openfaas-db-mongodb

If you want to use the fully-qualified DNS name that would be: openfaas-db-mongodb.openfaas-fn.svc.cluster.local.

Now skip ahead to "Build and test"

Docker Swarm

  1. Install OpenFaaS with Docker

https://docs.openfaas.com/deployment/docker-swarm/

  1. Install the OpenFaaS CLI
curl -sL https://cli.openfaas.com | sudo sh
  1. Set your OPENFAAS_URL variable
$ export OPENFAAS_URL=127.0.0.1:8080
  1. Create a mongodb Docker Service
$ docker service create --network=func_functions --name openfaas-db-mongodb --publish 27017:27017 mongo mongod

The entry for the stack.yml file will be the IP of your Docker Swarm manager.

Build and test

  1. Update your stack.yml's mongo field with the MongoDB DNS entry/IP from prior steps

  2. Replace "alexellis/" prefix from Docker Hub in stack.yml with your own account

  3. Build/push/deploy

Pull in the node8-express template:

$ faas template pull https://github.com/openfaas-incubator/node8-express-template

Now build and push / deploy

$ faas build && faas push && faas deploy
  1. Get a load-testing tool

This requires a local installation of Go.

$ go get -u github.com/rakyll/hey

An alternative tool would be Apache-Bench which is available for most Linux distributions via a package manager.

  1. Run a test

Let's start by running a single request with curl:

$ curl http://$OPENFAAS_URL/function/insert-user \
  --data-binary '{"first":"Alex", "last": "Ellis"}' \
  -H "Content-Type: application/json"

Now run a load-test with hey:

$ ~/go/bin/hey -m POST -d '{"first":"Alex", "last": "Ellis"}' \
  -H "Content-Type: application/json" \
  -n 1000 -c 10 http://$OPENFAAS_URL/function/insert-user

This test posts in a JSON body with 1000 requests with 10 of those being concurrent.

Here's an abridged output from hey with the function running on a remote server with the test being run from my laptop:

Summary:
  Requests/sec: 1393.2083
...
Status code distribution:
  [200] 10000 responses

If you look at the logs of the Mongo deployment or service you will see the connection count is between 1-10 connections only during the load-test. This shows that the connection-pool is being used by our function.

On Kubernetes:

$ kubectl logs deploy/openfaas-db-mongodb -f -n openfaas-fn

On Swarm:

$ docker service logs openfaas-db-mongodb -f
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].