Commit Graph

59793 Commits

Author SHA1 Message Date
Matthew Draper
2d6c14bca2 Temporarily make ACa tests noiser and more predictable 2016-10-03 18:32:22 +10:30
Matthew Draper
e1fdfa820f Merge pull request #26425 from prathamesh-sonpatki/fix-nil-issue
Fix issue with `cache_key` when the named timestamp column has value nil
2016-10-03 17:41:47 +10:30
Matthew Draper
e8b36e7711 Avoid bumping the class serial when invoking executor 2016-10-03 13:35:51 +10:30
Jon Moss
353122c9da Speed up Time.zone.now
@amatsuda, during his RailsConf talk this past year, presented a
benchmark that showed `Time.zone.now` (an Active Support joint)
performing 24.97x slower than Ruby's `Time.now`. Rails master appears to
be a _bit_ faster than that, currently clocking in at 18.25x slower than
`Time.now`. Here's the exact benchmark data for that:

```
Warming up --------------------------------------
            Time.now   127.923k i/100ms
       Time.zone.now    10.275k i/100ms
Calculating -------------------------------------
            Time.now      1.946M (± 5.9%) i/s -      9.722M in   5.010236s
       Time.zone.now    106.625k (± 4.3%) i/s -    534.300k in   5.020343s

Comparison:
            Time.now:  1946220.1 i/s
       Time.zone.now:   106625.5 i/s - 18.25x slower
```

What if I told you we could make `Time.zone.now` _even_ faster? Well,
that's exactly what this patch accomplishes. When creating `ActiveSupport::TimeWithZone`
objects, we try to convert the provided time to be in a UTC format. All
this patch does is, in the method where we convert a provided time to
UTC, check if the provided time is already UTC, and is a `Time` object
and then return early if that is the case, This sidesteps having to continue on,
and create a new `Time` object from scratch. Here's the exact benchmark
data for my patch:

```
Warming up --------------------------------------
            Time.now   124.136k i/100ms
       Time.zone.now    26.260k i/100ms
Calculating -------------------------------------
            Time.now      1.894M (± 6.4%) i/s -      9.434M in   5.000153s
       Time.zone.now    301.654k (± 4.3%) i/s -      1.523M in   5.058328s

Comparison:
            Time.now:  1893958.0 i/s
       Time.zone.now:   301653.7 i/s - 6.28x slower
```

With this patch, we go from `Time.zone.now` being 18.25x slower than
`Time.now` to only being 6.28x slower than `Time.now`. I'd obviously love some
verification on this patch, since these numbers sound pretty interesting... :)

This is the benchmark-ips report I have been using while working on this:

```ruby
require 'benchmark/ips'

Time.zone = 'Eastern Time (US & Canada)'

Benchmark.ips do |x|
  x.report('Time.now') {
    Time.now
  }

  x.report('Time.zone.now') {
    Time.zone.now
  }

  x.compare!
end
```

cc @amatsuda
cc performance folks @tenderlove and @schneems

![Pretty... pretty... pretty good.](https://media.giphy.com/media/bWeR8tA1QV4cM/giphy.gif)
2016-10-02 15:12:46 -04:00
Matthew Draper
a92fa72600 Shut down the worker pool - don't kill it
Different parts of concurrent-ruby's documentation make inconsistent
claims about how kill will behave. It doesn't do the thing we want.
2016-10-03 05:38:25 +10:30
Matthew Draper
4f8e336c44 Merge pull request #26620 from maclover7/jm-ac-pg-bug
Shutdown pubsub connection before classes are reloaded
2016-10-03 05:36:44 +10:30
Matthew Draper
62ed56135b Correct caller tracking in delegated deprecation methods 2016-10-03 05:22:28 +10:30
Andrew White
9128ba5cd4 Cache to_time to improve performance when comparing
In #25880 we tried to cache localtime to fix the performance
regression but that proved to be difficult due to the fact that
localtime/getlocal can take a utc_offset argument. We tried
caching based on the argument but since the argument can be nil
sometimes that meant that if the TZ environment variable changed
then the cached value for nil became invalid. By moving the
caching to DateAndTime#compatibility we don't have to worry about
arguments since it doesn't take any.

There is a possible edge condition where preserve_timezone is set
to false and the system timezone changes then it could result in
a cached value being incorrect but the only way to fix this would
be to remove all caching and live with the performance issue.
2016-10-02 17:15:44 +01:00
Andrew White
bd8f0871c2 Revert "Merge pull request #25880 from ryandv/fix_performance_regression_in_timewithzone_to_time"
Turns out trying to cache on localtime with arguments is too hard
so we'll do it on DateAndTime::Compatibility#to_time instead.

This reverts commit 3132fa6b7d9585e04eb44b25b55d298391b040b5, reversing
changes made to 6949f8e5e7dc901d4e04ebab6c975afb33ca44c9.
2016-10-02 17:02:27 +01:00
Andrew White
6c1dac00df Revert "Merge pull request #26677 from tbalthazar/26644"
Turns out trying to cache on localtime with arguments is too hard
so we'll do it on DateAndTime::Compatibility#to_time instead.

This reverts commit 9ce2d1b1a43fc4ef3db59849b7412d30583a4074, reversing
changes made to 53ede1aff2025d4391d0e05ba471fdaf3110a99c.
2016-10-02 17:00:18 +01:00
Jon Moss
d1cc11a360 Add tests for Server::Base#restart 2016-10-02 09:02:01 -04:00
Jon Moss
35a497dc29 Move behavior to Server::Base, and flush pubsub 2016-10-02 08:45:38 -04:00
Jon Moss
a5dfba4135 Shutdown pubsub connection before classes are reloaded
Before this patch, if you were to make a file edit in your Rails
application and you tried to load up the page, it would hang
indefinitely. The issue is that Active Record is trying to cleanup after
itself and clear all active connection, but Action Cable is still
holding onto a connection from the pool. To resolve this, we are now
shutting down the pubsub adapter before classes are reloaded, to avoid
this altogether (connection is being returned to the pool).

Credits to @skateman for discovering this bug. :)
2016-10-02 08:45:38 -04:00
Jon Moss
da0fdd6bf5 Merge pull request #26683 from y-yagi/add_cached_key_to_sql_active_record_event
add `cached` key to `sql.active_record` event [ci skip]
2016-10-02 08:36:40 -04:00
Matthew Draper
7b63f56ce0 Merge pull request #26672 from schpet/support_ruby_keywords_as_template_locals
Avoid compiling ruby keywords into template locals
2016-10-02 21:10:26 +10:30
Peter Schilling
f9960f2d74 Change render to support any hash keys in locals
this lets you pass ruby keywords to templates:

    <%= render 'example', class: "cool" %>

    <%= render 'example', "spaces are" => "a-ok" %>

    <%= render 'example', Foo: "bar" %>

