Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support memory cache #166

Merged
merged 3 commits into from
Jul 3, 2023
Merged

Support memory cache #166

merged 3 commits into from
Jul 3, 2023

Conversation

wchaws
Copy link
Owner

@wchaws wchaws commented Jul 2, 2023

Issue #, if available:

Fix: #167

Description of changes:

Support the following env to control cache behavior.

{
  "env": {
    "CACHE_TTL_SEC": "300",  // The cache ttl in seconds, Note that stale items are NOT preemptively removed by default. https://github.com/isaacs/node-lru-cache#ttl
    "CACHE_MAX_ITEMS": "10000", // The max cached keys count.
    "CACHE_MAX_SIZE_MB": "1024" // The max cached size in mb.
  }
}

If cache hit, the HTTP response will contain: X-Cached-Response: HIT

To check cached info: curl <endpoint>/debug and check logs(use CloudWatch filter expr { $.os.arch != "" }) in CloudWatch Logs. You will find something like below

{
    "os": {
        "arch": "x64",
        "cpus": 4,
        "loadavg": [
            12.23,
            9.71,
            7.15
        ]
    },
    "memory": {
        "stats": "free: 11.17 GB, total: 15.16 GB, usage 26.31 %",
        "free": 11995893760,
        "total": 16278593536,
        "usage": {
            "rss": 3009978368,
            "heapTotal": 43941888,
            "heapUsed": 21216176,
            "external": 747442337,
            "arrayBuffers": 502518701
        }
    },
    "resource": {
        "usage": {
            "userCPUTime": 10773049374,
            "systemCPUTime": 1577877281,
            "maxRSS": 4900488,
            "sharedMemorySize": 0,
            "unsharedDataSize": 0,
            "unsharedStackSize": 0,
            "minorPageFault": 501239508,
            "majorPageFault": 3166,
            "swappedOut": 0,
            "fsRead": 0,
            "fsWrite": 25328,
            "ipcSent": 0,
            "ipcReceived": 0,
            "signalsCount": 0,
            "voluntaryContextSwitches": 15725288,
            "involuntaryContextSwitches": 10475948
        }
    },
    "sharp": {
        "cache": {
            "memory": {
                "current": 1899,
                "high": 2346,
                "max": 2000
            },
            "files": {
                "current": 0,
                "max": 200
            },
            "items": {
                "current": 519,
                "max": 1000
            }
        },
        "simd": true,
        "counters": {
            "queue": 0,
            "process": 4
        },
        "concurrency": 4,
        "versions": {
            "aom": "3.5.0",
            "cairo": "1.17.6",
            "cgif": "0.3.0",
            "exif": "0.6.24",
            "expat": "2.5.0",
            "ffi": "3.4.4",
            "fontconfig": "2.14.1",
            "freetype": "2.12.1",
            "fribidi": "1.0.12",
            "gdkpixbuf": "2.42.10",
            "glib": "2.74.1",
            "gsf": "1.14.50",
            "harfbuzz": "5.3.1",
            "heif": "1.13.0",
            "imagequant": "2.4.1",
            "lcms": "2.14",
            "mozjpeg": "4.1.1",
            "orc": "0.4.33",
            "pango": "1.50.11",
            "pixman": "0.42.2",
            "png": "1.6.38",
            "proxy-libintl": "0.4",
            "svg": "2.55.1",
            "spng": "0.7.2",
            "tiff": "4.4.0",
            "vips": "8.13.3",
            "webp": "1.2.4",
            "xml": "2.10.3",
            "zlib-ng": "2.0.6"
        }
    },
    "lruCache": {  // HERE
        "keys": 10000,
        "sizeMB": 685.03,
        "ttlSec": 300
    }
}

Checklist

  • 👋 I have run the unit tests, and all unit tests have passed.
  • ⚠️ This pull request might incur a breaking change.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@wchaws wchaws merged commit 3400f78 into master Jul 3, 2023
2 checks passed
@wchaws wchaws deleted the dev branch July 3, 2023 08:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support in-memory cache for ecs architecture
1 participant