简体   繁体   English

数据库设计,有关实现的问题

[英]database design, question about implementation

Question regarding my sql database design for a project i am working on. 有关我正在从事的项目的sql数据库设计的问题。

I will be receiving data every few seconds and i am going to need to store that data into a database. 我将每隔几秒钟接收一次数据,我需要将这些数据存储到数据库中。 I am using mySQL for my DBMS. 我正在将mySQL用于我的DBMS。 The data needs to be stored in the database with a userid attached to each piece of data. 数据需要存储在数据库中,并在每个数据上附加一个用户ID。 I will only be handling one user per application. 每个应用程序只能处理一个用户。 So, each instance of the application will only be handling one users data. 因此,该应用程序的每个实例将仅处理一个用户数据。 The remote database will be storing all users data though. 但是,远程数据库将存储所有用户数据。 So, that is why i need userid's to know whose data is whose. 所以,这就是为什么我需要用户ID知道谁的数据是谁的原因。

My idea was to wait until i receive like 50 data packets and create a delimited string of all 50 data packets. 我的想法是等到我收到50个数据包并创建所有50个数据包的分隔字符串。 (Maybe separated by commas) Then push that string to the database along with the userid. (也许用逗号分隔)然后将该字符串与用户ID一起推送到数据库。 And store the data like that. 并像这样存储数据。 My question is, is that a good way to do it? 我的问题是,这是个好方法吗? Is there a better way? 有没有更好的办法? Is this bad practice? 这是不好的做法吗? TIPS PLEASE! 提示! =) =)

I will be receiving a lot of this data. 我将收到很多此类数据。 One data packet like every second, sometimes faster. 一个数据包每秒一样,有时更快。 Just let me know what you think. 请让我知道您的想法。

The DBMS will be running on a remote machine. DBMS将在远程计算机上运行。 The application will be running on an android phone. 该应用程序将在Android手机上运行。

Thanks in advance! 提前致谢!

I would not suggest concatenating a bunch of values together to send a delimited string to the database. 我不建议将一堆值连接在一起以将定界字符串发送到数据库。 That just creates additional work on the database to parse the string. 这样只会在数据库上创建其他工作来解析字符串。

Any reasonable framework for interacting with the database will let you create and send batches of SQL statements with different values for the bind variables to the database. 任何与数据库交互的合理框架都可以让您创建绑定变量并将不同值的SQL语句批次发送到数据库,并将其发送给数据库。 That keeps the nice, friendly syntax of the stored procedure or INSERT statement, it keeps the database properly normalized, and it accomplishes the performance goal of minimizing the number of round-trips. 这样可以保留存储过程或INSERT语句的优美而友好的语法,可以使数据库正确规范化,并且可以实现将往返次数最小化的性能目标。

The question you really have to answer is the tolerance you have for losing data. 您真正要回答的问题是丢失数据的容忍度。 A request per second transferring under 1k of data isn't much, especially using json vs. xml. 每秒传输1k数据以下的请求并不多,尤其是使用json和xml。 Then again, battery life is something to keep in mind on mobile devices, so making a request every 5-60 seconds is also doable. 再说一次,在移动设备上要牢记电池寿命,因此每5-60秒发出一次请求也是可行的。

There's no reason you cannot batch your updates to the server. 没有理由您无法将更新批处理到服务器。

If you have no tolerance for data loss, you could collect your batch of 50 updates on local storage, and upload them. 如果您对数据丢失没有容忍度,则可以在本地存储上收集50批更新,然后上载它们。 If a failure occurs in transmission you can resend. 如果传输失败,您可以重新发送。 In this case, however, I would want to have some record ID that's reasonably guaranteed to be unique, such as a UUID. 但是,在这种情况下,我希望有一些记录ID,可以合理保证它是唯一的,例如UUID。 This way the server can see which records it's already processed and exclude them from reprocessing. 通过这种方式,服务器可以查看已处理的记录,并将其从重新处理中排除。

If the dbms is running on a good server, and all you do with the data is a simple insert to a reasonably simple table, 1 insert per second should not a strain at all. 如果dbms在良好的服务器上运行,并且您对数据所做的只是对一个相当简单的表的简单插入,那么每秒1次插入应该一点也不费劲。 I'd expect it to be hardly measurable. 我希望它几乎无法测量。

I'm going to address the issue of storing it as a delimited string. 我将解决将其存储为定界字符串的问题。 HOw do you intend to query this data after it is stored? 存储数据后,您打算如何查询? If you will need to find the data for one or aeven a small group of values but not the entire string, donot consider storing the data this way as it will give you horrible performance in querying and will be very painful to write queries for. 如果您需要查找一个或一组很小的值而不是整个字符串的数据,则不要考虑以这种方式存储数据,因为这将给您带来可怕的查询性能,并且为查询编写代码将非常痛苦。 In general, storing more than one piece of dat ina field is a bad thing, it means you need a related table. 通常,存储多个dat ina字段是一件坏事,这意味着您需要一个相关的表。

Also, for what you are doing, if you don't need to to analytical querying of the data, perhaps a nosql database would be a better choice than a relational database. 同样,对于您正在做的事情,如果您不需要分析数据的查询,也许nosql数据库比关系数据库是更好的选择。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM