简体   繁体   English

NetSuite restlet 写入性能较差

[英]NetSuite restlet write performance is poor

Edit: I've redacted actual numbers and replaced them with pseudoswears because I've been told sharing performance data is against Netsuite's TOS.编辑:我已经编辑了实际数字并用伪誓言替换了它们,因为我被告知共享性能数据违反了 Netsuite 的 TOS。

I'm integrating our accounting system with NetSuite using restlets, and overall it has gone pretty well with the glaring exception of performance.我正在使用 restlets 将我们的会计系统与 NetSuite 集成,总体而言,除了性能方面的明显异常外,它进展顺利。 I have figured out that nlapiLoadRecord is Satan's own child from a performance perspective, so I avoid it whenever possible favoring the search api and now my read restlets are pretty snappy.从性能的角度来看,我已经发现 nlapiLoadRecord 是撒旦自己的孩子,所以我尽可能避免使用它,有利于搜索 api,现在我的 readrestlets 非常活泼。 However, whenever I ask a restlet to write anything it is as slow as a tortoise stuck in cold tar.然而,每当我让restlet写任何东西时,它就像一只困在冷焦油中的乌龟一样慢。 I'm generally profiling the nlapiSubmitRecord itself at between SLOW and REALLY DAMN SLOW seconds.我通常在SLOWREALLY DAMN SLOW秒之间分析 nlapiSubmitRecord 本身。 This seems insane to me.这对我来说似乎很疯狂。 No one would use NetSuite if the performance were always this poor for writing.如果编写性能总是如此糟糕,那么没有人会使用 NetSuite。 I'll include a couple of code examples below.我将在下面包含几个代码示例。 Any tips on speeding up NetSuite restlet write performance would be appreciated.任何有关加快 NetSuite restlet 写入性能的提示将不胜感激。

In this first one receivedInvoice is the incoming data, and findCurrencyCode and findCustomerByCustomerNumber are well performing functions that do those things.在这第一个 receivedInvoice 是传入数据, findCurrencyCode 和 findCustomerByCustomerNumber 是执行这些操作的性能良好的函数。 I just clocked this at a nearly unbelievable HOLY MONKEYS THAT IS SLOW seconds for a simple invoice with one line item, nearly all of the time passing while I waited for nlapiSubmitRecord to finish.我刚刚在一个几乎令人难以置信的HOLY MONKEYS计时,对于一个带有一个行项目的简单发票,几乎所有的时间都在等待 nlapiSubmitRecord 完成。

var createdInvoice = nlapiCreateRecord('invoice');

createdInvoice.setFieldValue('customform', Number(receivedInvoice.transactionType));
createdInvoice.setFieldValue('memo', receivedInvoice.message);
createdInvoice.setFieldValue('duedate', receivedInvoice.dateDue);

createdInvoice.setFieldValue('currency', findCurrencyCode(receivedInvoice.currencyUnit));
createdInvoice.setFieldValue('location', Number(receivedInvoice.location));
createdInvoice.setFieldValue('postingperiod', findPostingPeriod(receivedInvoice.datePosted));
var customer = findCustomerByCustomerNumber(receivedInvoice.customerNumber);

createdInvoice.setFieldValue('entity', customer.customerId );
createdInvoice.setFieldValue('custbody_end_user', customer.customerId );
createdInvoice.setFieldValue('department', customer.departmentId);

var itemCount = receivedInvoice.items.length;
for(var i = 0; i < itemCount; i++)
{
  createdInvoice.selectNewLineItem('item');
  createdInvoice.setCurrentLineItemValue('item', 'item',receivedInvoice.items[i].item);
  createdInvoice.setCurrentLineItemValue('item', 'quantity', receivedInvoice.items[i].quantity);
  createdInvoice.setCurrentLineItemValue('item', 'rate',receivedInvoice.items[i].price);
  createdInvoice.setCurrentLineItemValue('item', 'custcol_list_rate',receivedInvoice.items[i].price);
  createdInvoice.setCurrentLineItemValue('item', 'amount',receivedInvoice.items[i].totalAmount);
  createdInvoice.setCurrentLineItemValue('item', 'description',receivedInvoice.items[i].description);
  createdInvoice.commitLineItem('item');
}

var recordNumber = nlapiSubmitRecord(createdInvoice,false,true);

In this one I think I'm committing a performance heresy by opening the record in dynamic mode, but I'm not sure how else to get the possible line items.在这个中,我认为我通过在动态模式下打开记录来犯下性能异端,但我不确定如何获取可能的行项目。 Simply opening a new record in dynamic mode clocks in at around SLOW seconds.只需在大约SLOW秒内在动态模式下打开新记录即可。 Again, the submit is where most time is being eaten (often around OH DEAR SWEET MOTHER OF HORRIBLE seconds), although this one eats a decent amount of time as I mess with the line items, again presumably because I have opened the record in dynamic mode.再次,提交是大部分时间被消耗的地方(通常在OH DEAR SWEET MOTHER OF HORRIBLE几秒左右),尽管当我把订单项弄得一团糟时,这一次消耗了相当多的时间,这大概是因为我已经打开了动态记录模式。

