{"id":18792209,"url":"https://github.com/johto/bladepsgi","last_synced_at":"2025-06-14T15:35:06.948Z","repository":{"id":148506441,"uuid":"75394596","full_name":"johto/BladePSGI","owner":"johto","description":"Expose multiple instances of a PSGI application over a FastCGI socket","archived":false,"fork":false,"pushed_at":"2023-06-22T13:56:57.000Z","size":55,"stargazers_count":1,"open_issues_count":1,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-12-29T15:23:17.660Z","etag":null,"topics":["blade","fastcgi","perl","psgi"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/johto.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-12-02T12:40:10.000Z","updated_at":"2024-11-22T09:11:34.000Z","dependencies_parsed_at":"2024-12-29T15:31:53.865Z","dependency_job_id":null,"html_url":"https://github.com/johto/BladePSGI","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johto%2FBladePSGI","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johto%2FBladePSGI/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johto%2FBladePSGI/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johto%2FBladePSGI/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/johto","download_url":"https://codeload.github.com/johto/BladePSGI/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239718370,"owners_count":19685725,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["blade","fastcgi","perl","psgi"],"created_at":"2024-11-07T21:18:49.494Z","updated_at":"2025-02-19T19:13:50.992Z","avatar_url":"https://github.com/johto.png","language":"C++","readme":"BladePSGI\n=========\n\nIntroduction\n------------\n\nWhile [PSGI](http://plackperl.org) is a nice interface for writing web\napplications, the options available for actually running these applications are\nsomewhat scarce.  _BladePSGI_ was developed when it become apparent that\npatching our custom Perl-based runner was a dead end.\n\n_BladePSGI_ has a process-based architecture, meaning that each instance of the\nPSGI application runs in its own, single-threaded process.  _BladePSGI_ takes\ncare of forking all backends at startup, and then sits in the background making\nsure that none of the backends crash, or shutting them down if the server\nadministrator asks for that to happen.  It also starts a separate monitoring\nprocess which can be used to provide statistics to a separate monitoring\nsystem, e.g. Prometheus.\n\nFor communication with other services, _BladePSGI_ exposes a UNIX domain\nFastCGI socket.  Any (for example) HTTP daemon capable of acting as a FastCGI\nclient can be used to then expose the application to the internet.\n\nIf the PSGI application author chooses they can ask for \"auxiliary processes\"\nto be started and run with the application, expose the status of each backend\nprocess in shared memory, or share semaphores or atomic integers between PSGI\napplication backends.\n\nRequirements\n------------\n\nThe only currently supported platform is Linux.\n\nBuilding the binary requires cmake version 2.8 or later and a C++11 compatible\ncompiler.\n\nThe Plack::Util, FCGI and HTTP::Status Perl modules should also be available on\nthe server(s) that are going to run _BladePSGI_.\n\nHow to build\n------------\n\n```\ngit clone https://github.com/johto/BladePSGI.git\ncd BladePSGI\ncmake .\nmake\n```\n\nYou should now have a binary called \"bladepsgi\", which you can run normally.\n\nLoaders\n-------\n\nThe command-line argument --loader can be used to specify a Perl module\ncallback which is called once in the spawner process before the backends are\nforked.  The only passed argument is an object which can be used to ask the\nrunner for different facilities, documented below.  The loader subroutine\nshould return two values: a hashref which will be merged into the PSGI\nenvironment on every call to the PSGI application, and a subroutine for the\nPSGI application itself.\n\nThe passed-in object has the following methods:\n\n##### set\\_worker\\_status(status)\n\nExpects a single octet as an argument, which will be the new status of the\ncurrent backend process.  This method should only be called from the PSGI\napplication, and never from the loader!\n\n##### psgi\\_application\\_path()\n\nThe APPLICATION\\_PATH passed to _BladePSGI_ on the command line.  Only useful\nfor knowing where to load the application from in the loader subroutine.\n\n##### request\\_auxiliary\\_process(name, subr)\n\nRequests an auxiliary subprocess with the provided name to be started that\nlives with the application backends.  The process, once started, calls the\nprovided subroutine, which should never return.\n\n##### new\\_semaphore(name, initvalue)\n\nRequests a new shared semaphore with the provided name and initial value.  The\nreturn value is an object which provides the following methods:\n\n   + acquire(): If the current value of the semaphore is larger than zero, decreases the value by one and returns.  Otherwise waits for the value to become larger than zero, then decreases the value by one, and returns.\n\n  + tryacquire(): If the current value of the semaphore is larger than zero, decreases the value by one and returns TRUE.  Otherwise returns FALSE.\n\n  + release(): Increases the current value of the semaphore by one.\n\n##### new\\_atomic\\_int64(name, initvalue)\n\nRequests a new shared atomic 64-bit integer with the provided name and initial\nvalue.  The return value is an object which provides the following methods:\n\n  + incr(): Increases the current value by one.\n\n  + fetch\\_add(val): Increases the current value by _val_ and returns the value\n  before the operation.\n\n  + load(): Returns the current value.\n\n  + store(val): Stores the provided value into the integer.\n\nLoader example\n--------------\n\nYour final loader code might look something like the following:\n\n```Perl\npackage MyBladePSGILoader;\n\nuse strict;\nuse warnings;\n\nuse Plack::Util;\n\nmy $loader = sub {\n    my $bladepsgi = shift;\n\n    my $handle = MyAPIHandle-\u003enew();\n    $handle-\u003eload_configuration_file();\n    my $worker_status_setter = sub {\n        $bladepsgi-\u003eset_worker_status($_[0]);\n    };\n    $handle-\u003eset_worker_status_setter($worker_status_setter);\n    $handle-\u003eset_db_deadlock_counter($bladepsgi-\u003enew_atomic_int64('db_deadlock_counter', 0));\n\n    my $env = {\n        'myapix.handle' =\u003e $handle,\n    };\n    return $env, Plack::Util::load_psgi($bladepsgi-\u003epsgi_application_path());\n};\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjohto%2Fbladepsgi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjohto%2Fbladepsgi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjohto%2Fbladepsgi/lists"}