Initial development of ASP. VNext sequel: Cloud Optimization concept, Entity Framework 7.0, current performance is not good enough

Source: Internet
Author: User

After continuing with an initial summary of the development of ASP. NET VNext (using Visual Studio CTP1),

About cloud optimization and version control:

I wanted to do the self-host test for Mac and Linux, but the official said that the mono version of the operating environment required at least 3.4.1, I bought a watch last year, until the publication of this article, you let me go to Hell to find 3.4.1, with the 3.4.0 to make a night, Mac has been stuck in Httpapi.dll error, Ubuntu Server 12.0.4 is not recognized a few of the DLL package, specifically which several also forget, over a period of time have a stable version and then get it.

However, I've probably learned about what it calls "cloud optimization", and let's look at the complete steps to run a project in a non-Windows environment:

    1. After deploying the production environment code to a completely new platform (*nix and Mac), enter the current code directory
    2. Run the sudo kpm restore command
    3. The K runtime environment automatically restores the packages required for the current entire project based on the individual namespaces recorded in the Project.json
    4. Package is saved to local
    5. Run K Web, start self-host mode, or K run, start the third-party hosting mode such as Nginx. The "Web" and "run" parameters correspond to the corresponding node configuration in Project.json.

In step 3, different systems will get different packages, which is called Cloud optimization .

If you later need to update the version of the package, using KPM upgrade to update, is still manual, in addition to the ". NET 4.5 core" the most core namespace is loaded from the system, the rest of the entire operating environment required by all the packages, are stored in your own current directory, Load run from your own directory, equivalent to " green " ASP., for example, there are always some features that even if you put the DLL into the bin is useless, it must be installed through the system can be used, and now, it can be 100% Guarantee that all of the functionality you need can be addressed by deploying DLLs to the Bin directory, and the practical point is that AWS and Azure Linux hosts do not allow us to run the root user, and there is always something that we can't even install with sudo, which is just one example, So now you know what I mean. In turn, we can deploy different versions of the same application to different directories, bind different domain names, and completely isolate their run-time contexts, which is what each application can run in different versions .

concerns about loading packages from NuGet :

First boot it does not automatically go to NuGet to load, the next time how to reboot will not go to NuGet auto-load, everything involved in nuget behavior requires you to manually control, restore only 100% successfully loaded after your application can run, or rollback, Upgrade also must be 100% successful, or rollback, you think of it as a "transaction" to understand it, will not be "loading" the matter on your application impact.

This nuget is also not a nuget, and by default it will load packages to the NuGet official server, but KPM Restore and upgrade can specify different source addresses, and if you prefer, you can specify to 127.0.0.1. So there's no need to worry about deployment.

about VS2014:

According to Microsoft's unspoken rules, when a component is still in beta, its namespace is: Microsoft.XXX.XXX, which becomes System.XXX.XXX after the release of the official version. Many of these packages are currently under Microsoft's name.

My current VS2014 CTP1 is unloading the machine's 2013, 2012, 2010 after the smooth installation, but also do not know that I unload the process of unloading the wrong thing or VS2014 CTP1 itself mischief, my system of SQL Server honorable sacrifice dropped, Reinstall SQL Server again (fix installation), although it said it could not coexist with the old version of VS on the same machine, but I later installed the VS2013.2 again, everything works fine. (risk, do not imitate, I am not responsible for all consequences)

Sometimes you edit a project, everything is calm, but when you save, close vs2014, open vs2014 again after opening the project, the "reference list" in the project will stay in the loading state, restart a few times after the good, who knows why.

All things pay attention to good match, since the Times have entered the Vnext, without EF 7.0 how worthy of D and the people:

Entity Framework 7.0: More concise, hateful migration finally leave

(Entity Framework 7.0 can be run independently of Vnext, running on mvc1~5.x)

After creating the good one demo database, take a look at:

In the past, the biggest problem encountered when using migration, not the migration step itself, but from time to time: "Already exist the same table or object", the various solutions are strange, even need to modify the migration automatically generated files, their own game to play the project will forget, Real-world real-time production environment How dare you do that?

In the past, the migration table has recorded the structure of each data table hash value, if you manually modify the table structure, even if the actual structure has been maintained consistency, but the Entity Framework will still error, because the hash value is not correct, It only believes its own migration, although the application can be initialized during the shutdown of the data structure check to cross the migration step, but still flustered, go out and brag also afraid to be caught handle. Now that migration is finally gone, it means you can manually modify the table structure to synchronize with the code first structure, it will never be smart to embarrass you.

