Skip to content

Commit

Permalink
update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
malwaredllc committed May 24, 2022
1 parent f605e64 commit 3ac7e29
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 39 deletions.
70 changes: 37 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ $ go test -v main_test.go
```
# docker run --network minicache_default cacheclient
...
cache_client_docker_test.go:95: Time to complete 10k puts via REST API: 8.6985474s
client_docker_test.go:95: Time to complete 10k puts via REST API: 8.6985474s
```

**Result**: 1150 puts/second
Expand Down Expand Up @@ -257,24 +257,28 @@ In the example below:
- `RELATIVE_CONFIG_PATH` is the path to the JSON config file containing the initial node information, discussed [here](https://github.com/malwaredllc/minicache#set-up-and-usage)

```go
// start servers
// set up parameters for servers
capacity := 100
verbose := false
abs_cert_dir, _ := filepath.Abs(RELATIVE_CERT_DIR)
abs_config_path, _ := filepath.Abs(RELATIVE_CONFIG_PATH)
insecure := false
absCertDir, _ := filepath.Abs(RELATIVE_CLIENT_CERT_DIR)
absConfigDir, _ := filepath.Abs(RELATIVE_CONFIG_PATH)
shutdownChan := make(chan bool, 1)

// start servers defined in config file
components := server.CreateAndRunAllFromConfig(capacity, absConfigDir, verbose, insecure)

components := server.CreateAndRunAllFromConfig(capacity, abs_config_path, verbose)

...

// cleanup
for _, srv_comps := range components {
srv_comps.GrpcServer.Stop()
for _, srv := range components {
srv.GrpcServer.Stop()

ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
defer cancel()

if err := srv_comps.HttpServer.Shutdown(ctx); err != nil {
if err := srv.HttpServer.Shutdown(ctx); err != nil {
t.Logf("Http server shutdown error: %s", err)
}
}
Expand All @@ -287,64 +291,64 @@ From [main.go](https://github.com/malwaredllc/minicache/blob/main/main.go)
```go
func main() {
// parse arguments
grpc_port := flag.Int("grpc-port", 5005, "port number for gRPC server to listen on")
grpcPort := flag.Int("grpc_port", 5005, "port number for gRPC server to listen on")
capacity := flag.Int("capacity", 1000, "capacity of LRU cache")
client_auth := flag.Bool("client-auth", true, "require client authentication (used for mTLS)")
https_enabled := flag.Bool("https-enabled", true, "enable HTTPS for server-server and client-server communication. Requires TLS certificates in /certs directory.")
config_file := flag.String("config", "", "filename of JSON config file with the info for initial nodes")
rest_port := flag.Int("rest-port", 8080, "enable REST API for client requests, instead of just gRPC")
clientAuth := flag.Bool("enable_client_auth", true, "require client authentication (used for mTLS)")
httpsEnabled := flag.Bool("enable_https", true, "enable HTTPS for server-server and client-server communication. Requires TLS certificates in /certs directory.")
configFile := flag.String("config", "", "filename of JSON config file with the info for initial nodes")
restPort := flag.Int("rest_port", 8080, "enable REST API for client requests, instead of just gRPC")
verbose := flag.Bool("verbose", false, "log events to terminal")

flag.Parse()

// set up listener TCP connectiion
listener, err := net.Listen("tcp", fmt.Sprintf(":%d", *grpc_port))
listener, err := net.Listen("tcp", fmt.Sprintf(":%d", *grpcPort))
if err != nil {
panic(err)
}

// get new grpc id server
grpc_server, cache_server := server.NewCacheServer(
grpcServer, cacheServer := server.NewCacheServer(
*capacity,
*config_file,
*configFile,
*verbose,
server.DYNAMIC,
*https_enabled,
*client_auth,
*httpsEnabled,
*clientAuth,
)

// run gRPC server
cache_server.LogInfoLevel(fmt.Sprintf("Running gRPC server on port %d...", *grpc_port))
go grpc_server.Serve(listener)
cacheServer.LogInfoLevel(fmt.Sprintf("Running gRPC server on port %d...", *grpcPort))
go grpcServer.Serve(listener)

// register node with cluster
cache_server.RegisterNodeInternal()
cacheServer.RegisterNodeInternal()

// run initial election
cache_server.RunElection()
cacheServer.RunElection()

// start leader heartbeat monitor
go cache_server.StartLeaderHeartbeatMonitor()
go cacheServer.StartLeaderHeartbeatMonitor()

// run HTTP server
cache_server.LogInfoLevel(fmt.Sprintf("Running REST API server on port %d...", *rest_port))
http_server := cache_server.RunAndReturnHTTPServer(*rest_port)
cacheServer.LogInfoLevel(fmt.Sprintf("Running REST API server on port %d...", *restPort))
httpServer := cacheServer.RunAndReturnHTTPServer(*restPort)

// set up shutdown handler and block until sigint or sigterm received
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt, syscall.SIGTERM, syscall.SIGINT)
go func() {
<-c

cache_server.LogInfoLevel("Shutting down gRPC server...")
grpc_server.Stop()
cacheServer.LogInfoLevel("Shutting down gRPC server...")
grpcServer.Stop()

cache_server.LogInfoLevel("Shutting down HTTP server...")
cacheServer.LogInfoLevel("Shutting down HTTP server...")
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
defer cancel()

if err := http_server.Shutdown(ctx); err != nil {
cache_server.LogInfoLevel("Http server shutdown error: %s", err)
if err := httpServer.Shutdown(ctx); err != nil {
cacheServer.LogInfoLevel(fmt.Sprintf("Http server shutdown error: %s", err))
}
os.Exit(0)
}()
Expand All @@ -357,12 +361,12 @@ func main() {
### Example 4: Creating and Using a Cache Client

In the example below:
- `abs_cert_dir` is the directory containing TLS certificates you generated [here](https://github.com/malwaredllc/minicache#set-up-and-usage)
- `abs_config_path` is the path to the JSON config file containing the initial node information, discussed [here](https://github.com/malwaredllc/minicache#set-up-and-usage)
- `absCertDir` is the directory containing TLS certificates you generated [here](https://github.com/malwaredllc/minicache#set-up-and-usage)
- `absConfigDir` is the path to the JSON config file containing the initial node information, discussed [here](https://github.com/malwaredllc/minicache#set-up-and-usage)

```go
// start client
c := cache_client.NewClientWrapper(abs_cert_dir, abs_config_path, insecure, verbose)
c := client.NewClientWrapper(absCertDir, absConfigDir, insecure, verbose)
c.StartClusterConfigWatcher()

...
Expand Down
12 changes: 6 additions & 6 deletions client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ func Test10kRestApiPuts(t *testing.T) {
// set up parameters for client
insecure := false
verbose := false
abs_cert_dir, _ := filepath.Abs(RELATIVE_CLIENT_CERT_DIR)
abs_config_path, _ := filepath.Abs(RELATIVE_CONFIG_PATH)
absCertDir, _ := filepath.Abs(RELATIVE_CLIENT_CERT_DIR)
absConfigDir, _ := filepath.Abs(RELATIVE_CONFIG_PATH)
shutdown_chan := make(chan bool, 1)

// start client
c := NewClientWrapper(abs_cert_dir, abs_config_path, insecure, verbose)
c := NewClientWrapper(absCertDir, absConfigDir, insecure, verbose)
c.StartClusterConfigWatcher(shutdown_chan)

var wg sync.WaitGroup
Expand Down Expand Up @@ -62,12 +62,12 @@ func Test10kGrpcPuts(t *testing.T) {
// set up parameters for client
insecure := false
verbose := false
abs_cert_dir, _ := filepath.Abs(RELATIVE_CLIENT_CERT_DIR)
abs_config_path, _ := filepath.Abs(RELATIVE_CONFIG_PATH)
absCertDir, _ := filepath.Abs(RELATIVE_CLIENT_CERT_DIR)
absConfigDir, _ := filepath.Abs(RELATIVE_CONFIG_PATH)
shutdown_chan := make(chan bool, 1)

// start client
c := NewClientWrapper(abs_cert_dir, abs_config_path, insecure, verbose)
c := NewClientWrapper(absCertDir, absConfigDir, insecure, verbose)
c.StartClusterConfigWatcher(shutdown_chan)

var wg sync.WaitGroup
Expand Down

0 comments on commit 3ac7e29

Please sign in to comment.