This is a migrated thread and some comments may be shown as answers.

Fluent Mapping Performance

5 Answers 90 Views
Data Access Free Edition
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Richard
Top achievements
Rank 1
Richard asked on 26 Apr 2016, 01:27 AM

     We are using Data Access with WebAPI to supply data to our website.  We have been using JMeter to test a simple web method to return data.  Even through our LINQ and resultant SQL from the LINQ does not change the more columns that we map the slower the throughput gets.  Mapping 5 columns we can achieve 200 requests per second, but with 100+ columns mapped we are suddenly down to 10 requests per second.  Again the SQL statements do not change in this case only the number of columns being mapped that are never even used.  A sample of our mapping code is below.  We have also tested progressively adding columns and it gets worse the more that you add (progressively getting slower).  Can someone help explain this behavior?  Thank you.

 

var configuration = new MappingConfiguration<Sku>();
            configuration.MapType().ToTable("SKU");      
     configuration.HasProperty(x => x.ImageRecnbr).IsIdentity().HasFieldName("_imagerecnbr").WithDataAccessKind(DataAccessKind.ReadWrite).ToColumn("IMAGE_RECNBR").IsNotNullable().HasColumnType("decimal").HasPrecision(10).HasScale(0);
            configuration.HasProperty(x => x.SkuInternal).HasFieldName("_skuinternal").WithDataAccessKind(DataAccessKind.ReadWrite).ToColumn("SKU_INTERNAL").IsNotNullable().HasColumnType("decimal").HasPrecision(9).HasScale(0);

5 Answers, 1 is accepted

Sort by
0
Richard
Top achievements
Rank 1
answered on 26 Apr 2016, 03:08 PM
 I have been able to verify that the older rlinq equivalent does not exhibit this behavior.  It seems to be a newly introduced issue.  Since fluent mapping is only the option moving forward this is serious concern for us.
0
RIT
Top achievements
Rank 1
answered on 27 Apr 2016, 11:24 AM

Hi Richard

How have you measured your throughput? We saw a similar issue, that can be solved by instantiating the MetadataContainer only once:

before:

    public partial class Db : OpenAccessContext, IDbUnitOfWork
    {
        private static string connectionStringName = @"myconnectionstringname";
             
        private static readonly BackendConfiguration Backend = GetBackendConfiguration();
 
        private static readonly MetadataSource MetadataSource = new DbMetadataSource();
...

after:

    public partial class Db : OpenAccessContext, IDbUnitOfWork
    {
        private static string connectionStringName = @"myconnectionstringname";
             
        private static readonly BackendConfiguration Backend = GetBackendConfiguration();
 
        private static readonly MetadataContainer metadataContainer = new DbMetadataSource().GetModel();
...

So the context will not build the model every time you instantiate a new context. This has a big impact if your MetadataSource is big...

Greetings,

Florian

0
Richard
Top achievements
Rank 1
answered on 27 Apr 2016, 09:48 PM

We have used JMeter to perform all of our performance testing. We did create a static instance of the MetadataContainer.  The performance was much worse before we did.  We created and populated the container on application start.

 

0
Richard
Top achievements
Rank 1
answered on 27 Apr 2016, 10:08 PM
I spoke too soon!  I thought that we had done that, but in fact we only created a static instance as in your first example.  Thank you for the help!!
0
egoren
Top achievements
Rank 1
answered on 25 Apr 2017, 07:14 PM

Hi Florian,

I just wanted to thank you for posting this solution. It saved my day.

We were experiencing performance degradation after switching to the Fluent mapping, and we were about to rollback the upgrade.

changing private static readonly MetadataSource MetadataSource = new DbMetadataSource(); to private static readonly MetadataContainer metadataContainer = new DbMetadataSource().GetModel(); and using a different constructor fixed the problem!

Thanks again, Eyal.

Tags
Data Access Free Edition
Asked by
Richard
Top achievements
Rank 1
Answers by
Richard
Top achievements
Rank 1
RIT
Top achievements
Rank 1
Richard
Top achievements
Rank 1
egoren
Top achievements
Rank 1
Share this question
or