Another benefit: By eliminating this feature, it also means saving a lot of development and testing steps, the EF team is able to focus more on the core functionality of the EF itself, faster updates/fixes, and third-party database developers can release/update the entity corresponding to their own database more quickly Framework frameworks.

You can still use migration, the system separates this function to place in the Microsoft.Data.Entity.Migration space, as to how to use, I did not study.

In the past, at run time, the Entity Framework automatically checks for the existence of a database, automatically creates a database if it does not exist, and creates all corresponding structures, such as the corresponding table. Now this feature needs to be opened manually, and the "CREATE Database" and "CREATE TABLE" are different, like this:

?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 /// <summary> /// 数据库操作类 /// </summary> public class DBOperator : DbContext {     public DBOperator()     {         if (!Database.Exists())         {             Database.Create(); //创建数据库             Database.CreateTables(); //创建表         }     }    public DbSet<Customers> Customers { get; set; }    protected override void OnConfiguring(DbContextOptions builder)     {         builder.UseSqlServer(@"Server=HP\SQLSERVER;Database=vNextTest;Trusted_Connection=True;MultipleActiveResultSets=true");     } }

In the 1~6.x version, you can remove the constructor, no problem, the system will automatically create the database and table, but now, if you delete the constructor in the code example above, the database will not be created at the beginning, which raises the thinking: in the actual operation of the process, 99.9999999999% of the situation is not necessary to go if (! Database.exists ()), we can do this by building a polymorphic structure to ensure maximum performance:

?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 public abstract class DBO : DbContext {     public DbSet<Customers> Customers { get; set; }    protected override void OnConfiguring(DbContextOptions builder)     {         builder.UseSqlServer(@"Server=HP\SQLSERVER;Database=vNextTest;Trusted_Connection=True;MultipleActiveResultSets=true");     } }public sealed class DBOperator : DBO {     //实际运行时使用这个类     //省去不需要的判断 }public sealed class FirstTime : DBO {     public FirstTime()     {         //系统第一次运行时使用这个类,把它放在Started.cs中执行一次就好了         if (!Database.Exists())         {             Database.Create(); //创建数据库             Database.CreateTables(); //创建表         }     } }

Set Project.json, enable entity:

?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 {     "dependencies": {         "Helios" : "0.1-alpha-build-0585",         "Microsoft.AspNet.StaticFiles": "0.1-alpha-build-0443",         "Microsoft.AspNet.Mvc": "0.1-alpha-build-1268",         "Microsoft.AspNet.Server.WebListener": "0.1-alpha-build-0520",         "Microsoft.Data.Entity": "0.1-alpha-build-*", //启用Entity         "Microsoft.Data.Entity.SqlServer": "0.1-alpha-build-0863", //启用SQL Server         "Microsoft.DataAnnotations": "0.1-alpha-build-0100", //启用DataAnnotations         "Microsoft.Framework.ConfigurationModel": "0.1-alpha-build-0233" //启用配置文件操作     },     "configurations" : {         "net45" : { },         "k10" : { }     } }

Other SaveChange, add and other operations as before, do not say.

Fellow people, from now on, please throw away migration.

Vnext runs in self-host mode and IIS mode, compared to traditional MVC 5.x

Here is the use of AB to do a simple stress test of vnext, mainly on the throughput has a psychological concept, controller in the Fibonacci sequence 30 iterations, view is empty, only the simple HTML output, the client simulated 1000 users for a total of 10,000 visits. Before each test, it is accessed through IE once (eliminate the initial boot).

?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 public IActionResult Index() {     var x = new int[30];     var length = x.Length;     for (int n = 0; n < 30; n++)     {         switch (n)         {             case 0:                 x[n] = 1;                 break;             case 1:                 x[n] = 1;                 break;             default:                 x[n] = x[n - 1] + x[n - 2];                 break;         }         this.Context.Response.WriteAsync((x[n]).ToString() + "<br />");     }    return View(); }

It is said in the picture, I hope the official version will be better after the situation.

Issues that are not currently resolved

*nix environment is not configured, if there is a brother willing to toss, please see their official note: Https://github.com/aspnet/home

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.