Previously you'd see confusing syntax errors like this:

    SyntaxError (.../_example.html.erb:1: syntax error, unexpected '='

Now you can reference invalid identifiers through local_assigns.

If you try to use an invalid keyword (e.g. class) in your template, you
get a syntax error on the line where you use it.
2016-10-02 00:21:17 -07:00
yuuji.yaginuma
f597822f4a add cached key to sql.active_record event [ci skip]
Follow up to #26584
2016-10-02 13:29:17 +09:00
Matthew Draper
832b02620b Merge pull request #26682 from matthewd/cable-tests
Use websocket-client-simple instead of Faye in tests
2016-10-02 12:58:58 +10:30
Matthew Draper
7c812c2401 Use websocket-client-simple instead of Faye as a websockets client
Mostly, this is just to avoid EventMachine. But there's also an argument
to be made that we're better off using a different protocol library for
our test suite than the one we use to implement the server.
2016-10-02 12:25:33 +10:30
Matthew Draper
a5abc310cd Shut down EventMachine before re-enabling warnings 2016-10-02 12:25:33 +10:30
Andrew White
9ce2d1b1a4 Merge pull request #26677 from tbalthazar/26644
Fix `ActiveSupport::TimeWithZone#localtime`
2016-10-01 21:30:02 +01:00
Matthew Draper
53ede1aff2 Merge pull request #26678 from larskanis/patch-1
Add missing require for zlib in ActiveRecord::Migrator
2016-10-02 05:26:46 +10:30
Lars Kanis
c16a70a4e6 Add missing require for zlib
Zlib is used to generate the advisory lock since commit 2c2a8755460 .

Using the Migrator fails since then, when it is called without the rails context:

    NameError: uninitialized constant ActiveRecord::Migrator::Zlib

This patch fixes the above error.
2016-10-01 16:29:22 +02:00
Andrew White
58cabed38e Remove obsolete comment about class-level respond_to
The class-level respond_to was extracted in ee77770 to responders gem

[ci skip]
2016-10-01 14:29:42 +01:00
Thomas Balthazar
607a6c7a9a Fix ActiveSupport::TimeWithZone#localtime
Previously memoization in `localtime` wasn't taking the `utc_offset`
parameter into account when returning a cached value. It now caches the
computed value depending on the `utc_offset` parameter, e.g:

    Time.zone = "US/Eastern"

    t = Time.zone.local(2016,5,2,11)
    # => Mon, 02 May 2016 11:00:00 EDT -04:00

    t.localtime(-7200)
    # => 2016-05-02 13:00:00 -0200

    t.localtime(-3600)
    # => 2016-05-02 14:00:00 -0100
2016-10-01 13:38:43 +02:00
Matthew Draper
95f4a88f17 Merge pull request #26676 from matthewd/no-faye-mode
Remove Faye mode
2016-10-01 16:08:14 +09:30
Matthew Draper
eabff0daa8 Make PG deadlock error more deterministic
We've seen occasional Travis failures mentioning deadlocks. I think
they're escaping from this test.
2016-10-01 16:04:42 +09:30
Matthew Draper
3e779d3c67 In-line the configuration points that only existed for Faye support 2016-10-01 15:36:26 +09:30
Matthew Draper
d44177d45e Remove Faye mode
No deprecation, because it was never documented.
2016-10-01 15:35:59 +09:30
Matthew Draper
9588a3d66d Merge pull request #26547 from palkan/fix/actioncable-confirmation-race-condition
Avoid race condition on subscription confirmation
2016-10-01 15:18:39 +09:30
Jon Moss
72f97e2810 Merge pull request #26675 from j1wilmot/update-docs
Remove dup distinct from AR query list doc [ci skip]
2016-09-30 18:20:15 -04:00
Jeremy Wilmot
7d0e73bc01 Remove dup distinct from AR query list [ci skip] 2016-09-30 15:12:16 -07:00
Rafael França
dc61db08b6 Merge pull request #26584 from Shopify/cached-query-name
Preserve cached queries name in AS notifications
2016-09-30 13:58:58 -04:00
Matthew Draper
8356dcac9b Merge pull request #26646 from matthewd/cable-buffer
Buffer writes to the cable sockets
2016-10-01 00:57:08 +09:30
Matthew Draper
4f2d1d6c4c Merge pull request #26147 from matthewd/callback-backtrace
Callbacks: leave less lines in the backtrace
2016-10-01 00:56:48 +09:30
Matthew Draper
871ca21f6a Tighten the backtrace pollution from passing through callbacks
Callbacks are everywhere, so it's better if we can avoid making a mess
of the backtrace just because we've passed through a callback hook.

I'm making no effort to the before/after invocations: those only affect
backtraces while they're running. The calls that matter are the ones
that remain on the call stack after run_callbacks yields: around
callbacks, and internal book-keeping around the before/afters.
2016-09-30 06:57:43 +09:30
Sean Griffin
268a5bb010 Don't skip in-memory insertion of associations when loaded in validate
This was caused by 6d0d83a33f59d9415685852cf77818c41e2e2700. While the
bug it's trying to fix is handled if the association is loaded in an
after_(create|save) callback, it doesn't handle any cases that load the
association before the persistence takes place (validation, or before_*
filters). Instead of caring about the timing of persistence, we can just
ensure that we're not double adding the record instead.

The test from that commit actually broke, but it was not because the bug
has been re-introduced. It was because `Bulb` in our test suite is doing
funky things that look like STI but isn't STI, so equality comparison
didn't happen as the loaded model was of a different class.

Fixes #26661.
2016-09-29 14:57:31 -04:00
Vipul A M
09487dc86c Merge pull request #26660 from unasuke/fix_typo_in_5_0_release_notes
Fix typo in 5_0_release_notes.md doc [ci skip]
2016-09-29 18:34:57 +05:30
Yusuke Nakamura
86c0dccac1 Fix typo in 5_0_release_notes.md doc [ci skip] 2016-09-29 21:56:56 +09:00
Kasper Timm Hansen
01221e1d08 Merge pull request #26659 from y-yagi/remove_mongrel_once_again
remove `mongrel` once again
2016-09-29 13:07:02 +02:00
Akira Matsuda
b18f8b9d77 Merge pull request #26402 from mtsmfm/remove-dead-constants
Remove dead constants
2016-09-29 18:52:39 +09:00
yuuji.yaginuma
ca41fafd9a remove mongrel once again
`mongrel` was removed in #26408. But have back accidentally in #26414.
2016-09-29 17:30:56 +09:00
Jon Moss
29f883640c Merge pull request #26648 from y-yagi/update_description_of_queue_adapter
update description of queue adapter in test [ci skip]
2016-09-28 17:04:21 -04:00
Jon Moss
c93b80d53d Merge pull request #26654 from Neodelf/activesupport_1
[ci skip] Remove not necessary whitespace
2016-09-28 17:02:22 -04:00
Jon Moss
19dcf0a210 Merge pull request #26653 from Neodelf/new_branch_name
[ci skip] Use right format text
2016-09-28 17:01:39 -04:00
Jon Moss
a7b937d382 Merge pull request #26652 from Neodelf/activesupport_2
[ci skip] Use class name instead of path to file
2016-09-28 17:00:43 -04:00
Andrey Molchanov
1ba3ee4dd1 [ci skip] Use class name instead of path to file 2016-09-28 23:31:54 +03:00
Andrey Molchanov
64930cecaa [ci skip] Use right format text 2016-09-28 23:29:01 +03:00
Andrey Molchanov
05eb2c0835 [ci skip] Remove not necessary whitespace 2016-09-28 23:24:26 +03:00
प्रथमेश Sonpatki
db88160eff Merge pull request #26649 from michaellennox/remove_broken_perf_test_link
[ci skip] Removes broken performance testing link from the 2.2 release notes
2016-09-28 18:49:25 +05:30