---
# System prepended metadata

title: Code Doc

---

# Code Doc 
* ### server/Makefile
    >makefile為一種文件，通常裡面定義了一些指令來編譯，鏈結，設定環境等等。
    
    目前指令
    * create_db
        使用docker run來執行mongoDB
    * remove_db
        將create_db生出來的container rm掉
* ### server/.env (不會出現在git，請自行複製)
    >負責存儲一些重要的變數
```
DATABASE_URL=mongodb://localhost:27017
REDIS_ADDR=localhost:6379
CLOUDINARY_URL=cloudinary://997846618742551:Lsoo_LvRkQVqnoKwF95NvDXkZMk@ddrpscnwc
GIN_MODE=release
```


* ### server/internal/cron/.env
    >負責存儲一些本地執行cron job需要的環境變數
```
DATABASE_URL=mongodb://localhost:27017
CLOUDINARY_URL=cloudinary://997846618742551:Lsoo_LvRkQVqnoKwF95NvDXkZMk@ddrpscnwc

```


`docker pull grafana/k6`
```

import http from "k6/http";
import { sleep } from "k6";
import { check } from 'k6';
import { Rate, Trend } from "k6/metrics";
//docker run --rm -i grafana/k6 run - <load.js

// Define custom metrics
//const failedRequests = new Rate("failed_requests");
//const requestsPerSecond = new Trend("requests_per_second");

export const options = {
  stages: [
    { duration: '10s', target: 200 },
    { duration: '100s', target: 200 },
    { duration: '10s', target: 100}
  ],
};
// export const options = {
//   vus: 2000,
//   duration: '10s',
//   rps: 120
// };
export const sameImage = false
export default function () {
  const url = "https://randomcat.io/api/image?w=100&h=170";
  const res = http.get(url);
  check(res, { 'status was 200': (r) => r.status == 200 });
  //sleep(1);
}
```
# Testing
    http_req_receiving.............: avg=4.96ms   min=90.25µs  med=1.51ms   max=225ms    p(90)=13.69ms p(95)=19.42ms 

    http_req_receiving.............: avg=408.6ms  min=0s       med=3.3ms    max=52.3s  p(90)=104.55ms p(95)=2.04s
    http_req_duration..............: avg=3.39s    min=0s       med=3.52s    max=1m0s   p(90)=6.14s    p(95)=8.3s
