Return-Path: X-Original-To: apmail-cassandra-user-archive@www.apache.org Delivered-To: apmail-cassandra-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 4BA2218CE6 for ; Sat, 12 Mar 2016 00:24:39 +0000 (UTC) Received: (qmail 10753 invoked by uid 500); 12 Mar 2016 00:24:35 -0000 Delivered-To: apmail-cassandra-user-archive@cassandra.apache.org Received: (qmail 10702 invoked by uid 500); 12 Mar 2016 00:24:35 -0000 Mailing-List: contact user-help@cassandra.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@cassandra.apache.org Delivered-To: mailing list user@cassandra.apache.org Received: (qmail 10692 invoked by uid 99); 12 Mar 2016 00:24:35 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 12 Mar 2016 00:24:35 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id 6D77A180535 for ; Sat, 12 Mar 2016 00:24:35 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 1.999 X-Spam-Level: * X-Spam-Status: No, score=1.999 tagged_above=-999 required=6.31 tests=[HTML_MESSAGE=2, SPF_PASS=-0.001] autolearn=disabled Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id Vm7soLtLLqwk for ; Sat, 12 Mar 2016 00:24:30 +0000 (UTC) Received: from setentaytres29.nsprimario.com (setentaytres31.nsprimario.com [188.93.73.31]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with ESMTPS id AD8E05FAC4 for ; Sat, 12 Mar 2016 00:24:29 +0000 (UTC) X-No-Relay: not in my network Received: from mail-wm0-f43.google.com (mail-wm0-f43.google.com [74.125.82.43]) by setentaytres29.nsprimario.com (Postfix) with ESMTPSA id 9F5F510A0F97 for ; Sat, 12 Mar 2016 01:24:22 +0100 (CET) Received: by mail-wm0-f43.google.com with SMTP id l68so37184199wml.0 for ; Fri, 11 Mar 2016 16:24:22 -0800 (PST) X-Gm-Message-State: AD7BkJJ6GR3QoqlFauVNVCl/GgFhVOL05J1VjW6baJ0Jw6igfXiKKk2h3Dsyu6syh41wOzV3nP/pZJHW4ef9sw== MIME-Version: 1.0 X-Received: by 10.194.200.194 with SMTP id ju2mr12063136wjc.63.1457742262303; Fri, 11 Mar 2016 16:24:22 -0800 (PST) Received: by 10.28.145.194 with HTTP; Fri, 11 Mar 2016 16:24:22 -0800 (PST) In-Reply-To: References: <1842220918.12093.1457735878521.JavaMail.yahoo@mail.yahoo.com> Date: Sat, 12 Mar 2016 01:24:22 +0100 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: Strategy for dividing wide rows beyond just adding to the partition key From: Carlos Alonso To: "user@cassandra.apache.org" Content-Type: multipart/alternative; boundary=047d7b62499cb80cb8052dcf11a4 --047d7b62499cb80cb8052dcf11a4 Content-Type: text/plain; charset=UTF-8 Hi Jason, If I understand correctly you have no problems with the size of your partitions or transactional queries but with the 'identification' of them when having to do analytical queries. I'd then suggest two options: 1. Keep using Cassandra and store the first 'bucket' of each sensor in a separate table to use as the starting point of your full scan queries. Then issue async queries incrementing the bucket until today (logical end of the data). Cassandra is very efficient at returning empty partitions, so querying on empty buckets is normally fine. 2. Periodically offload your 'historic' data to another storage more appropriate for analytics (Parquet + S3) and query it using Spark. Hope it helps On Saturday, 12 March 2016, Jack Krupansky wrote: > Thanks for the additional information, but there is still not enough color > on the queries and too much focus on a premature data model. > > Is this 5000 readings for a single sensor of a single sensor unit, or for > all sensors of a specified unit, or... both? > > I presume you want "next" and "previous" 5000 readings as well as first > and last, but... you will have to confirm that. > > One technique is to store the bulk of your raw sensor data in a separate > table and then simply store the PK of that data in your time series. That > way you can have a much wider row of time series (number of rows) without > hitting a bulk size issue for the partition. But... I don't want to jump to > solutions until we have a firmer handle on the query side of the fence. > > -- Jack Krupansky > > On Fri, Mar 11, 2016 at 5:37 PM, Jason Kania > wrote: > >> Jack, >> >> Thanks for the response. >> >> We are targeting our database design to 10000 sensor units and each >> sensor unit has 32 sensors. We are seeing about 700 events per day per >> sensor, each providing about 2K of data. Based on keeping each partition to >> about 10 Mb (based on readings we saw on performance), we chose to break >> our partitions on a weekly basis. This is possibly finer than we need as we >> were seeing timeouts only once a single partition was about 150Mb in size >> >> When pulling in data, we will typically need to pull 1 to 4 months of >> data for our analysis and will use only the sensorUnitId and sensorId to >> uniquely identify the data source with the timeShard value used to break up >> our partitions. We have handling to sequentially scan based on our >> "timeShard" value, but don't have a good handle on the determination of the >> "timeShard" portion of the partition key at read time. The data starts >> coming in when a subscriber starts using our system and finishes when they >> discontinue service or put the service on hold temporarily. >> >> When I talk about hotspots, it isn't the time series data that is the >> concern, it is with respect to storing the maximum and minimum timeShard >> values in another table for subsequent lookup or the cost of running the >> current implementation of SELECT DISTINCT. We need to run queries such as >> getting the first or last 5000 sensor readings when we don't know the time >> frame at which they occurred so cannot directly supply the timeShard >> portion of our partition key. >> >> I appreciate your input, >> >> Thanks, >> >> Jason >> >> ------------------------------ >> *From:* Jack Krupansky > > >> *To:* "user@cassandra.apache.org >> " < >> user@cassandra.apache.org >> > >> *Sent:* Friday, March 11, 2016 4:45 PM >> >> *Subject:* Re: Strategy for dividing wide rows beyond just adding to the >> partition key >> >> I'll stay away from advising on a specific schema per se, but I'll stick >> to the advice that you need to make sure that your queries are depending >> solely on the columns of the primary key or relatively short slices/scans, >> rather than run the risk of very long scans or having to process multiple >> partitions for a single query. That's canned to some extent, but still >> essential. >> >> Of course we generally wish to avoid hotspots, but with time series they >> are unavoidable. I mean, sure you could place successive events at separate >> partitions, but then you can't do any kind of scanning/slicing. >> >> But, events for separate sensors are not true hotspots in the traditional >> sense - unless you have only a single sensor/unit. >> >> After considering your queries, the next step is to consider the >> cardinality of your data - how many sensors, how many units, rate of >> events, etc. That will feedback into queries as well, such as how big a >> slice or scan might be, as well as sizing of partitions. >> >> So, how many sensor units do you expect, how many sensors per unit, and >> expected rate of events per sensor? >> >> Try not to jump too quickly to specific solutions - there really is a >> method to understanding all of this other stuff upfront. >> >> -- Jack Krupansky >> >> On Thu, Mar 10, 2016 at 12:39 PM, Jason Kania > > wrote: >> >> Jack, >> >> Thanks for the response. I don't think I provided enough information and >> used the wrong terminology as your response is more the canned advice is >> response to Cassandra antipatterns. >> >> To make this clearer, this is what we are doing: >> >> create table sensorReadings ( >> sensorUnitId int, >> sensorId int, >> time timestamp, >> timeShard int, >> readings blob, >> primary key((sensorUnitId, sensorId, timeShard), time); >> >> where timeShard is a combination of year and week of year >> >> For known time range based queries, this works great. However, the >> specific problem is in knowing the maximum and minimum timeShard values >> when we want to select the entire range of data. Our understanding is that >> if we update another related table with the maximum and minimum timeShard >> value for a given sensorUnitId and sensorId combination, we will create a >> hotspot and lots of tombstones. If we SELECT DISTINCT, we get a huge list >> of partition keys for the table because we cannot reduce the scope with a >> where clause. >> >> If there is a recommended pattern that solves this, we haven't come >> across it. >> >> I hope makes the problem clearer. >> >> Thanks, >> >> Jason >> >> ------------------------------ >> *From:* Jack Krupansky > > >> *To:* user@cassandra.apache.org >> ; Jason Kania >> > > >> *Sent:* Thursday, March 10, 2016 10:42 AM >> *Subject:* Re: Strategy for dividing wide rows beyond just adding to the >> partition key >> >> There is an effort underway to support wider rows: >> https://issues.apache.org/jira/browse/CASSANDRA-9754 >> >> This won't help you now though. Even with that improvement you still may >> need a more optimal data model since large-scale scanning/filtering is >> always a very bad idea with Cassandra. >> >> The data modeling methodology for Cassandra dictates that queries drive >> the data model and that each form of query requires a separate table >> ("query table.") Materialized view can automate that process for a lot of >> cases, but in any case it does sound as if some of your queries do require >> additional tables. >> >> As a general proposition, Cassandra should not be used for heavy >> filtering - query tables with the filtering criteria baked into the PK is >> the way to go. >> >> >> -- Jack Krupansky >> >> On Thu, Mar 10, 2016 at 8:54 AM, Jason Kania > > wrote: >> >> Hi, >> >> We have sensor input that creates very wide rows and operations on these >> rows have started to timeout regulary. We have been trying to find a >> solution to dividing wide rows but keep hitting limitations that move the >> problem around instead of solving it. >> >> We have a partition key consisting of a sensorUnitId and a sensorId and >> use a time field to access each column in the row. We tried adding a time >> based entry, timeShardId, to the partition key that consists of the year >> and week of year during which the reading was taken. This works for a >> number of queries but for scanning all the readings against a particular >> sensorUnitId and sensorId combination, we seem to be stuck. >> >> We won't know the range of valid values of the timeShardId for a given >> sensorUnitId and sensorId combination so would have to write to an >> additional table to track the valid timeShardId. We suspect this would >> create tombstone accumulation problems given the number of updates required >> to the same row so haven't tried this option. >> >> Alternatively, we hit a different bottleneck in the form of SELECT >> DISTINCT in trying to directly access the partition keys. Since SELECT >> DISTINCT does not allow for a where clause to filter on the partition key >> values, we have to filter several hundred thousand partition keys just to >> find those related to the relevant sensorUnitId and sensorId. This problem >> will only grow worse for us. >> >> Are there any other approaches that can be suggested? We have been >> looking around, but haven't found any references beyond the initial >> suggestion to add some sort of shard id to the partition key to handle wide >> rows. >> >> Thanks, >> >> Jason >> >> >> >> >> >> >> >> > -- Carlos Alonso | Software Engineer | @calonso --047d7b62499cb80cb8052dcf11a4 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Hi Ja= son,

If I understand correctly you hav= e no problems with the size of your partitions or transactional queries=C2= =A0but with the 'identification' of them when having to do analytic= al queries.

I'd then suggest= two options:
1. Keep using Cassandra and store the firs= t 'bucket' of each sensor in a separate table to use as the startin= g point of your full scan queries. Then issue async queries incrementing th= e bucket until today (logical end of the data). Cassandra is very efficient= at returning empty partitions, so querying on empty buckets is normally fi= ne.

2. Periodically offload your= 'historic' data to another storage more appropriate for analytics= =C2=A0(Parquet + S3) and query it using Spark.

Hope it helps

On Saturday, 12 March 2= 016, Jack Krupansky <jack.kr= upansky@gmail.com> wrote:
Thanks for the additional information, but there is still not enou= gh color on the queries and too much focus on a premature data model.
<= br>
Is this 5000 readings for a single sensor of a single sensor = unit, or for all sensors of a specified unit, or... both?

I presume you want "next" and "previous" 5000 r= eadings as well as first and last, but... you will have to confirm that.

One technique is to store the bulk of your raw senso= r data in a separate table and then simply store the PK of that data in you= r time series. That way you can have a much wider row of time series (numbe= r of rows) without hitting a bulk size issue for the partition. But... I do= n't want to jump to solutions until we have a firmer handle on the quer= y side of the fence.

-- Jack Krupansky

On Fri, Mar 11, 2016 at 5:37 PM, Jason Kania= <jason.kania@ymail.com&g= t; wrote:
Jack,

Thanks for th= e response.

We are targeting our database design to 10000 sensor uni= ts and each sensor unit has 32 sensors. We are seeing about 700 events per = day per sensor, each providing about 2K of data. Based on keeping each part= ition to about 10 Mb (based on readings we saw on performance), we chose to= break our partitions on a weekly basis. This is possibly finer than we nee= d as we were seeing timeouts only once a single partition was about 150Mb i= n size

When pulling in data, we will typically need to pull 1 to 4 mont= hs of data for our analysis and will use only the sensorUnitId and sensorId= to uniquely identify the data source with the timeShard value used to brea= k up our partitions. We have handling to sequentially scan based on our &qu= ot;timeShard" value, but don't have a good handle on the determina= tion of the "timeShard" portion of the partition key at read time= . The data starts coming in when a subscriber starts using our system and f= inishes when they discontinue service or put the service on hold temporaril= y.

When I talk about hotspo= ts, it isn't the time series data that is the concern, it is with respe= ct to storing the maximum and minimum timeShard values in another table for= subsequent lookup or the cost of running the current implementation of SEL= ECT DISTINCT. We need to run queries such as getting the first or last 5000= sensor readings when we don't know the time frame at which they occurr= ed so cannot directly supply the timeShard portion of our partition key.

I appreciate your= input,

Thanks,

Jason
=


From: Jack Krupansky <jack= .krupansky@gmail.com>
To: "user@cassandra.apache.or= g" <user@cassandra.apache.org&= gt;
Sent: Friday, March= 11, 2016 4:45 PM

Subject= : Re: Strategy for dividing wide rows beyond just adding to the = partition key

<= div dir=3D"ltr">I'll stay away from advising on a specific schema per s= e, but I'll stick to the advice that you need to make sure that your qu= eries are depending solely on the columns of the primary key or relatively = short slices/scans, rather than run the risk of very long scans or having t= o process multiple partitions for a single query. That's canned to some= extent, but still essential.

Of course w= e generally wish to avoid hotspots, but with time series they are unavoidab= le. I mean, sure you could place successive events at separate partitions, = but then you can't do any kind of scanning/slicing.

But, events for separate sensors are not true hotspots= in the traditional sense - unless you have only a single sensor/unit.

After considering your queries, the nex= t step is to consider the cardinality of your data - how many sensors, how = many units, rate of events, etc. That will feedback into queries as well, s= uch as how big a slice or scan might be, as well as sizing of partitions.

So, how many sensor units do you exp= ect, how many sensors per unit, and expected rate of events per sensor?

Try not to jump too quickly to specifi= c solutions - there really is a method to understanding all of this other s= tuff upfront.

-- Jac= k Krupansky

On Thu, Mar 10, 2016 at 12:39 PM, Jason Kania = <jason.kania@ymail.com> wrote:
=
=
Jack,

Thanks for the response. I don't think I provided enough inform= ation and used the wrong terminology as your response is more the canned ad= vice is response to Cassandra antipatterns.
<= div>
To make this clearer, this is what = we are doing:

=
create table sensorReadings (
sensorUnitId int,
sensorId int,
time timestamp,
timeShard int,
readings blob,
primary key((sensorUnitId, sensorId, timeShard), time);

where t= imeShard is a combination of year and week of year
For known time range based queries, this works = great. However, the specific problem is in knowing the maximum and minimum = timeShard values when we want to select the entire range of data. Our under= standing is that if we update another related table with the maximum and mi= nimum timeShard value for a given sensorUnitId and sensorId combination, we= will create a hotspot and lots of tombstones. If we SELECT DISTINCT, we ge= t a huge list of partition keys for the table because we cannot reduce the = scope with a where clause.

=
If there is a recommended pattern that solves this, = we haven't come across it.

I hope makes the problem clearer.

Thanks,

Jason


From: Jack Krupansk= y <jack.krup= ansky@gmail.com>
To: user@cassandra.apache.org; Jason Kania <jason.kania@ymail.com>
Sent:= Thursday, March 10, 2016 10:42 AM
Subject: Re: Strategy for dividing wide ro= ws beyond just adding to the partition key

There is an = effort underway to support wider rows:

This won't help you now though. Even with that improvement you still m= ay need a more optimal data model since large-scale scanning/filtering is a= lways a very bad idea with Cassandra.

The data modeling methodology for Cassandra dictates that queries drive = the data model and that each form of query requires a separate table ("= ;query table.") Materialized view can automate that process for a lot = of cases, but in any case it does sound as if some of your queries do requi= re additional tables.

As a general = proposition, Cassandra should not be used for heavy filtering - query table= s with the filtering criteria baked into the PK is the way to go.


-- Jack Krupansky

On Thu, Mar 10, 2016 at 8:54 AM, Jason Kania <= span dir=3D"ltr"><jason.kania@ymail.com> wrote:
<= div>
<= div>Hi,

We have sensor input that c= reates very wide rows and operations on these rows have started to timeout = regulary. We have been trying to find a solution to dividing wide rows but = keep hitting limitations that move the problem around instead of solving it= .

We have a partition k= ey consisting of a sensorUnitId and a sensorId and use a time field to acce= ss each column in the row. We tried adding a time based entry, timeShardId,= to the partition key that consists of the year and week of year during whi= ch the reading was taken. This works for a number of queries but for scanni= ng all the readings against a particular sensorUnitId and sensorId combinat= ion, we seem to be stuck.

We won't know the range of valid values of the timeShard= Id for a given sensorUnitId and sensorId combination so would have to write= to an additional table to track the valid timeShardId. We suspect this wou= ld create tombstone accumulation problems given the number of updates requi= red to the same row so haven't tried this option.

Alternatively= , we hit a different bottleneck in the form of SELECT DISTINCT in trying to= directly access the partition keys. Since SELECT DISTINCT does not allow f= or a where clause to filter on the partition key values, we have to filter = several hundred thousand partition keys just to find those related to the r= elevant sensorUnitId and sensorId. This problem will only grow worse for us= .

Are there any other approaches that can be suggested? We have bee= n looking around, but haven't found any references beyond the initial s= uggestion to add some sort of shard id to the partition key to handle wide = rows.

Thank= s,

Jason









--
Carlos Alonso | Software Engineer |=C2=A0@calonso

--047d7b62499cb80cb8052dcf11a4--