-
Requests (Last Hour)
-
Blocked Requests
-
Avg Latency (ms)

Top API Keys by Usage

API Key Tier Requests Tokens Used Cost (USD) Status

การทำ Load Balancing หลาย Redis

lua -- /etc/openresty/redis_cluster.lua local redis_cluster = require "resty.redis.cluster" local _M = {} local cluster_config = { name = "ai_ratelimit", startup_nodes = { { ip = "10.0.0.1", port = 6379 }, { ip = "10.0.0.2", port = 6379 }, { ip = "10.0.0.3", port = 6379 } }, connect_timeout = 1000, read_timeout = 1000, send_timeout = 1000, keepalive_timeout = 60000, keepalive_cons = 100, max_redir = 3 } local cluster, err = redis_cluster:new(cluster_config) function _M.incr(key) local count, err = cluster:incr(key) if not count then ngx.log(ngx.ERR, "Redis cluster error: ", err) return 0 end return count end function _M.zadd(key, score, member) local ok, err = cluster:zadd(key, score, member) if not ok then ngx.log(ngx.ERR, "Redis cluster zadd error: ", err) return false end return true end function _M.zcard(key) local count, err = cluster:zcard(key) if not count then return 0 end return count end function _M.zremrangebyscore(key, min, max) local count, err = cluster:zremrangebyscore(key, min, max) if not count then return 0 end return count end return _M

การตั้งค่า Failover และ Circuit Breaker

lua -- /etc/openresty/circuit_breaker.lua local _M = {} local circuits = {} _M.config = { failure_threshold = 5, recovery_timeout = 30, half_open_max_requests = 3 } -- Check if circuit is open function _M.is_open(service) local circuit = circuits[service] if not circuit then return false, nil end if circuit.state == "open" then if ngx.now() - circuit.opened_at > _M.config.recovery_timeout then circuit.state = "half-open" circuit.half_open_requests = 0 return false, circuit end return true, circuit end return false, circuit end -- Record success function _M.record_success(service) local circuit = circuits[service] if circuit and circuit.state == "half-open" then circuit.success_count = (circuit.success_count or 0) + 1 if circuit.success_count >= _M.config.half_open_max_requests then circuit.state = "closed" circuit.failure_count = 0 circuit.success_count = 0 end end end -- Record failure function _M.record_failure(service) if not circuits[service] then circuits[service] = { state = "closed", failure_count = 0, success_count = 0, opened_at = 0 } end local circuit = circuits[service] circuit.failure_count = circuit.failure_count + 1 if circuit.failure_count >= _M.config.failure_threshold then circuit.state = "open" circuit.opened_at = ngx.now() end end return _M

การ Optimize Performance

lua -- /etc/openresty/performance.lua local _M = {} -- L1 cache (Nginx shared dict) _M.l1_cache = ngx.shared.l1_cache -- L2 cache (Lua variable cache for worker) local worker_cache = {} function _M.get(key) -- Try L1 cache first local value = _M.l1_cache:get(key) if value then return value end -- Try L2 cache local cached = worker_cache[key] if cached and cached.expiry > ngx.now() then return cached.value end return nil end function _M.set(key, value, ttl) -- Set L1 cache _M.l1_cache:set(key, value, ttl or 60) -- Set L2 cache worker_cache[key] = { value = value, expiry = ngx.now() + (ttl or 60) } end -- Prefetch popular configs function _M.prefetch_configs(api_keys) for _, key in ipairs(api_keys) do local config = _M.get("config:" .. key) if not config then -- Fetch from Redis in background -- Implementation depends on your setup end end end return _M ```

เหมาะกับใคร / ไม่เหมาะกับใคร

เหมาะกับใคร

- ธุรกิจที่ใช้ AI API หลายตัวพร้อมกัน (Multi-provider) - ทีมที่ต้องการควบคุมค่าใช้จ่ายอย่างเข้มงวด - Startup ที่ต้องการ scale ระบบอย่างรวดเร็ว - ผู้พัฒนาที่ต้องการ latency ต่ำ (<50ms) - ธุรกิจในเอเชียที่ต้องการชำระเงินด้วย WeChat/Alipay

ไม่เหมาะกับใคร

- โปรเจกต์เล็กมากที่มี request น้อยกว่า 1,000 ต่อเดือน - องค์กรที่ต้องการใช้งานผ่าน Azure/GCP marketplace เท่านั้น - ทีมที่ไม่มีท