Proxy server with go context, go cache

proxy-tut

1. 프록시 서버의 기능

  • 클라이언트에게 요청이 오면 캐시되었는지 확인한후, 캐시되어있다면 본서버로 요청을 보내지 않고 데이터를 내려줍니다.
  • 동일한 요청이 여러개 들어올 시(본서버에서 응답을 받기전이라 캐시되지 않은경우) 동일한 요청은 본서버에 한번만 보내고 나머지 요청은 블락시키고 응답을 받으면 공유하여 내려줍니다.

2. 캐시 저장소 구성 및 저장규칙

  • CacheRepository
    go cache를 사용하여 관리하여 본서버에서 데이터를 받으면 1분간 데이터를 캐시합니다. 캐시를 저장하느라 클라이언트에게 데이터를 늦게 주면 안되므로 저장로직은 고루틴(스레드)으로 돌아갑니다. 스케일 아웃을 고려한다면 구현체로 global nosql을 사용합니다.

  • TemporaryRepository
    동일한 요청이 본서버의 응답을 받았다면 데이터가 캐시되어있겠지만, 본서버에서 응답이 오기전(캐시하기전) 동일한 요청이 또 들어왔을때를 처리하기 위함입니다. (본서버에서 응답을 내려주는데 1초가 걸린다면 1초안에 온 100개의 동일한 요청은 본서버에 들어갈 필요 x) 본서버에 들어간 요청과 동일한 요청은 block시킨후 하나의 응답이 오면 모두 response를 내려줍니다. 본서버에서 응답이 오면 고루틴(스레드)를 사용하여 데이터를 캐시하므로 고루틴이 돌기전 들어온 동일한 요청의 데이터를 캐시(2초간)하는 역할도 포함됩니다.

3. output

프록시서버: [hello] 요청을 본서버에 보냈습니다. 2초동안 동일한 요청은 본서버에 보내지 않습니다 
프록시서버: [hello] 요청은 이미 본서버에 보낸 요청입니다. 응답이 오면 동일한 결과를 내립니다. 
프록시서버: [hello] 요청은 이미 본서버에 보낸 요청입니다. 응답이 오면 동일한 결과를 내립니다. 
본서버: [hello] 요청을 받았습니다 결과값을 내려줍니다. 
클라이언트: 결과 데이터: world
클라이언트: 결과 데이터: world
클라이언트: 결과 데이터: world
서버: 본서버에서 response가 왔으므로 {hello: world}의 데이터를 캐시합니다
프록시서버: [hello]는 캐시되어있으므로 [world]를 내려줍니다
클라이언트: 결과 데이터: world
프록시서버: [hello]는 캐시되어있으므로 [world]를 내려줍니다
클라이언트: 결과 데이터: world
Similar Resources

HTTP cache server, such as varnish

HTTP cache server, such as varnish

pike 与varnish类似的HTTP缓存服务器,主要的特性如下: 提供WEB的管理配置界面,简单易上手 支持br与gzip两种压缩方式,根据客户端自动选择。对于可缓存与不可缓存请求使用不同的压缩配置,更佳的时间与空间的平衡 仅基于Cache-Control生成缓存有效期,接口缓存完全由接口开发者

Dec 17, 2022

gRPC LRU-cache server and client with load test

gRPC k-v storage with LRU-cache server & client + load test. Specify LRU-cache capacity: server/cmd/app.go - StorageCapacity go build ./server/cmd/*

Dec 26, 2021

A secure image proxy server

go-camo Contents About How it works Differences from Camo Installing pre-built binaries Building Running Running on Heroku Securing an installation Co

Jan 7, 2023

A fast reverse proxy to help you expose a local server behind a NAT or firewall to the internet.

A fast reverse proxy to help you expose a local server behind a NAT or firewall to the internet.

frp README | 中文文档 What is frp? frp is a fast reverse proxy to help you expose a local server behind a NAT or firewall to the Internet. As of now, it s

Jan 5, 2023

Simple edge server / reverse proxy

reproxy Reproxy is simple edge HTTP(s) sever / reverse proxy supporting various providers (docker, static, file). One or more providers supply informa

Dec 29, 2022

Smocker is a simple and efficient HTTP mock server and proxy.

Smocker is a simple and efficient HTTP mock server and proxy.

Smocker (server mock) is a simple and efficient HTTP mock server. The documentation is available on smocker.dev. Table of contents Installation With D

Jan 7, 2023

A deployable proxy server and tunnel written in go

Tunnelify Tunnelify is a deployable proxy server and tunnel written in go Installing | Quickstart | Configuration Installing Direct download You can i

Dec 11, 2022

4chain is a simple、fast reverse proxy to help you expose a local server behind a NAT or firewall to the Internet.

4Chain What is 4chain? 4chain is a simple、fast reverse proxy to help you expose a local server behind a NAT or firewall to the Internet. Using the ssh

Nov 1, 2022
Related tags
Tcp-proxy - A dead simple reverse proxy server.

tcp-proxy A proxy that forwords from a host to another. Building go build -ldflags="-X 'main.Version=$(git describe --tags $(git rev-list --tags --max

Jan 2, 2022
Open Source HTTP Reverse Proxy Cache and Time Series Dashboard Accelerator
Open Source HTTP Reverse Proxy Cache and Time Series Dashboard Accelerator

Trickster is an HTTP reverse proxy/cache for http applications and a dashboard query accelerator for time series databases. Learn more below, and chec

Jan 2, 2023
“Dear Port80” is a zero-config TCP proxy server that hides SSH connection behind a HTTP server!

Dear Port80 About The Project: “Dear Port80” is a zero-config TCP proxy server that hides SSH connection behind a HTTP server! +---------------------

Jun 29, 2022
An experimental Tor-Proxy serivce written in Go using Go-proxy and Go-libtor.

tor-proxy An experimental standalone tor-proxy service built with Go, using go-proxy, go-libtor and bine. This is a simple replacement to Tor's origin

Nov 9, 2022
mt-multiserver-proxy is a reverse proxy designed for linking multiple Minetest servers together

mt-multiserver-proxy mt-multiserver-proxy is a reverse proxy designed for linking multiple Minetest servers together. It is the successor to multiserv

Nov 17, 2022
A simple tool to convert socket5 proxy protocol to http proxy protocol

Socket5 to HTTP 这是一个超简单的 Socket5 代理转换成 HTTP 代理的小工具。 如何安装? Golang 用户 # Required Go 1.17+ go install github.com/mritd/s2h@master Docker 用户 docker pull m

Jan 2, 2023
IP2Proxy Go package allows users to query an IP address to determine if it was being used as open proxy, web proxy, VPN anonymizer and TOR exits.

IP2Proxy Go Package This package allows user to query an IP address if it was being used as VPN anonymizer, open proxies, web proxies, Tor exits, data

Sep 15, 2022
Proxy - Minimalistic TCP relay proxy.

Proxy Minimalistic TCP relay proxy. Installation ensure you have go >= 1.17 installed clone the repo cd proxy go install main.go Examples Listen on po

May 22, 2022
Http-logging-proxy - A HTTP Logging Proxy For Golang

http-logging-proxy HTTP Logging Proxy Description This project builds a simple r

Aug 1, 2022
Battlesnake-logging-proxy - A little proxy between the internet and your battlesnake

battlesnake-logging-proxy a little proxy between the internet and your battlesna

Feb 11, 2022