Skip to content

Dt performance patch 1 - #2416

Closed
dtomlins wants to merge 3 commits into
opensourcepos:masterfrom
dtomlins:dt-performance-patch-1
Closed

dtomlins wants to merge 3 commits into
opensourcepos:masterfrom
dtomlins:dt-performance-patch-1

Conversation

@dtomlins

Copy link
Copy Markdown

Upload version 2. I have no idea how from a bad repo - I just forked 2 days ago!

THIS MOD REQUIRES DATABASE CHANGE:
create index trxbydate ospos_inventory (trans_date);

This is the commented version, with a lot of "commented" code in case re-instatement is necessary,
as well as give a better idea of the changes.

Query times on mine (62,000 items, 1.07 million inventory transactions) drops from
62.5 + 31.6 seconds (94.1) on opening to a typical 0.62 seconds on opening + .05 if transactions are queried.

Searching by date through ospos_inventory is NOT required or done on initial load, but only if selected in the options box. Option added for transactions in date range AND no transactions in date range.

Ideally the checkmarks would be mutually exclusive, but has_transactions has precedence.

** Uses SQL_CALC_FOUND_ROWS to populate next query FOUND_ROWS() to eliminate time required to count the records again - saving typically .32 of a second. (was 32 seconds)
** has to turn off dbprefix temporarily in controller to convince CodeIgniter that it isn't a table needing pre-fixing.

I look forward to your comments!
Dan

@dtomlins dtomlins mentioned this pull request Mar 26, 2019
Minor change to "suggest" that the MEMORY engine be used for the temporary table.
This on my data changes the typical execution time from:
  Create temporary:   0.65
  Drop temporary:      0.10
to: 
  Create temporary:   0.003
  Drop temporary:      0.0006

It's only 3/4 of a second per instance, but on a page of 50 queries it is very significant.

@jekkos jekkos left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some cool suggestions here (like using engine = memory ) and getting rid of the group_by in items, but then we need proper testing of the functionality involved here.

// create a temporary table to contain all the sum and average of items
$this->db->query('CREATE TEMPORARY TABLE IF NOT EXISTS ' . $this->db->dbprefix('sales_items_temp') .
' (INDEX(sale_id))
' (INDEX(sale_id)) ENGINE=MEMORY

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't know about this one but looks like a neat little trick. According to docs performance is dependent on how you have configured your database server.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's one of the "little" things. Most of them are. ENGINE=MEMORY drops just about 3/4 of a second ... not enough to worry about, until it is repeated 25, 50 or 100 times.
I want to test against a different version of storage engine too. MEMORY works well for THAT query, and would help the next except it isn't allowed. The GROUP_CONCAT creates a "text" field that cannot be in that engine.
My DevTest server is "small" settings by design. So I design for good performance once the code escapes into the real world. When the result exceeds the size of memory allocated it fails badly. Yes, the error is logged, but the operator screen shows no data. Not even an error message.

Comment thread application/models/Item.php Resolved
$this->db->where('DATE_FORMAT(trans_date, "%Y-%m-%d") BETWEEN ' . $this->db->escape($filters['start_date']) . ' AND ' . $this->db->escape($filters['end_date']));
// $this->db->where('DATE_FORMAT(trans_date, "%Y-%m-%d") BETWEEN ' . $this->db->escape($filters['start_date']) . ' AND ' . $this->db->escape($filters['end_date']));
$this->db->where('items.item_id in (select distinct(trans_items) from ospos_inventory use index (trxbydate) where trans_date BETWEEN ' . $this->db->escape($filters["start_date"]) . ' AND ' . $this->db->escape($filters["end_date"] . ' 23:59:59') . ' AND trans_location = ' . $filters["stock_location_id"] . ')' ); //dmt
} elseif ($filters['no_transactions'] != FALSE)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mind indentation here

}

// avoid duplicated entries with same name because of inventory reporting multiple changes on the same item in the same date range
$this->db->group_by('items.item_id');

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree that it would be a lot cleaner to get rid of the group by, but it's indeed still needed by attributes.
Also removing the inventory query will probably break the date filtering functionality.

If you can find a way to reconstruct the full resultset by for example appending results of different queries then that would be nice.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll look at the attributes, if I can figure what they are best used for, but a quick look at them didn't show that they would create multiple returned data. Duplicates would be thrown out by the group by anyway!
I'm still trying to figure out the "operator setup" part of the taxes! Looks like it could work, sort-of for here (Canada), but figuring out where to put numbers has me stumped. Putting the tax-rate into each of the thousands of products is a non-starter! What happens when the rate changes? Edit all the products? I don't think that's yours though :)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sure @SteveIreland would love to hear about your Taxation requirements. He brilliantly reworked all of this.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The group was required for the inventory issue to remove duplication. Please test that report.

We should really build a test harness for the models to help with any refactoring.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thinking about it further, I feel that it might be better to use a separate query if the date filtering is used only. It will simplify the main query a lot and probably yield result quite a bit faster.

@daN4cat

daN4cat commented Apr 28, 2019

Copy link
Copy Markdown
Collaborator

@dtomlins any progress with your improvements?

@daN4cat daN4cat left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I block this because it cannot be merged as it stands

@ebrahimidelawar

Copy link
Copy Markdown

hello dear friends
please Loading speed very slow with large DB in item option please help me dear friend

@ebrahimidelawar

Copy link
Copy Markdown

hello dear friend
please Loading speed very slow with large DB in item page please i don't want show page of item?

@ebrahimidelawar

Copy link
Copy Markdown

i install new wamp and new version of opensourcepos .3.4.0 but not solve my problem please help me?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants