Commit Graph

21 Commits

Author SHA1 Message Date
Anton Kaliaev e4ef2835f0
return error if client already subscribed 2017-12-09 23:35:14 -06:00
Anton Kaliaev cb4ba522ef
add String method to Query interface
Required for https://github.com/tendermint/tendermint/issues/945
2017-12-09 23:05:13 -06:00
Anton Kaliaev c325ce2182
use NoErrorf and Errorf functions 2017-12-05 17:49:42 -06:00
Petabyte Storage 4769719a4b fix Errorf 2017-12-04 08:54:19 -08:00
Petabyte Storage ebc543ebe3 fix warnings 2017-12-01 09:51:37 -08:00
Anton Kaliaev c9694b1ba1
fix warnings 2017-11-29 12:44:16 -06:00
Anton Kaliaev 3822727981
add Conditions function
Refs https://github.com/tendermint/tendermint/pull/835
2017-11-29 12:44:16 -06:00
Zach Ramsay 3c57c24921 linting: next round of fixes 2017-09-22 12:14:27 -04:00
Zach Ramsay d6e03d2368 linting: add to Makefile & do some fixes 2017-09-22 11:42:29 -04:00
Anton Kaliaev fa990f0803
add test case for hex 2017-08-10 19:46:59 -04:00
Anton Kaliaev a6a06f820f
[pubsub/query] quote values using single quotes
This fixes the problem with base-16 encoded values which may start with
digits: 015AB.... In such cases, the parser recognizes them as numbers
but fails to parse because of the follow-up characters (AB).

```
failed to parse tm.events.type=Tx AND hash=136E18F7E4C348B780CF873A0BF43922E5BAFA63:
parse error near digit (line 1 symbol 31 - line 1 symbol 32):
  "6"
```

So, from now on we should quote any values. This seems to be the way
Postgresql has chosen.
2017-07-21 13:20:32 +03:00
Anton Kaliaev 77f6febb03
rename TestClientResubscribes to TestClientSubscribesTwice
test UnsubscribeAll properly
test BufferCapacity getter
2017-07-20 11:46:22 +03:00
Anton Kaliaev 992c54253f
fixes from gometalinter review 2017-07-18 11:53:41 +03:00
Anton Kaliaev 17d6091ef4
updates as per Bucky's comments 2017-07-15 13:33:47 +03:00
Anton Kaliaev e664f9c688
use context to provide timeouts! 2017-07-14 14:49:25 +03:00
Anton Kaliaev 0006bfc359
return ErrorOverflow on Subscribe if server is overflowed
> why we need it?

most of our subscribers will be RPC WS subscribers, so if there are too
many, nothing wrong with rejecting to subscribe.

however, consensus reactor must be the first to subscribe, since its
work depends on the pubsub package.
2017-07-14 13:02:32 +03:00
Anton Kaliaev 13207a5927
remove overflow options 2017-07-14 12:32:01 +03:00
Anton Kaliaev 4aa024d843
add more info to error messages 2017-07-12 23:10:36 +03:00
Anton Kaliaev e4f3f9d9bf
remove comment about LRU cache (see comments below)
I've tried https://github.com/hashicorp/golang-lru/tree/master/simplelru today and here are
the results:

with LRU cache:

```
Benchmark10Clients-2                               50000             29021 ns/op         3976 B/op         105 allocs/op
Benchmark100Clients-2                               3000            363432 ns/op        36382 B/op        1005 allocs/op
Benchmark1000Clients-2                               500           2473752 ns/op       360500 B/op       10009 allocs/op
Benchmark10ClientsUsingTheSameQuery-2             300000              4059 ns/op          773 B/op          15 allocs/op
Benchmark100ClientsUsingTheSameQuery-2            500000              4360 ns/op          773 B/op          15 allocs/op
Benchmark1000ClientsUsingTheSameQuery-2           300000              4204 ns/op          773 B/op          15 allocs/op
```

without LRU cache:

```
Benchmark10Clients-2                      200000              5267 ns/op             616 B/op       25 allocs/op
Benchmark100Clients-2                      30000             42134 ns/op            2776 B/op      205 allocs/op
Benchmark1000Clients-2                      3000            552648 ns/op           24376 B/op     2005 allocs/op
Benchmark10ClientsOneQuery-2             1000000              2127 ns/op             462 B/op        9 allocs/op
Benchmark100ClientsOneQuery-2             500000              2353 ns/op             462 B/op        9 allocs/op
Benchmark1000ClientsOneQuery-2            500000              2339 ns/op             462 B/op        9 allocs/op
```

> How were you using the lru cache exactly?

I was adding a KV pair each time there is a match plus checking if
`lru.Contains(key)` before running the actual check (`q.Matches(tags)`).

```
key = fmt.Sprintf("%s/%v", query + tags)
```
2017-07-12 22:52:13 +03:00
Anton Kaliaev 8062ade787
remove all clients (including closing all channels) on shutdown 2017-07-12 13:10:36 +03:00
Anton Kaliaev a99b8a6210
new events package
query parser

use parser compiler to generate query parser

I used https://github.com/pointlander/peg which has a nice API and seems
to be the most popular Golang compiler parser using PEG on Github.

More about PEG:

- https://en.wikipedia.org/wiki/Parsing_expression_grammar
- https://github.com/PhilippeSigaud/Pegged/wiki/PEG-Basics
- https://github.com/PhilippeSigaud/Pegged/wiki/Grammar-Examples

rename

implement query match function

match function

uncomment test lines

add more test cases for query#Matches

fix int case

rename events to pubsub

add comment about cache

assertReceive helper to not block on receive in tests

fix bug with multiple conditions

uncomment benchmark

first results:

```
Benchmark10Clients-2                1000           1305493 ns/op         3957519 B/op     355 allocs/op
Benchmark100Clients-2                100          12278304 ns/op        39571751 B/op    3505 allocs/op
Benchmark1000Clients-2                10         124120909 ns/op        395714004 B/op   35005 allocs/op
```

124ms to publish message to 1000 clients. A lot.

use AST from query.peg.go

separate pubsub and query packages by using Query interface in pubsub

wrote docs and refactor code

updates from Frey's review

refactor type assertion to use type switch

cleanup during shutdown

subscriber should create output channel, not the server

overflow strategies, server buffer capacity

context as the first argument for Publish

log error

introduce Option type

update NewServer comment

move helpers into pubsub_test

increase assertReceive timeout

add query.MustParse

add more false tests for parser

add more false tests for query.Matches

parse numbers as int64 / float64

try our best to convert from other types

add number to panic output

add more comments

save commit

introduce client argument as first argument to Subscribe

> Why we do not specify buffer size on the output channel in Subscribe?

The choice of buffer size of N here depends on knowing the number of
messages server will receive and the number of messages downstream
subscribers will consume. This is fragile: if we publish an additional
message, or if one of the downstream subscribers reads any fewer
messages, we will again have blocked goroutines.

save commit

remove reference counting

fix test

test client resubscribe

test UnsubscribeAll

client options

[pubsub/query] fuzzy testing

do not print msg as it creates data race!
2017-07-12 09:48:01 +03:00