顯示具有 nodejs 標籤的文章。 顯示所有文章
顯示具有 nodejs 標籤的文章。 顯示所有文章

2016年8月25日 星期四

stress test, loda test, 壓力測試, node.js

常見的 stress test 工具為 java 的 JMeter, 但對 Nodejs server 做壓力測試可以用開源使用者開發的 library, 例如 loadtest 和 nodeload .


What is load-test, stress-test, and identity

Load testing is the process of putting demand on a software system or computing device and measuring its response.
Load testing is performed to determine a system's behavior under both normal and anticipated peak load conditions.
It helps to identify the maximum operating capacity of an application as well as any bottlenecks and determine which element is causing degradation.
When the load placed on the system is raised beyond normal usage patterns to test the system's response at unusually high or peak loads, it is known as stress testing.



Methodology 

There is little agreement on what the specific goals of load testing are. The term is often used synonymously with concurrency testing, software performance testing, reliability testing, and volume testing. Load testing is usually a type of non-functional testing, but it can be used as a functional test to validate suitability for use.


Nodejs VS Apache

http://zgadzaj.com/benchmarking-nodejs-basic-performance-tests-against-apache-php

nodeload

 is a collection of independent node.js modules for load testing HTTP services.
https://www.npmjs.com/package/nodeload


NODE STRESS SUITE

is a collection of independent node.js modules for load testing HTTP services.
https://github.com/Samuel29/NodeStressSuite

loadtest

Runs a load test on the selected HTTP or WebSockets URL. The API allows for easy integration in your own tests.
https://github.com/alexfernandez/loadtest




2016年8月24日 星期三

nodejs, express, middleware, use globally


Execute the CallBack function for every request (GET, POST). 

////////////////////////////////////////////////////
////////////////////////////////////////////////////

app.use(function (req, res, next) {
  console.log('Time:', Date.now( ));
});

//GET /api/v1/me/buildin
//Time: 1472093395081

////////////////////////////////////////////////////
////////////////////////////////////////////////////

2016年8月18日 星期四

set environment variable before npm start, nodejs

Set environment variable before npm start

 package.json

...
"scripts": {
  "start": "node app.js",
  "test": "CONFIG=abc mocha --reporter spec"
},
...



app.js

console.log(process.env.CONFIG)  //abc

2016年7月5日 星期二

google storage nodejs 上傳教學

最近在整合 node server 檔案上傳到google cloud storage , 發現可以的工具只有 google 官方推出gcloud 工具. 但缺少和前端 檔案上傳 和 ACL 設定, 所以為大家介紹第三方套件, 針對上傳檔案到 google cloud storage 而設計 ,

https://www.npmjs.com/package/gcloud-storage-api



  • 提供3個google cloud storage 檔案的function , 

前2個上傳function, uploadLocalFile 和 uploadBuffer 而且設定為public link 下載, 以 formidable 方式 獲得multipart 檔案和 json:
  • googleAPI.uploadLocalFile(BUCKET_NAME, fileName, fileLocalPath)
  • googleAPI.uploadBuffer(BUCKET_NAME, fileName, buffer)
  • googleAPI.deleteStorageFile(url)



  • 安裝:

$ npm install --save gcloud-storage-api



  • 使用:

service-key 和 account  的設定可以參考官方教學:

https://www.npmjs.com/package/gcloud


1- 到google cloud console 中新增 Credentials, 選 service account key



2- key 類型選 JSON , 檔案下載請放到nodejs 的目錄底下


3- 成功下載的service-key.json 

4- service-key.json 的內容如下
{
  "private_key_id": "******",
  "private_key": "******",
  "client_email": "******",
  "client_id": "******",
  "type": "service_account"
}

5- node_modules/gcloud-upload-api 有一個測試用的html 檔案, 可以用作測試












google storage nodejs 上傳教學

最近在整合 node server 檔案上傳到google cloud storage , 發現可以的工具只有 google 官方推出gcloud 工具. 但缺少和前端 檔案上傳 和 ACL 設定, 所以為大家介紹第三方套件, 針對上傳檔案到 google cloud storage 而設計 ,

https://www.npmjs.com/package/gcloud-storage-api



  • 提供3個google cloud storage 檔案的function , 

前2個上傳function, uploadLocalFile 和 uploadBuffer  是以 formidable 方式 獲得multipart 檔案和 json:

  • googleAPI.uploadLocalFile(BUCKET_NAME, fileName, fileLocalPath)
  • googleAPI.uploadBuffer(BUCKET_NAME, fileName, buffer)
  • googleAPI.deleteStorageFile(url)



  • 安裝:

$ npm install --save gcloud-storage-api



  • 使用:

service-key 和 account  的設定可以參考官方教學:

https://www.npmjs.com/package/gcloud


1- 到google cloud console 中新增 Credentials, 選 service account key



2- key 類型選 JSON , 檔案下載請放到nodejs 的目錄底下


3- 成功下載的service-key.json 

4- service-key.json 的內容如下
{
  "private_key_id": "******",
  "private_key": "******",
  "client_email": "******",
  "client_id": "******",
  "type": "service_account"
}

5- node_modules/gcloud-upload-api 有一個測試用的html 檔案, 可以用作測試












2016年4月6日 星期三

nodejs, host, web, simple, connect, serve-static


npm install -save connect serve-static



app.js

var connect = require('connect'),
    serveStatic = require('serve-static');

var app = connect();

app.use(serveStatic("./"));
app.listen(3000);


node app