Slowness with FluentNHibernate

1

I'm using FluentNHibernate in a simple product registration application.

The first time I run something that accesses the database (product query screen or a product registration), the site will load 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 query screen the system keeps charging for a long time. After that loads if I go back and access the product query screen again the system loads fast.

Are you able to tell me what the system loads on this first access and if it is possible to make it asynchronous soon after loading the site's home?

Thank you.

    
asked by anonymous 10.05.2016 / 18:36

1 answer

0

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

Settings

Some questions about your settings:

  • How are you configuring the NHibernate session?
  • Are you using Schema? SchemaUpdate ? SchemaExport ?
  • Is NHibernate creating your tables?
  • Basically these settings will tell if NHibernate will compare the metadata of your tables with your Mapping, and whether you will create some DDL 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 to use in tests, since the data / tables will be erased with each 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 tests, and in the development phase while modeling tables, NEVER in production , as it will compare the metadata of the database 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 development phase, if you do not want NHibernate to change its database structure, and this setting does not make metadata comparison and does not create any DDL when creating the connection, MUST be used in production , because it is the least configuration overflow at startup).

    About initializing NHibernate at system startup!

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

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

        
    18.05.2016 / 14:05