Commit graph

67 commits

Author SHA1 Message Date
Fletcher Haynes
da9b57bd45 Updated dependency paths to reflect new repo location 2022-09-06 09:39:22 -07:00
Fletcher Haynes
eb06bb50ae Updated code to latest version for open-sourcing. 2022-09-02 13:23:39 -07:00
Ben Johnson
c7c9c1e1d7
v2.0.0
Co-authored-by: Cody Soyland <codysoyland@gmail.com>
2019-10-08 14:56:17 -06:00
Seebs
c133ce0376 Make containers copy-on-write
This patch replaces a lot of circumstances in which containers
were being copied with circumstances in which they are shared,
using copy-on-write semantics.

To achieve this, we emulate somewhat the design of go's
native `append` function. Operations on a container may optionally
yield a new container. A container can be marked "frozen",
after which no operation should ever write to it in any way;
that applies both to the container itself and the backing store
it refers to, if any. So for instance, instead of:

	c.arrayToBitmap()

we now write:

	c = c.arrayToBitmap()

Operations which need to modify a container in any way
need to be able to return a new container, which is a modified
copy of the previous container. This applies to operations
like add/remove, but also to things like unmapping memory-mapped
storage, or changing a container's type.

Bitmaps do not support the same copy-on-write semantics,
currently, but "copying" a bitmap and sharing the containers
instead of duplicating them is *much* cheaper than copying
the containers.

Bitmaps do support a .Freeze method, which currently copies
the previous bitmap, making a new one with the same container
pointers, and freezes the individual containers. Use this
if you need a writeable copy of a bitmap -- the resulting
bitmap can safely have its set of containers modified, and
bitmap operators that would want to modify the containers
will use copy-on-write for that.

The primary motivation of this is to reduce the cost of the
row cache used by fragments. As a secondary issue, the row cache
is no longer updated on writes -- that update was actually a
race condition waiting to happen. Rather, writes to a row
invalidate the cache entry for that row. The row cache is
created by creating a new bitmap, and freezing the relevant
containers from the fragment's storage. In the case where
nothing is being written, the row cache grows to contain
bitmaps containing all those containers, but never copies
any containers. If nothing's being read, the row cache is
never created, and the containers are in general not getting
frozen. The only circumstance where copies have to happen is
when things are read (and thus stored in the row cache) and
later modified. In that case, each read freezes objects, and
the first write to a container after it's been frozen will
create a new copy.

We drop the enterprise/b btree implementation, because we
don't really need it anymore -- we now provide that
implementation by default in the open source product anyway.

Along with this, there's a lot of other changes which
improve support for nil containers, as a cheaper representation
for empty containers. Operations which we know will provide
an empty container can always short-circuit and just yield
a nil *Container. Similarly, operations which would provide
a full container can return a single shared full container
object (which is frozen). The higher-level (non type-specific)
container ops are now using that logic to short-circuit
operations for empty and full containers. (For instance,
difference of anything minus an empty container is the
original thing, union of anything and empty is the original
thing, and so on.)

The Containers interface adds "Update" and "UpdateEvery"
methods, based in part on the "Put" interface provided
by the underlying btree implementation; Update performs
a possible update in-place of a container for a given
key, bypassing the need to replicate the search for that
key in the container. UpdateEvery loops through all the
containers.

Containers do not strictly guarantee that they won't
return nil `*Container` objects. However, the container
iterators won't return those -- empty containers aren't
interesting. Some tests are updated to reflect this.

Some of the container internals, like N(), or the isArray()
and related functions, accept nil container pointers. Some,
like Thaw(), do not. For the array(), bitmap(), and runs()
methods, roaringparanoia enables an explicit panic on a nil
container explaining the problem, but the intent is that those
should never be called unless you already know you have the
right kind of container, so by default they don't perform
the extra checks. In most cases, this is already covered
because a nil container is empty, and there's no operation
we can perform that requires us to inspect the contents of
an empty container. This is passing a fair amount of testing,
but the testing may not be comprehensive enough.

The overall impact of this is pretty trivial performance-wise.
In our default roaring/ benchmarks, a few things get a few
percent faster, or slower. The advantage is that, with
read-heavy workloads, the row cache no longer eats up incredible
amounts of memory.

