about summary refs log tree commit homepage
path: root/lib
DateCommit message (Collapse)
2024-03-23treewide: future-proof frozen_string_literal changes
Once again Ruby seems ready to introduce more incompatibilities and force busywork upon maintainers[1]. In order to avoid incompatibilities in the future, I used the following Perl script to prepend `frozen_string_literal: false' to every Ruby file: use v5.12; use autodie; my $usage = 'perl /path/to/script <LIST_OF_RB_FILES>'; my $fsl = "# frozen_string_literal: false\n"; for my $f (@ARGV) { open my $fh, '<', $f; my $s = do { local $/; <$fh> } // die "read($f): $!"; next if $s =~ /^#\s*frozen_string_literal:/sm; # fsl must be after encoding: line if it exists: if ($s =~ s/^([ \t]*\#[ \t\-\*\#]+encoding:[^\n]+\n)/$1$fsl/sm # or after the shebang || $s =~ s/^(#![^\n]+\n)/$1$fsl/ # or after embedded switches in rackup files: || ($f =~ /\.ru$/ && $s =~ s/^(#\\[^\n]+\n)/$1$fsl/) # or prepend as a last resort: || (substr($s, 0, 0) = $fsl)) { open $fh, '>', $f; print $fh $s; close $fh; } } Somebody interested will have to go through every Ruby source file and enable frozen_string_literal once they've thoroughly verified it's safe to do so. [1] https://bugs.ruby-lang.org/issues/20205
2024-01-15middleware: reuse inet_diag netlink socket
Eric Wong <bofh@yhbt.net> wrote: > I'll squash this in for fork+preload safety. I forget there are multithreaded servers using this :x ------8<----- Subject: [PATCH v3] middleware: reuse inet_diag netlink socket No point in constantly allocating and deallocating FDs (and Ruby IO objects) when reusing them is supported. However, we must guard it against parallel callers since linux_inet_diag.c::diag releases the GVL while calling sendmsg(2) and recvmsg(2), so it's possible two Ruby threads can end up crossing streams if the middlware is used with a multi-threaded server. AFAIK, Raindrops::Middleware isn't a heavily-trafficked endpoint, so saving FDs and avoiding thread specific data is preferable for memory-constrained systems I use.
2023-09-10aggregate/last_data_recv: support Socket#accept{,_nonblock}
Socket#accept and Socket#accept_nonblock return an Addrinfo object in addition to a client socket. This allows web servers to avoid having to make getpeername(2) syscalls to get the same information.
2021-11-26Allow Raindrops objects to be backed by a file
Currently, all memory used by Raindrops is mapped as MAP_ANONYMOUS. This means that although Raindrops counters can be shared between processes that have forked from each other, it is not possible to share the counter values with another, unrelated process. This patch adds support for backing the Raindrops mapping with a file descriptor obtained from an IO object. The #initialize API has been enhanced with two new keyword options: Raindrops.new(size, io: nil, zero: false) If an instance of IO is provided, then the underlying file descriptor for that IO will be used to back the memory mapping Raindrops creates. An unrelated process can then open the same file, and read the counters; either by mmap'ing the file itself (or using Raindrops to do so), or by making ordinary seek()/read() calls if performance is not a concern. Note that the provided IO object _must_ implement #truncate; this is used to set the size of the file to be right-sized for the memory mapping that is created. If the zero argument is passed as true, then the mapping will be zero'd by Raindrops as part of its initialization. If it's false, then the Raindrops counters existing in the file will be preserved. This allows counter values to be persisted (although note that Raindrops makes no attempt to msync the values, so they are not durable to e.g. system crashes). Counter values can easily be shared between processes in-memory only without touching the disk by passing in a File on a tmpfs as the io object.
2020-01-06replace bogomips.org with yhbt.net
The expiration for bogomips.org is coming up and I'm not keen on paying or supporting extortionists. Not wanting to be beholden to ICANN or any powerful organizations, .onion sites are available to Tor users: http://raindrops.ou63pmih66umazou.onion/ http://ou63pmih66umazou.onion/raindrops.git/ http://ou63pmih66umazou.onion/raindrops-public/ (the demo is not yet available via .onion, yet, could be a bit)
2020-01-06fixes for newer rubies
Newer rubies have more warnings
2017-07-25Properly override respond_to? in Raindrops::Middleware::Proxy
Correct method definition according to Ruby documentation (https://ruby-doc.org/core-2.4.1/Object.html#method-i-respond_to-3F) is: respond_to?(string, include_all=false) → true or false Rack started using second argument starting from version 2: https://github.com/rack/rack/blob/master/lib/rack/body_proxy.rb#L14 If raindrops is used in Rack 2+ applications, an exception is raised: ArgumentError: wrong number of arguments (2 for 1) <ROOT>/gems/raindrops-0.18.0/lib/raindrops/middleware/proxy.rb:30:in `respond_to?' <ROOT>/gems/rack-2.0.3/lib/rack/body_proxy.rb:14:in `respond_to?'
2017-03-23aggregate/pmq: update version numbers for Ruby and Linux
Linux is in the 4.x and Ruby is into the 2.x range, by now, so try to get with the times.
2017-03-18aggregate/pmq: avoid File#stat allocation aggregate-pmq
File#size is available in modern Rubies so the extra syscall is avoided.
2017-03-18aggregate/pmq: remove io-extra requirement
IO.copy_stream is standard in 1.9+ and can use pread when given an offset. We do not need to use pwrite with fcntl locking, actually.
2017-03-18aggregate/pmq: avoid false sharing of lock buffers
And rely on frozen string optimizations in Ruby while we're at it.
2016-07-29use HTTPS and move homepage to https://bogomips.org/raindrops/
While raindrops.bogomips.org exists, having extra subjectAltName entries is bloating the certificate. This will make it easier to mirror the homepage on Tor hidden services.
2016-07-27drop Rack::Utils.bytesize dependency
rack 2.0 removes this method, but we actually don't need it since any strings we generate are binary and Aggregate#to_s output is 7-bit clean.
2016-02-24middleware: minor bytecode size reduction
The "defineclass" VM instruction takes more operands and uses more space than "setconstant". Since we have no methods or subclasses/constants to define under the "Raindrops::Middleware::Stats" class,
2016-02-23linux: remove Pathname stdlib dependency
The File.readlink has been available since the earliest SVN import of Ruby from Jan 16 1998. There's no reason to load the Pathname class here since we don't do any further pathname manipulation. So avoid loading the extra .so here and creating extra objects.
2016-02-23linux: workaround Ruby 2.3 change
File.readlink (and thus Pathname#realpath) returns the filesystem encoding (Encoding.find "filesystem"). The filesystem encoding defaults to the locale encoding, which tends to be UTF-8. This is true even on *nix filesystems which can have any byte besides "\0". ref: https://bugs.ruby-lang.org/issues/12034 ref: http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/73593
2016-02-02remove optimizations which made sense for older rubies
Since Ruby 2.2, frozen string literals are implied for Hash#[] lookups. Constant lookups have inline caching since Ruby 1.9 (from YARV).
2015-01-13move mailing list to raindrops-public@bogomips.org
Existing subscribers on librelist will need to resubscribe since there's no published subscriber lists anywhere. The public-inbox + mlmmj setup on bogomips.org allows posting without subscription and offers downloadable archives via git. The lack of rsyncable archives on librelist nowadays and subscription-required nature of librelist are points against it. Repliers should Cc: all recipients (using the reply-all function of their mail client) since many readers are not subscribed. This project has never accepted or encouraged HTML email, but librelist accepted it. The bogomips.org mail server is configured to treat HTML mail as spam, so do not send HTML mail if you expect a response. Users who wish to subscribe may send a message to: raindrops-public+subscribe@bogomips.org Similarly, they may unsubscribe via: raindrops-public+unsubscribe@bogomips.org HTTP archives are available via: http://bogomips.org/raindrops-public/ ssoma users may also use: git://bogomips.org/raindrops-public (see README change) Old messages to the librelist addresses will continue to get routed to the new mailing list. ref: http://public-inbox.org/
2013-11-05last_data_recv: do not assume Unicorn includes all constants
Some projects may load parts of Unicorn and not others.
2013-04-11watcher: set Content-Type via assignment
Relying on String#replace to set Content-Type stopped working with rack commit 3623d04526b953a63bfb3e72de2d6920a042563f This fixes compatibility with the Rack 1.5.x series.
2012-11-30Watcher: Use relative paths in HTML links
When I mount Raindrops::Watcher like so: map "/_raindrops" do run Raindrops::Watcher.new end Then in the HTML output links use an absolute path instead of relative to the path /_raindrops/ Cheers, Lawrence Signed-off-by: Eric Wong <normalperson@yhbt.net>
2012-06-18watcher: do not require Rack::Head for HEAD response
Rack webservers are not guaranteed to include Rack::Head in the middleware stack. Watcher is a standalone app, so it cannot rely on a framework which automatically includes Rack::Head.
2012-06-18watcher: sort index of listener listing
For hosts with many listeners, it should be easier to read the index page if the results are shown in a consistent order. Requested privately via email to raindrops@bogomips.org
2012-06-12unix: show zero-value stats for idle listeners
When unix_listener_stats is called without arguments, it should still match the behavior of tcp_listener_stats and return ListenerStats object with zero values. This allows callers to iterate through the results to find the pathnames of all the Unix domain sockets in in listen mode.
2012-06-07middleware/proxy: favor __send__ for method dispatch
"send" is more likely to be overridden in subclasses whereas the Ruby runtime (at least 1.9.3) will warn loudly if any user code (re)defines the "__send__" method. For example, BasicSocket#send and UDPSocket#send in the Ruby stdlib are wrappers for the send(2)/sendto(2) system calls, and it's entirely possible an application could return a Socket-subclass as a Rack response body.
2012-06-05unix_listener_stats follows and remembers symlinks
Teach unix_listener_stats to remember the symlink path it followed and have it point to the same object as the resolved (real) socket path. This allows the case where looking up stats by symlinks works if the symlink is given to unix_listener_stats: File.symlink("/real/path/of.sock", "/path/to/link.sock") stats = unix_listener_stats(["/path/to/link.sock"]) stats["/path/to/link.sock"] => # same as stats["/real/path/of.sock"]
2012-06-05resolve symlinks to Unix domain sockets
Raindrops currently fails when provided a symlink to a socket. As this is a common practice for many deployment tools (Vlad, etc.) this patch adds support for finding the realpath prior to looking the socket up in /proc/net/unix [ew: commit message subject] [ew: fixed test to pass under 1.9.3 and 1.8.7: * Tempfile#unlink is unsafe to call if we want to reuse the path, use File.unlink(tmp.path) instead * The return value of File.symlink is zero (or it raises), so it's unusable. * File.symlink will not call #to_path under 1.8.7, so it's necessary to pass pathnames to it, not Tempfile objects. ] Signed-off-by: Eric Wong <normalperson@yhbt.net>
2012-05-21middleware/proxy: fixup comment/whitespace
Noted, but not fixed in the previous commit commit abc6dd47ede5b96ada1ff8f37dfba73cd5fd586a (Add method_missing to Raindrops::Middleware::Proxy)
2012-05-18Add method_missing to Raindrops::Middleware::Proxy
This enables it to behave more like a Rack BodyProxy would, delegating methods to its body object when it does not implement them itself. (Also includes a minor grammar fix to a comment.) [ew: minor comment/whitespace fix] Signed-off-by: Eric Wong <normalperson@yhbt.net>
2012-01-07avoid calling tcp_listener_stats when it is not available
Signed-off-by: Aman Gupta <aman@tmm1.net> Acked-by: Eric Wong <normalperson@yhbt.net>
2012-01-07fix ListenStats documentation error in Raindrops::Linux.unix_listener_stats
Signed-off-by: Aman Gupta <aman@tmm1.net> Acked-by: Eric Wong <normalperson@yhbt.net>
2011-10-141.8 compatibility workarounds
Math.sqrt on 1.8.7 does not give NaN for certain errors. We'll also fix our Errno::EDOM retry loop to avoid resetting the "retried" flag.
2011-10-12avoid inadvertant object creation with invalid addresses
Just in case somebody tries to scan all addresses, we won't run out of memory as easily.
2011-10-03watcher: document new headers for users
These names are not finalized, yet.
2011-10-03watcher: add peak times for statistics
It could be useful to know when the first and last peak time of a maximum was.
2011-09-27watcher: add X-Current header to headers
It can be useful to some to see that info all at once without hitting the HTML index page.
2011-08-01watcher: add POST /reset/$LISTENER endpoint rdoc
This was always supported via the HTML (browser) interface but there was no documented way of hitting it without a browser, before.
2011-06-27doc: librelist.com => librelist.org
A non-profit TLD makes more sense for a Free Software project.
2011-06-27fix Ruby warnings
Found in the check-warnings target in pkg.mk
2011-03-25last_data_recv: fixup rdoc
formatting is hard :<
2011-03-24watcher: fix documentation for X-* headers
I copied and pasted off the Raindrops::LastDataRecv documentation. While the headers and mathematical meanings are identical, they measure different things (but for the same purpose) Noticed-by: Troex Nevelin
2011-03-21watcher: remove redundant Rack::Response
No need to duplicate code
2011-03-18watcher: add title attributes to elements
It can help navigation, we think...
2011-03-18watcher: RDoc examples point to the demo
No need to waste bandwidth of example.com when we have a meaningful demo site :)
2011-03-18watcher: set Expires headers for cache invalidation
We know exactly when to invalidate based on the delay :)
2011-03-18watcher: prevent Rack::Deflater from buffering
Set "Cache-Control: no-transform" to prevent frontend proxies from flushing data.
2011-03-17watcher: add link to the Watcher documentation
Hopefully people can learn to use the REST API this way.
2011-03-16watcher: fix rdoc
2011-03-16watcher: retry on empty stats
Those will cause Aggregate to raise Errno::EDOM
2011-03-17rdoc: document the demo URLs