简体   繁体   English

实体框架代码首先在生产中使用mysql

[英]Entity Framework code first with mysql in Production

I am creating an asp.net * MVC * application using EF code first. 我首先使用EF代码创建一个asp.net * MVC *应用程序。 I had used Sql azure as my database. 我曾使用Sql azure作为数据库。 But it turns out Sql Azure is not reliable. 但是事实证明Sql Azure是不可靠的。 So I am thinking of using MySql/PostgreSQL for database. 因此,我正在考虑将MySql / PostgreSQL用于数据库。

I wanted to know the repercussions/implications of using EF code first with MySql/PostgreSQL in regards of performance . 我想知道在性能方面首先在MySql / PostgreSQL中使用EF代码的影响/含义 Has anyone used this combo in production or knows anyone who has used it? 有人在生产中使用过此组合吗?还是知道有人使用过该组合?

EDIT 编辑
I keep on getting following exceptions in Sql Azure . 我继续在Sql Azure中获取以下异常。

SqlException: "*A transport-level error has occurred when receiving results from the server.* 
(provider: TCP Provider, error: 0 - An existing connection was forcibly closed by the remote host.)"

    SqlException: *"Database 'XXXXXXXXXXXXXXXX' on server 'XXXXXXXXXXXXXXXX' is not
 currently available. Please retry the connection later.* If the problem persists, contact
 customer support, and provide them the session tracing ID of '4acac87a-bfbe-4ab1-bbb6c-4b81fb315da'.
 Login failed for user 'XXXXXXXXXXXXXXXX'."

First your problem seems to be a network issue, perhaps with your ISP. 首先,您的问题似乎是网络问题,也许与您的ISP有关。 You may want to look at getting a remote PostgreSQL or MySQL db I think you will run into the same problems. 您可能想看看获得远程PostgreSQL或MySQL数据库,我想您会遇到同样的问题。

Secondly comparing MySQL and PostgreSQL performance is relatively tricky. 其次,比较MySQL和PostgreSQL的性能比较棘手。 In general, MySQL is optimized for pkey lookups, and PostgreSQL is more generally optimized for complex use cases. 通常,MySQL针对pkey查找进行了优化,而PostgreSQL更针对复杂的用例进行了优化。 This may be a bit low-level but.... 这可能有点低级,但是....

MySQL InnoDB tables are basically btree indexes where the leaf note includes the table data. MySQL InnoDB表基本上是btree索引,其中叶笔记包括表数据。 The primary key is the key of the index. 主键是索引的键。 If no primary key is provided, one will be created for you. 如果没有提供主键,则会为您创建一个。 This means two things: 这意味着两件事:

  1. select * from my_large_table will be slow as there is no support for a physical order scan. 由于不支持实物订单扫描,因此select * from my_large_table将变慢。

  2. Select * from my_large_table where secondary_index_value = 2 requires two index traversals sinc ethe secondary index an only refer to the primary key values. Select * from my_large_table where secondary_index_value = 2需要两个索引遍历,从第二个索引开始,第二个索引仅引用主键值。

In contrast a selection for a primary key value will be faster than on PostgreSQL because the index contains the data. 相反,由于索引包含数据,因此对主键值的选择将比在PostgreSQL上更快。

PostgreSQL by comparison stores information in an unordered way in a series of heap pages. 相比之下,PostgreSQL以无序方式将信息存储在一系列堆页面中。 The indexes are separate from the data. 索引与数据是分开的。 If you want to pull by primary key you scan the index, then read the data page in which the data is found, and then pull the data. 如果要通过主键进行拉动,请扫描索引,然后读取在其中找到数据的数据页,然后拉动数据。 In comparison, if you pull from a secondary index, this is not any slower. 相比之下,如果从二级索引中拉出,则速度不会降低。 Additionally, the tables are structured such that sequential disk access is possible when doing a long select * from my_large_table will result in the operating system read-ahead cache being able to speed performance significantly. 另外,这些表的结构使得当对select * from my_large_table进行长select * from my_large_table时,可以进行顺序磁盘访问select * from my_large_table将导致操作系统select * from my_large_table读缓存能够显着提高性能。

In short, if your queries are simply joinless selection by primary key, then MySQL will give you better performance. 简而言之,如果您的查询只是通过主键进行的无连接选择,那么MySQL将为您提供更好的性能。 If you have joins and such, PostgreSQL will do better. 如果您有这样的联接,PostgreSQL会做得更好。

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

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