For a smallish test case, pilosa's memory usage (RES in top) after
startup was ~2.5GB. Without this patch, simply reading every
row a few times got memory usage to about 9GB, which seemed
reasonably stable. With this patch, memory usage went to about
3GB. This will be less noticeable in mixed read/write loads,
but it should be consistently significantly lower.

In addition to dropping things from the rowCache on modifications,
we also stopped performing a full count on a modified row when
not using a cache of a kind that would use that count, and don't
repopulate the rowCache regardless. We don't want every write
to imply a corresponding read after it.

There's a lot of room for possible future optimizations in
terms of things like in-place operations, and some of the
row/rowSegment code is a little suspicious to me, but I don't
think it should be *worse* in any cases.
2019-05-30 16:36:20 -05:00
Seebs
a203313143 move Logger and Stats to their own packages
I'd like to add stat tracking to Roaring, which means it
has to be able to import the stats package, which means
stats has to be a package rather than part of the pilosa
package. If stats stops being in pilosa, it still needs
a way to import logger, so logger also has to leave the
pilosa package. Then everything using them needs to import
them and use package selectors on their names.

This doesn't actually add the stats support to roaring,
it just makes it so there's a way to import the stats
code from something in the roaring package.
2018-11-15 15:10:44 -06:00
Travis Turner
1b6d738bab
Support ranked cache value=0.
Since there is no way to remove a value from the cache (because
the interface doesn't support it), this PR modifies the ranked
cache implemetation to allow setting the cache value to 0 for a
row. Doing so effectively removes that row from the cache. Values
below the threshold (other than 0) are still ignored by the
ranked cache's Add() method.
2018-09-24 15:52:44 -05:00
Matt Jaffee
3ea07ae3a7
use cache.Recalculate instead of Invalidate for imports
Invalidate does not always rebuild the cache - if the last rebuild is < 10s ago,
it does nothing. We always want to rebuild the cache after imports.

Also updated the comments around recalculate/invalidate to clarify.
2018-09-12 17:07:46 -05:00
Cody Soyland
dc50204846 Fix linter issues: unconvert 2018-07-20 11:51:55 -05:00
Matt Jaffee
def3be0f17
remove more dead code 2018-07-05 16:25:04 -05:00
Matt Jaffee
e76a90e69b
change Query and QueryNode to use pilosa.* Query structs 2018-07-05 15:02:33 -05:00
Matt Jaffee
712404b4ec
clean up nopCache 2018-07-02 15:05:00 -05:00
Matt Jaffee
65700f9604
unexport a bunch of cache.go stuff 2018-07-02 14:58:17 -05:00
Travis Turner
7d91261968
un-export some package level constants 2018-06-13 17:18:52 -05:00
Cody Soyland
f2c104dfef Migrate HTTP handler and client into http subpackage. 2018-06-12 13:22:40 -05:00
Matt Jaffee
4ef266e5cc
revert a bunch of stuff and fix some comments 2018-05-24 16:35:27 -05:00
Todd Gruben
fb7bf11825 Bit -> Column migration 2018-05-23 15:05:22 -05:00
Todd Gruben
575e199ad8 renamed pilosa.Bitmap to Row 2018-05-21 09:12:42 -05:00
Matt Jaffee
68dec9c60a
remove unnecessary capacity in make() 2018-05-15 10:46:41 -05:00
Matt Jaffee
0e38eae6e3
convert time.Now().Sub() to time.Since() 2018-05-15 10:45:58 -05:00
Travis Turner
f2729b90d7
vendor github.com/golang/groupcache/lru. rebuild Gopkg.lock 2018-04-23 10:43:06 -05:00
Travis Turner
0ad65e64b7
use json:omitempty on Pair.Key 2018-01-16 11:21:02 -06:00
Ben Johnson
234d40fe96
Enterprise support. 2018-01-16 11:21:01 -06:00
Travis Turner
b039747887
fix a few typos 2017-11-10 10:45:56 -06:00
Todd Gruben
773019a0f3 corrected nameing 2017-08-28 14:15:59 -05:00
Todd Gruben
60ee6dcfdd constant cache removal 2017-08-28 14:12:31 -05:00
Todd Gruben
6a70f27f59 account for all same values in rank 2017-08-28 13:46:18 -05:00
Linh Vo
326a162094 fixed review 2017-07-24 22:09:31 -05:00
Linh Vo
2cfcf497e1 add tests for none cache 2017-07-21 00:16:37 -05:00
Linh Vo
f68362c40c implement nopcache 2017-07-20 16:11:13 -05:00
Michael Baird
59f26ce585 removed no-op stats tracking, fixed typos 2017-05-30 11:13:39 -05:00
Michael Baird
d4e9e5cdbc cache StatsD recalculate, invalidate, and threshold counts 2017-05-16 15:21:26 -05:00
Michael Baird
4a051900c0 Add sampling rate to StatsD functions, and fix data dog logging 2017-05-16 10:35:49 -05:00
Michael Baird
ee159b455d Merge remote-tracking branch 'origin/master' into metrics
Conflicts:
	.gitignore
	cluster.go
	frame.go
	glide.lock
	index.go
2017-05-01 10:41:04 -05:00
Cody Soyland
3996b56b88 Apply Apache License 2.0 2017-04-28 14:22:03 -05:00
Michael Baird
d2a7869142 comment cleanup 2017-04-25 16:40:39 -05:00
Michael Baird
3972d0cfaa added missing comments for godocs 2017-04-25 13:31:12 -05:00
Michael Baird
5a8c165c53 Merge remote-tracking branch 'origin/master' into metrics
Conflicts:
	cache.go
	cluster.go
	db.go
	executor.go
	fragment.go
	frame.go
	gossip/gossip.go
	handler.go
	index.go
	server.go
	server/server.go
2017-04-24 16:35:25 -05:00
Ben Johnson
d34687121f
Rename bitmap/profile to row/column. 2017-04-21 21:23:24 -06:00
Michael Baird
40cb2adef6 add cache stats 2017-04-19 16:27:39 -05:00
Travis
b0f1fc7523 Makes Messenger a first-class object under Server (with pointers in Handler and Index).
Primary message interface is the MessageBroker which is an attribute of the Messenger.
MessageBroker implementations:
- Gossip (memberlist)
- Broadcast (uses HTTP, received by existing Handler)
- Static (no-ops)

Changes CacheSize from `int` to `uint32` for consistency with protobuf.
Removes unnecessary dependencies in glide:
- `github.com/aws/aws-sdk-go`
- `golang.org/x/net` (although this gets included by memberlist)

TODO:
- [ ] Add tests around the Messenger and MessageBroker objects.
- [ ] Refactor CreateSliceMessage to work with views.
- [ ] Support propogation of meta data on PATCH calls.

fixing some issues from last rebase
2017-04-19 10:33:26 -05:00
Michael Baird
8e2e9254f7 fixed comment 2017-04-19 10:26:47 -05:00
Michael Baird
e864a45d57 cleaned up the comments and code for the cache threshold. Also made the max size the set value of the cache rather than the calculated index. This ensures the user will not receive less cached values than they expect 2017-04-19 10:26:47 -05:00
Michael Baird
9321637d18 trim the ranked cache set on the 1st recalculate call 2017-04-19 10:06:11 -05:00
Matt Jaffee
e6309d45e1 make sure exported functions are godoc'd 2017-04-18 15:10:59 -05:00
Linh Vo
7979b4d69b set profile attr for columnLabel 2017-03-24 12:18:59 -05:00
Linh Vo
ac8018c4f3 change Pair struct Key to ID 2017-03-23 12:38:09 -05:00
Linh Vo
67a691dfe0 use id instead of key in topN results 2017-03-23 12:02:57 -05:00
Travis
2b94be965e Make sure the TopN test is actually using a RankCache supported frame.
Implement cache.Recalculate to bypass the 10-second delay built into cache.Invalidate().
2017-03-10 11:07:18 -06:00
Travis
c013661880 bug fix in SimpleCache.Fetch (really just reverting my change) 2017-03-02 16:00:34 -06:00
Travis
cbac9ec88b move BitmapCache into cache.go. adjust some variable names for clarity 2017-03-02 15:17:21 -06:00