var customerPayment = nlapiCreateRecord('customerpayment',{recordmode: 'dynamic'});

customerPayment.setFieldValue('customer', parseInt(customerId));
customerPayment.setFieldValue('payment', paymentAmount);
customerPayment.setFieldValue('paymentmethod', paymentMethod);
customerPayment.setFieldValue('checknum', transactionId);
customerPayment.setFieldValue('currency', currency);
customerPayment.setFieldValue('account', account);

var applyCount = customerPayment.getLineItemCount('apply');

if(applyCount>0)
{
    for(var i=1;i<=applyCount;i++)
    {
        var thisInvoice = customerPayment.getLineItemValue('apply','refnum',i);

        if(thisInvoice == invoiceToPay)
        {
            customerPayment.selectLineItem('apply', i);
            customerPayment.setCurrentLineItemValue('apply','apply','T');
            customerPayment.setCurrentLineItemValue('apply', 'amount',paymentAmount);
            customerPayment.commitLineItem('apply');
        }
    }

}
nlapiSubmitRecord(customerPayment,false,true);

A few thoughts:一些想法:

  1. (just to get it off my chest) Integrating your accounting system with Netsuite just sounds odd. (只是为了摆脱我的想法)将您的会计系统与 Netsuite 集成听起来很奇怪。 Netsuite is an accounting system and generally is the accounting system of record for the orgs that use it. Netsuite 是一个会计系统,通常是使用它的组织的会计记录系统。 If you are not using Netsuite for accounting you might want to consider what utility it has for the price and get off it.如果您不使用 Netsuite 进行会计处理,您可能需要考虑它的价格效用并放弃它。
  2. When I integrate an external system with Netsuite I generally try to make it async.当我将外部系统与 Netsuite 集成时,我通常会尝试使其异步。 I do this by getting the raw info into a custom record and then kick off a scheduled script to process the queued update.为此,我将原始信息放入自定义记录中,然后启动预定脚本来处理排队更新。 This lets my api return quickly.这让我的 api 快速返回。 When I process the queue I store errors in the queue record so that if anything comes up I can fix the data or code and re-submit it.当我处理队列时,我将错误存储在队列记录中,以便如果出现任何问题,我可以修复数据或代码并重新提交。
  3. One apparently major source of slow transaction submit (aside from slow UE scripts) is the state of your books.事务提交缓慢的一个明显主要来源(除了缓慢的 UE 脚本)是您的账簿状态。 I had a startup customer who did really well but they never closed their books and they were using IIRC Average Costing.我有一个创业客户,他做得很好,但他们从不关账,他们使用 IIRC 平均成本计算。 Every time they saved a posting transaction Netsuite was recalculating the whole period (which at the point where things were grinding to a halt was about 2 years of records for a very busy site).每次他们保存一个发布交易时,Netsuite 都会重新计算整个时间段(对于一个非常繁忙的站点来说,在事情陷入停滞时大约是 2 年的记录)。 When they started closing periods transaction save times went way down.当他们开始关闭期间,交易保存时间大大减少。 When they converted to standard costing transaction save times went down again (I imagine LIFO would be faster than Avg and slower than standard but YMMV)当他们转换为标准成本交易时,节省时间再次下降(我想 LIFO 会比 Avg 快,比标准慢,但 YMMV)

Also notes on your code.还要注意您的代码。

The normal way to create an invoice is创建发票的正常方法是

nlapiTransformRecord('customer', customer.customerId, 'invoice'); or nlapiTransformRecord('customer', customer.customerId, 'invoice', {recordmode:'dynamic'});nlapiTransformRecord('customer', customer.customerId, 'invoice', {recordmode:'dynamic'});

I've never tested whether this has an effect on submit times but it might help since NS will start the save from a slightly better place (grasping at straws but with NS sometimes non-obvious changes have speed benefits)我从来没有测试过这是否对提交时间有影响,但它可能会有所帮助,因为 NS 会从一个稍微好一点的地方开始保存(抓住稻草,但 NS 有时不明显的变化有速度优势)

Also not sure how changing the customform in dynamic mode works.也不确定如何在动态模式下更改自定义表单。 When you know the form you can also add that to the init defaults:当您知道表单时,您还可以将其添加到 init 默认值中:

{recordmode:'dynamic', customform:receivedInvoice.transactionType}

One of the reasons why you Submit is slow might be there are a lot of User Event scripts attached to the record.您提交缓慢的原因之一可能是记录中附加了大量用户事件脚本。 Since it is the Restlet that saves the record, it will trigger the User Event scripts.由于是 Restlet 保存记录,所以会触发用户事件脚本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM