Skip to content
This repository has been archived by the owner on Aug 9, 2021. It is now read-only.

Commit

Permalink
chore: profiling
Browse files Browse the repository at this point in the history
  • Loading branch information
zachferland committed Jul 29, 2020
1 parent e0b1080 commit bb30960
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 64 deletions.
12 changes: 8 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,24 @@ jobs:
test:
working_directory: ~/3box-pinning-server
docker:
- image: circleci/node:10
- image: circleci/node:10.12.0
steps:
- checkout

# Download and cache dependencies
- restore_cache:
keys:
- dependencies-cache-{{ checksum "package.json" }}
- dependencies-cache-{{ checksum "package-lock.json" }}

- run:
name: install dependencies
command: |
sudo npm i -g codecov node-gyp
npm i
npm ci
# - run:
# name: versions
# command: npm list libp2p-gossipsub

- run:
name: test
Expand All @@ -37,7 +41,7 @@ jobs:
command: bash <(curl -s https://codecov.io/bash)

- save_cache:
key: dependency-cache-{{ checksum "package.json" }}
key: dependency-cache-{{ checksum "package-lock.json" }}
paths:
- ./node_modules

Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ COPY src ./src

EXPOSE 8081 4002 4003 5002 9090 9229

CMD npm run start:prod
CMD npm run start:prod:profile
36 changes: 17 additions & 19 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
"ipfs-repo": "^3.0.2",
"js-sha256": "^0.9.0",
"level-mem": "^5.0.1",
"libp2p-gossipsub": "github:zachferland/js-libp2p-gossipsub#7e26a1dc757da433358d02ae7c18eadabf2da6eb",
"libp2p-pubsub": "github:zachferland/js-libp2p-pubsub#870b36536599bc1e802085e3e3187fa92712540d",
"multihashes": "^0.4.14",
"muport-did-resolver": "^1.0.3",
"orbit-db": "^0.24.2",
Expand Down
52 changes: 26 additions & 26 deletions src/__tests__/healthcheckService.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,32 +26,32 @@ describe('HealthcheckService', () => {
isOnlineMock.mockRestore()
})

it('should return a failure if IPFS isn\'t online', async (done) => {
isOnlineMock.mockReturnValue(false)

request(healthcheckService.app)
.get('/healthcheck')
.expect(503)
.end(done)
})

it('should return a failure on low cpu', async (done) => {
cpuFreeMock.mockImplementation(cb => cb(0.01)) // eslint-disable-line standard/no-callback-literal

request(healthcheckService.app)
.get('/healthcheck')
.expect(503)
.end(done)
})

it('should return a failure on low memory', async (done) => {
freememPercentageMock.mockReturnValue(0.01)

request(healthcheckService.app)
.get('/healthcheck')
.expect(503)
.end(done)
})
// it('should return a failure if IPFS isn\'t online', async (done) => {
// isOnlineMock.mockReturnValue(false)
//
// request(healthcheckService.app)
// .get('/healthcheck')
// .expect(503)
// .end(done)
// })
//
// it('should return a failure on low cpu', async (done) => {
// cpuFreeMock.mockImplementation(cb => cb(0.01)) // eslint-disable-line standard/no-callback-literal
//
// request(healthcheckService.app)
// .get('/healthcheck')
// .expect(503)
// .end(done)
// })
//
// it('should return a failure on low memory', async (done) => {
// freememPercentageMock.mockReturnValue(0.01)
//
// request(healthcheckService.app)
// .get('/healthcheck')
// .expect(503)
// .end(done)
// })

it('should return a success if memory, cpu and IPFS status are OK', async (done) => {
request(healthcheckService.app)
Expand Down
26 changes: 13 additions & 13 deletions src/healthcheckService.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
const express = require('express')
const os = require('os-utils')
// const os = require('os-utils')

const { createLogger } = require('./logger')

const HEALTH_CPU_LIMIT_PERCENT = (process.env.HEALTH_CPU_LIMIT || 50) / 100
// const HEALTH_CPU_LIMIT_PERCENT = (process.env.HEALTH_CPU_LIMIT || 90) / 100
// Temporarily Low Default, Mem Leak
const HEALTH_MEM_LIMIT_PERCENT = (process.env.HEALTH_MEM_LIMIT || 20) / 100
// const HEALTH_MEM_LIMIT_PERCENT = (process.env.HEALTH_MEM_LIMIT || 80) / 100

class HealthcheckService {
constructor (pinning, port) {
Expand All @@ -17,16 +17,16 @@ class HealthcheckService {
}

async healthcheckHandler (req, res, next) {
if (!this.pinning.ipfs.isOnline()) {
return res.status(503).send()
}

const cpu = 1 - (await new Promise((resolve, reject) => os.cpuFree(resolve)))
const mem = 1 - os.freememPercentage()

if (cpu > HEALTH_CPU_LIMIT_PERCENT || mem > HEALTH_MEM_LIMIT_PERCENT) {
return res.status(503).send()
}
// if (!this.pinning.ipfs.isOnline()) {
// return res.status(503).send()
// }
//
// const cpu = 1 - (await new Promise((resolve, reject) => os.cpuFree(resolve)))
// const mem = 1 - os.freememPercentage()
//
// if (cpu > HEALTH_CPU_LIMIT_PERCENT || mem > HEALTH_MEM_LIMIT_PERCENT) {
// return res.status(503).send()
// }
return res.status(200).send()
}

Expand Down
2 changes: 1 addition & 1 deletion src/s3.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const agent = new https.Agent({
})

AWS.config.update({
logger: console,
// logger: console,
httpOptions: {
timeout: 45000,
connectTimeout: 45000,
Expand Down

0 comments on commit bb30960

Please sign in to comment.