Perlba...ernals(3pm)
β¨ NAME β¨
okay bestie, so this is Perlbal::Manual::Internals(3pm) and it's literally Perlbal's architecture at a glance π. like, the whole vibe is "here's how Perlbal works inside, fr fr." no cap.
πΈ VERSION πΈ
Perlbal 1.78. π periodt.
π DESCRIPTION π
Connections come in from wherever and get to the TCPListener. It uses Service objects to determine what kind of Client* to spawn. The Client classes then handle crafting the response for the user. it's giving main character energy, lowkey.
{{ INTERNET }}
|
v
[Service]<===>[TCPListener]
___/ | \___
v v v
[ClientManage] [ClientHTTP] [ClientProxy]
^
|
v
[BackendHTTP]
Perlbal decides what backend to send a request to randomly (only presently supported method). If that service has idle backend connections available, configured by backend_persist and connect_ahead, it will reuse those connections and greatly reduce latency. See more detail in Perlbal::Manual::LoadBalancer. highkey iconic.
Perlbal also specializes in "spoonfeeding" data to slow clients. This allows backends to continue serving requests while Perlbal transfers responses back as fast as the client can read. π₯β¨ obsessed.
π¦ Classes π¦
The following is a brief introduction/overview to the main Perlbal's classes:
Perlbal::Socket
Descends from Danga::Socket.
Adds on to the base class to provide some functionality specifically useful for creating HTTP sockets.
β¨ Fields β¨
headers_stringβ Headers as they're being read. π periodt.req_headersβ The finalPerlbal::HTTPHeadersobject inbound. no cap.res_headersβ Response headers outbound (Perlbal::HTTPHeadersobject). slay.create_timeβ Creation time. β° it's giving timestamp.alive_timeβ Last time noted alive. πstateβ General purpose state; used by descendants. lowkey important.do_dieβ If on, die and do no further requests. π not me dying.read_bufβ Arrayref of scalarref read from client. πΌread_aheadβ Bytes sitting inread_buf.read_sizeβ Total bytes read from client, ever.ditch_leading_rnβ If true, the next header parsing will ignore a leading\r\n.observed_ip_stringβ If defined, contains the observed IP string of the peer we're serving. This is intended for holding the value of theX-Forwarded-Forand using it to govern ACLs. iykyk.
Perlbal::TCPListener
Descends from Perlbal::Socket.
Very lightweight and fast connection accept class. Takes incoming connections as fast as possible and passes them off, instantiating one of the various Client* classes to handle it. it's giving speed demon.
β¨ Fields β¨
serviceβPerlbal::Service.hostportβ Scalar IP port of where this service is listening for new connections.ssloptsβ The SSL Options.
use Data::Dumper;
warn Dumper( $tcp_listener->{'sslopts'} );
The above lines would print something like the following:
$VAR1 = {
'ssl' => {
'SSL_cipher_list' => '...',
'SSL_cert_file' => '...',
'SSL_key_file' => ',,,',
'SSL_ca_path' => '...',
'SSL_verify_mode' => '...'
}
};
v6β Boolean value stating whether the installation of Perlbal supports IPv6 (which basically boils down toDanga::Socketv1.6.1 andIO::Socket::INET6being available). π
Perlbal::BackendHTTP
Descends from Perlbal::Socket.
This class handles connections to the backend web nodes for getting data back to the user. This class is used by other classes such as Perlbal::ClientProxy to send a request to an internal node. it's giving middleman energy.
β¨ Fields β¨
clientβPerlbal::ClientProxyconnection, orundef.serviceβPerlbal::Service.poolβPerlbal::Pool; whatever pool we spawned from.ipβ IP scalar.portβ Port scalar.ipportβ"$ip:$port".reporttoβ Object; must implement reporter interface.has_attentionβ Has been accepted by a webserver and we know for sure we're not just talking to the TCP stack. πwaiting_optionsβ If true, we're waiting for anOPTIONS *response to determine when we have attention.disconnect_atβ Time this connection will be disconnected, if it's kept-alive and backend told us; otherwiseundeffor unknown.content_lengthβ Length of document being transferred. Only applies when the backend server sends a content-length header.content_length_remainβ Bytes remaining to be read. Only applies when the backend server sends a content-length header.use_countβ Number of requests this backend's been used for.generationβ Int; counts what generation we were spawned in.buffered_upload_modeβ Boolean. If on, we're doing a buffered upload transmit.scratchβ Extra storage; plugins can use it if they want. π§
Perlbal::HTTPHeaders
Header management. Parses headers (request and response) and stores data for further user. Also manages validation of the request line so that it conforms to HTTP specifications. it's giving strict teacher vibes.
β¨ Fields β¨
headersβ href; lowercase header -> comma-sep list of values.origcaseβ Href; lowercase header -> provided case.hdorderβ Aref; order headers were received (canonical order).methodβ Scalar; request method (if GET request).uriβ Scalar; request URI (if GET request).typeβ"res"or"req".codeβ HTTP response status code.codetextβ Status text that for response code.verβ Version (string)"1.1".vernumβ Version (number: major*1000+minor):"1.1"=> 1001.responseLineβ First line of HTTP response (if response).requestLineβ First line of HTTP request (if request).
Perlbal::ClientHTTPBase
Descends from Perlbal::Socket.
Provides base functionality to Perlbal::ClientHTTP and Perlbal::ClientProxy. Notably, the ability to efficiently send files to the remote user. Also handles most of the state logic for statistics and such. Is also used for services of type "selector". Perlbal::ClientHTTPBase then reads in the request headers, and asks the service to re-bless the client instance to a more specific type, for either a Perlbal::ClientProxy or a Perlbal::ClientHTTP (depending on selector's mapping). it's giving base class realness.
β¨ Fields β¨
serviceβPerlbal::Serviceobject.replacement_uriβ URI to send instead of the one requested; this is used to instruct"_serve_request"to send an index file instead of trying to serve a directory and failing.scratchβ Extra storage; plugins can use it if they want.reproxy_fileβ Filename the backend told us to start opening.reproxy_file_sizeβ Size of file, once we"stat()"it.reproxy_fhβ If needed,IO::Handleof fd.reproxy_file_offsetβ How much we've sent from the file.post_sendfile_cbβ Subref to run after we're done sendfile'ing the current file.requestsβ Number of requests this object has performed for the user.selector_svcβ The original service from which we came.is_sslβ Whether the socket was SSL attached (restricted operations). π
Perlbal::ClientHTTP
Descends from Perlbal::ClientHTTPBase.
Very simple and lightweight class. Handles sending files to the user without much overhead. Most of the functionality is contained in the parent class, and this class doesn't implement much new stuff. it's giving minimal effort, maximum slay.
β¨ Fields β¨
put_in_progressβ 1 when we're currently waiting for an async job to return.put_fhβ File handle to use for writing data.put_fh_filenameβ Filename ofput_fh.put_posβ File offset to write next data at.content_lengthβ Length of document being transferred.content_length_remainβ Bytes remaining to be read.chunked_upload_stateβ Boolean/obj: if processing a chunked upload,Perlbal::ChunkedUploadStateobject, else undef.
Perlbal::ClientProxy
Descends from Perlbal::ClientHTTPBase.
Takes an incoming connection from a user and connects to a backend node ("Perlbal::BackendHTTP") and relays the request. The backend can then either tell the proxy to reproxy and load a file from disk, or return a file directly, or just return a status message. it's giving messenger of the group chat.
β¨ Fields β¨
backendβPerlbal::BackendHTTPobject (or"undef"if disconnected).backend_requestedβ True if we've requested a backend for this request.reconnect_countβ Number of times we've tried to reconnect to backend.high_priorityβ Boolean; 1 if we are or were in the high priority queue.low_priorityβ Boolean; 1 if we are or were in the low priority queue.reproxy_urisβ Arrayref; URIs to reproxy to, in order.reproxy_expected_sizeβ Int: size of response we expect to get back for reproxy.currently_reproxyingβ Arrayref; the host info and URI we're reproxying right now.content_length_remainβ Int: amount of data we're still waiting for.respondedβ Bool: whether we've already sent a response to the user or not.last_request_timeβ Int: time that we last received a request.primary_res_hdrsβ If defined, we are doing a transparent reproxy-URI and the headers we get back aren't necessarily the ones we want. Instead, get most headers from the provided"res"headers object here.is_bufferingβ Bool; if we're buffering some/all of a request to memory/disk.is_writingβ Bool; if on, we currently have an"aio_write"out.start_timeβ Hi-res time when we started getting data to upload.bufhβ Buffered upload filehandle object.bufilenameβ String; buffered upload filename.bureasonβ String; if defined, the reason we're buffering to disk.buoutposβ Int; buffered output position.backend_stalledβ Boolean: if backend has shut off its reads because we're too slow.unread_data_waitingβ Boolean: if we shut off reads while we know data is yet to be read from client.chunked_upload_stateβ Bool/obj: if processing a chunked upload,Perlbal::ChunkedUploadStateobject, else undef.request_body_lengthβ Integer: request's body length, either as-declared, or calculated after chunked upload is complete.last_upload_packetβ the unixtime we last sent a UDP upload packet. It's for perlbal sending out UDP packets related to upload status (for the xmlhttprequest upload bar π ).upload_sessionβ the client's self-generated upload session. Again, for perlbal sending out UDP packets related to upload status (for that xmlhttprequest upload bar).retry_countβ number of times we've retried this request so far after getting 500 errors π.
π¦ Perlbal::ClientManage π¦
Descends from Perlbal::Socket.
Okay so this one is a simple interface that gives users a way to use Perlbal's management interface. You can connect to the management port (as defined in the config file) with a web browser or regular telnet β see Perlbal::Manual::Management for more info on all of that π«Ά.
β¨ Fields β¨
serviceβPerlbal::Service.bufβ read buffer.is_httpβ boolean stating whether the request is HTTP.ctxβPerlbal::CommandContext.
π Perlbal::Service π
A service is a particular item that Perlbal is doing. Services can have a role which defines how they behave. Each service can also have a whole bunch of parameters set to further adjust its behavior. By itself, the Service class handles maintaining pools of backend connections and managing statistics about itself π.
π Fields π
nameβ name of the service.roleβ role type ("web_server","reverse_proxy", etc).enabledβ boolean; whether we're enabled or not (enabled = listening).poolβPerlbal::Poolthat we're using to allocate nodes if we're in proxy mode.listenerβPerlbal::TCPListenerobject, when enabled.reproxy_cacheβPerlbal::Cacheobject, when enabled.
π End-user tunables π
listenβ"IP:port"of where we're listening for new connections.docrootβ document root for the"web_server"role.dirindexingβ boolean; directory indexing (for the"web_server"role). Not async, bestie.index_filesβ arrayref of filenames to try for index files.enable_concatenate_getβ boolean; if the user can request concatenated files.enable_putβ boolean; whetherPUTis supported.max_put_sizeβ max size in bytes of a put file.max_chunked_request_sizeβ max size in bytes of a chunked request (to be written to disk first).min_put_directoryβ number of directories required to exist at the beginning of URIs in put.enable_deleteβ boolean; whetherDELETEis supported.high_priority_cookieβ cookie name to check if the client's requests should be considered high priority.
See also "high_priority_cookie_contents".
high_priority_cookie_contentsβ the aforementioned cookie value must contain this substring.backend_persist_cacheβ max number of persistent backends to hold onto while there are no clients.persist_clientβ boolean; persistent connections for clients.persist_backendβ boolean; persistent connections for backends.verify_backendβ boolean; get the attention of the backend before giving it clients (usingOPTIONS).verify_backend_pathβ path to check with theOPTIONSrequest (default is"*").max_backend_usesβ max requests to send per kept-alive backend (default0= unlimited).connect_aheadβ number of spare backends to connect to in advance, all the time.buffer_sizeβ how much data aPerlbal::ClientProxyobject should buffer from a backend.buffer_size_reproxy_urlβ same as above, but for backends that are reproxying for us.queue_relief_sizeβ number of outstanding standard priority connections to activate pressure relief at.queue_relief_chanceβ int,0-100; % chance to take a standard priority request when we're in pressure relief mode.trusted_upstream_proxiesβ array ofNet::Netmaskobjects containing netmasks for trusted upstreams.always_trustedβ boolean; if true, always trust upstreams.blind_proxyβ boolean; if true, do not modifyX-Forwarded-For,X-Host, orX-Forwarded-Hostheaders.enable_reproxyβ boolean; if true, advertise that the server will reproxy files and/or URLs.reproxy_cache_maxsizeβ maximum number of reproxy results to be cached. (0is disabled and is the default).client_sndbuf_sizeβ bytes forSO_SNDBUF.server_processβ path to the server process (executable).persist_client_idle_timeoutβ keep-alive timeout in seconds for clients (default is30).idle_timeoutβ idle timeout outside of keep-alive time (default is30).
π§ Internal state π§
waiting_clientsβ arrayref of clients waiting for backendhttp connections.waiting_clients_highpriβ arrayref of high-priority clients waiting for backendhttp connections.waiting_clients_lowpriβ arrayref of low-priority clients waiting for backendhttp connections.waiting_client_countβ number of clients waiting for backends.waiting_client_mapβ map of clientproxy fd ->1(if they're waiting for a connection).pending_connectsβ hashref of"ip:port"->$time(only one pending connect to a backend at a time).pending_connect_countβ number of outstanding backend connects.bored_backendsβ arrayref of backends we've already connected to, but haven't got clients.hooksβ hashref: hookname => [ [ plugin, ref ], [ plugin, ref ], ... ].pluginsβ hashref: name =>1.plugin_orderβ arrayref: name, name, name...plugin_settersβ hashref:{ plugin_name => { key_name => coderef } }.extra_configβ hashref with extra config options; name => values.spawn_lockβ boolean; if true, we're currently inspawn_backends.extra_headersβ{ insert => [ [ header, value ], ... ], remove => [ header, header, ... ], set => [ [ header, value ], ... ] }.
Used in the header management interface.
generationβ int; generation count so we can slough off backends from old pools.backend_no_spawnβ{ "ip:port" => 1 }.
If on, spawn_backends will ignore this ip:port combo.
buffer_backend_connectβ0if off; otherwise, number of bytes to buffer before we ask for a backend.selectorβCODEref, or undef, for role"selector"services.default_serviceβ name of a service a selector should default to.buffer_uploadsβ boolean; enable/disable the buffered uploads to disk system.buffer_uploads_pathβ path to store buffered upload files.buffer_upload_threshold_timeβ int; buffer uploads estimated to take longer than this.buffer_upload_threshold_sizeβ int; buffer uploads greater than this size (in bytes).buffer_upload_threshold_rateβ int; buffer uploads uploading at less than this rate (in bytes/sec).upload_status_listenersβ comma separated list of"ip:port"of UDP upload status receivers.upload_status_listeners_sockaddrβ arrayref of sockaddrs (packed ip/port).enable_sslβ boolean; whether this service speaks SSL to the client.ssl_key_fileβ file path to key pem file.ssl_cert_fileβ file to path to cert pem file.ssl_cipher_listβ OpenSSL cipher list string.ssl_ca_pathβ path to certificates directory.ssl_verify_modeβ int; verification mode, seeIO::Socket::SSL.enable_error_retriesβ boolean; whether we should retry requests after errors.error_retry_scheduleβ comma-separated seconds (full or partial) to delay between retries.latencyβ milliseconds of latency to add to request.server_tokensβ boolean; whether to provide aServerheader._stat_requestsβ total requests to this service._stat_cache_hitsβ total requests to this service that were served via the reproxy-url cache.
and that's a wrap, bestie π this page is perl v5.34.0, dated 2022-06-28 β so like, it's giving vintage but she still eats π go forth and slay your services πβ¨
π¦ where this page comes from
- debian bookworm: libperlbal-perl 1.80-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libperlbal-perl 1.80-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libperlbal-perl 1.80-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu questing: libperlbal-perl 1.80-4
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms