举一个简单的例子:
现在淘宝,一号店等一系列电商都有自己的开放平台。我现在的程序调用淘宝开放平台的上传商品接口来上传商品。并且把上传的实体通过JSON格式存储在数据库中。那么这里就会出现两种储存结果:
这两种方式,当上传接口返回错误信息的时候。第一种方式重现需要将数据库里面的数据取出来,然后跑测试用例,而第二种方式将数据取出来,直接通过main方法就可以重现。其实这两种方法的复杂程度是差不多的,但是第二种查起来可能会更加快。因为不用去跑测试用例(测试用例每跑一次加载配置项的时间让人不能忍),这里会节省一点时间。
问题:数据库存储的数据的最终形态究竟应该是怎么样的呢?像上面第一种和第二种方式哪种比较优?而这个最终形态是否需要考虑程序排查问题的方便性?
PHP中文网2017-04-17 13:29:17
I personally think that the final form in the database should be viewed this way, requirements > = performance > implementation.
I classified what you said about "considering program troubleshooting" into the implementation method. Whenever the demand is greater than anything else, you must first have the demand and then have the project for you to do. Of course, you must also consider In actual sacrifices, the performance may not be reliable after the requirements are realized, so some requirements need to be sacrificed to achieve the standard performance. This is complementary. The final consideration is how to make the implementation more nice. Of course, if the implementation is more convenient but the performance difference is not big, it is better to pay more attention to implementation. After all, this thing requires people to do and maintain...
The final purpose of the above two methods is the same. If there are no special requirements (the db must be saved like this!), what needs to be considered is the performance issue. There is no mention of prerequisites or environmental factors, then we The performance of the second method may be better than the first method, because it just takes the data from the db and saves it, while the first method has to be modified before saving, which is not good. But the first one may seem more general, and it is possible that the pre-existing things in the second one are too targeted or too simple, and are not as general as the first one.
In fact, after saying so much, you should understand what is important in the project. You can put it later when considering program troubleshooting.
Let’s take another example. I remember that there was a project before that really tested the performance (such as the number of processes per second). After optimizing for a period of time, it almost reached the standard. In the end, I had to remove some logs during program processing ( It turns out that logging is time-consuming and unnecessary). These logs are added to make it easier to troubleshoot problems, but they cannot affect the performance we are concerned about.