diff --git a/readme.md b/readme.md index eb295b6..ee06b68 100644 --- a/readme.md +++ b/readme.md @@ -1,10 +1,8 @@ -

- +
+ -npm-cache-proxy -

+

npm-cache-proxy

-

Current Release @@ -14,33 +12,32 @@ npm-cache-proxy Licence -

+ -> `npm-cache-proxy` is a lightweight npm caching proxy written in Go that achieves warp speeds by using Redis for data storage. B-b-blazing fast! +
+
+ +## Introduction + +#### ⚡️ Performance +NCP is a tiny but very fast caching proxy written and Go. It uses Redis for data storage, which in combination with the speed of Go makes it incredibly fast. NCP is well-optimized and can be run on almost any platform, so if you have a Raspberry Pi, you can install NCP as your local cache there. + +#### ✨ Modularity +NCP is modular. Now it has only one database adapter which is Redis. If you need support for any other database, feel free to open an issue or implement it [on your own](https://github.com/emeralt/npm-cache-proxy/blob/7c8b90ff6ba0656f60e3de915b9fb4eaabfb467b/proxy/proxy.go#L29) and then open a pull request (_bonus points_). + +#### 💡 Simplicity +NCP is very simple. It just proxies requests to an upstream registry, caches response and returns cached response for next requests to the same package. Cached data are stored in Redis with an original request URL as a key. -
-Table of Contents -

+
-- [Getting started](#getting-started) -- [CLI](#cli) - - [`ncp`](#ncp) - - [`ncp list`](#ncp-list) - - [`ncp purge`](#ncp-purge) -- [Programmatic usage](#programmatic-usage) - - [Example](#example) -- [Deployment](#deployment) -- [Benchmark](#benchmark) -- [License](#license) -

-
+## Installation +NCP binaries for different paltforms can be downloaded can be downloaded on the [Releases](https://github.com/emeralt/npm-cache-proxy/releases) page. Also, Docker image is provided on [Docker Hub](https://cloud.docker.com/u/emeralt/repository/docker/emeralt/npm-cache-proxy). -## Getting started -Release binaries for different platforms can be downloaded on the [Releases](https://github.com/emeralt/npm-cache-proxy/releases) page. Also, [Docker image](https://cloud.docker.com/u/emeralt/repository/docker/emeralt/npm-cache-proxy) is provided. +#### 💫 Quick Start +The quickies way to get started with NCP is to use Docker. -The fastest way to get started with NCP is to use Docker image: ```bash # run proxy inside of docker container in background docker run -e REDIS_ADDRESS=host.docker.internal:6379 -p 8080:8080 -it -d emeralt/npm-cache-proxy @@ -49,56 +46,90 @@ docker run -e REDIS_ADDRESS=host.docker.internal:6379 -p 8080:8080 -it -d emeral npm config set registry http://localhost:8080 ``` +
+ ## CLI -Additionally, NCP provides a command line utility for proxy configuration and data management. +NCP provides command line interface for interaction with a cached data. ---- +#### `ncp` +Start NCP server. -| Global Options | Env | Default | Description | -| ----------------------------- | ---------------- | ----------------------- | ----------------- | -| `--redis-address
` | `REDIS_ADDRESS` | `http://localhost:6379` | Redis address | -| `--redis-database ` | `REDIS_DATABASE` | `0` | Redis database | -| `--redis-password ` | `REDIS_PASSWORD` | - | Redis password | -| `--redis-prefix ` | `REDIS_PREFIX` | `ncp-` | Redis keys prefix | +
+Options ---- +| Options | Env | Default | Description | +| ----------------------------- | ------------------ | ---------------------------- | ----------------------------------- | +| `--listen
` | `LISTEN_ADDRESS` | `locahost:8080` | Address to listen | +| `--upstream
` | `UPSTREAM_ADDRESS` | `https://registry.npmjs.org` | Upstream registry address | +| `--silent
` | `SILENT` | `0` | Disable logs | +| `--cache-limit ` | `CACHE_LIMIT` | - | Cached packages count limit | +| `--cache-ttl ` | `CACHE_TTL` | `3600` | Cache expiration timeout in seconds | +| `--redis-address
` | `REDIS_ADDRESS` | `http://localhost:6379` | Redis address | +| `--redis-database ` | `REDIS_DATABASE` | `0` | Redis database | +| `--redis-password ` | `REDIS_PASSWORD` | - | Redis password | +| `--redis-prefix ` | `REDIS_PREFIX` | `ncp-` | Redis keys prefix | -### `ncp` +
-Start proxy server. +#### `ncp list` +List cached url paths. + +#### `ncp purge` +Purge cached url paths. + + +
+ + +## Benchmark +Benchmark is run on Macbook Pro 15″ 2017, Intel Core i7-7700HQ. + +#### 1️⃣ 1 process ```bash -ncp --listen "localhost:1234" # listen on port 1234 +# GOMAXPROCS=1 ncp --silent + +$ go-wrk -c 100 -d 6 http://localhost:8080/tiny-tarball +Running 6s test @ http://localhost:8080/tiny-tarball + 100 goroutine(s) running concurrently + +70755 requests in 5.998378587s, 91.16MB read + +Requests/sec: 11795.69 +Transfer/sec: 15.20MB +Avg Req Time: 8.477674ms +Fastest Request: 947.743µs +Slowest Request: 815.787409ms +Number of Errors: 0 ``` -| Options | Env | Default | Description | -| ----------------------- | ------------------ | ---------------------------- | ----------------------------------- | -| `--listen
` | `LISTEN_ADDRESS` | `locahost:8080` | Address to listen | -| `--upstream
` | `UPSTREAM_ADDRESS` | `https://registry.npmjs.org` | Upstream registry address | -| `--cache-limit ` | `CACHE_LIMIT` | - | Cached packages count limit | -| `--cache-ttl ` | `CACHE_TTL` | `3600` | Cache expiration timeout in seconds | -| `--silent
` | `SILENT` | `0` | Disable logs | - ---- - -### `ncp list` -List all cached packages. - ---- - -### `ncp purge` -Purge all cached packages. - ---- - -## Programmatic usage -Along with the CLI, go package is provided. Documentation is available on [godoc.org](https://godoc.org/github.com/emeralt/npm-cache-proxy/proxy). +#### ♾ unlimited processes ```bash -go get -u github.com/emeralt/npm-cache-proxy/proxy +# ncp --silent + +$ go-wrk -c 100 -d 6 http://localhost:8080/tiny-tarball +Running 6s test @ http://localhost:8080/tiny-tarball + 100 goroutine(s) running concurrently + +115674 requests in 5.98485984s, 149.04MB read + +Requests/sec: 19327.77 +Transfer/sec: 24.90MB +Avg Req Time: 5.173902ms +Fastest Request: 273.015µs +Slowest Request: 34.777963ms +Number of Errors: 0 ``` -### Example + +
+ + +## Programmatic Usage +NCP provides `proxy` go package that can be used programmatically. Docs are available on [godoc.org](https://godoc.org/github.com/emeralt/npm-cache-proxy/proxy). + +#### 🤖 Example ```golang package main @@ -141,27 +172,9 @@ func main() { } ``` -## Deployment -NCP can be deployed using Kubernetes, Docker Compose or any other container orchestration platform. NCP supports running indefinite amount of instances simultaneously. -## Benchmark -Macbook Pro 15″ 2017, Intel Core i7-7700HQ. Note `GOMAXPROCS=1`. +
-```bash -# SILENT=1 GIN_MODE=release GOMAXPROCS=1 ncp - -$ go-wrk -c 100 -d 10 http://localhost:8080/ascii -Running 10s test @ http://localhost:8080/ascii - 100 goroutine(s) running concurrently -120227 requests in 9.996788553s, 136.21MB read -Requests/sec: 12026.56 -Transfer/sec: 13.63MB -Avg Req Time: 8.314928ms -Fastest Request: 1.157793ms -Slowest Request: 782.917402ms -Number of Errors: 0 -``` ## License - [MIT](./license)