Slowness with Fluentnhibernate

Asked

Viewed 217 times

1

I am using Fluentnhibernate in a simple product registration application.

The first time I run something that accesses the database (product query screen or register a product) the site is loading for a long time. But after this first load the system does the same things quickly.

Example: I enter for the first time in the product consultation screen the system is loading for a long time. After it loads if I go back and access again the products query screen the system loads fast.

They know to inform me what the system loads in this first access and if it is possible to make it asynchronous right when loading the Home of the site?

Thank you.

  • Which database are you using? Is this slowness in any "first" query? Could you post your query in the question?

  • I am using SQL Server. Not necessarily query. If the first thing, with access to base, that I do on the site is the inclusion of the product then the inclusion that will take.

1 answer

1


Not necessarily will that be an answer, but maybe it’ll help you!

Settings

Some questions about your settings:

  1. How you are setting up the Nhibernate session?
  2. Is using which Schema? SchemaUpdate? SchemaExport?
  3. Nhibernate is creating their tables?

Basically these settings tell if Nhibernate will compare the metadata of its tables with its Mapping, and if it will create some DDL(Data Definition Language) in the database (This impacts directly on the first connection).

I can demonstrate 3 configuration scenarios to compare with your settings:

  • new SchemaExport(cfg).Create(false, true); // apagar o database e criar novamente todas as tabelas (recommended only for use in tests, as the data/tables will be deleted every new connection, NEVER in production);
  • new SchemaUpdate(cfg).Execute(false, true); // atualizar o database, acrescentando novas tabelas e colunas sem excluir o que não está no mapeamento (recommended for use in testing, and in the development phase while modelling the tables, NEVER in production, as it will compare the database media with the mapping and add the Ddls that are not in the database);
  • new SchemaExport(cfg).Create(false, false); // normal, não criar nenhum DDL no database (Recommended, for any stage of development, if you do not want Nhibernate to change its database structure, and this setting does not compare metadata and does not create any DDL when creating the connection, MUST be used in production, because it is the configuration that has least overflow at startup).

About booting Nhibernate when booting the system!

You can initialize the Nhibernate connection at any time by running any routine in the database (query, Insert, etc).

You can simply in the Home Controller make a simple query to initialize Nhibernate. Or you can do this at system startup, such as at Application_Start() in the Globa.asax.cs in the case of ASP.NET < 5, or Startup.cs on ASP.NET 5.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.