From dev-return-4842-apmail-plc4x-dev-archive=plc4x.apache.org@plc4x.apache.org Thu Oct 8 11:07:38 2020 Return-Path: X-Original-To: apmail-plc4x-dev-archive@locus.apache.org Delivered-To: apmail-plc4x-dev-archive@locus.apache.org Received: from mailroute1-lw-us.apache.org (mailroute1-lw-us.apache.org [207.244.88.153]) by minotaur.apache.org (Postfix) with ESMTP id 0EDAD19E19 for ; Thu, 8 Oct 2020 11:07:38 +0000 (UTC) Received: from mail.apache.org (localhost [127.0.0.1]) by mailroute1-lw-us.apache.org (ASF Mail Server at mailroute1-lw-us.apache.org) with SMTP id B2E901238C6 for ; Thu, 8 Oct 2020 11:07:37 +0000 (UTC) Received: (qmail 65235 invoked by uid 500); 8 Oct 2020 11:07:37 -0000 Delivered-To: apmail-plc4x-dev-archive@plc4x.apache.org Received: (qmail 65212 invoked by uid 500); 8 Oct 2020 11:07:37 -0000 Mailing-List: contact dev-help@plc4x.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@plc4x.apache.org Delivered-To: mailing list dev@plc4x.apache.org Received: (qmail 65199 invoked by uid 99); 8 Oct 2020 11:07:36 -0000 Received: from spamproc1-he-fi.apache.org (HELO spamproc1-he-fi.apache.org) (95.217.134.168) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 08 Oct 2020 11:07:36 +0000 Received: from localhost (localhost [127.0.0.1]) by spamproc1-he-fi.apache.org (ASF Mail Server at spamproc1-he-fi.apache.org) with ESMTP id D3355C0158 for ; Thu, 8 Oct 2020 11:07:35 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamproc1-he-fi.apache.org X-Spam-Flag: NO X-Spam-Score: -0.002 X-Spam-Level: X-Spam-Status: No, score=-0.002 tagged_above=-999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HTML_MESSAGE=0.2, RCVD_IN_MSPIKE_H2=-0.001, SPF_PASS=-0.001] autolearn=disabled Authentication-Results: spamproc1-he-fi.apache.org (amavisd-new); dkim=pass (2048-bit key) header.d=gmail.com Received: from mx1-ec2-va.apache.org ([116.203.227.195]) by localhost (spamproc1-he-fi.apache.org [95.217.134.168]) (amavisd-new, port 10024) with ESMTP id owd_Cj6ZUhNi for ; Thu, 8 Oct 2020 11:07:34 +0000 (UTC) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=209.85.167.67; helo=mail-lf1-f67.google.com; envelope-from=ben.hutche@gmail.com; receiver= Received: from mail-lf1-f67.google.com (mail-lf1-f67.google.com [209.85.167.67]) by mx1-ec2-va.apache.org (ASF Mail Server at mx1-ec2-va.apache.org) with ESMTPS id 4A2B2BC45B for ; Thu, 8 Oct 2020 11:07:34 +0000 (UTC) Received: by mail-lf1-f67.google.com with SMTP id d24so5986587lfa.8 for ; Thu, 08 Oct 2020 04:07:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=9Ihp52r/N8AQVtk2+nIdKnbGvQl1W9qIWoEDdsBDPEU=; b=nLVkbLbWwg/C09PZw6fWz/ddx9rgO6jue5Lt687I4uk00mlZEFpfjMgVVqC+dMopu2 /GDtvVnRfeZ4IXCvfDCcaXjsfKj+pf0cGjA1NKCTd0Tv2uB6EPjHYwshuK9iK/iroTWq fZ1F5dMPGHJRznnUytcQ4XgEB2uJ5MJUYfWYpvFJPKCw4Lh8A0zFgFOLQbG5K8ci6tB9 e6JXZPz1aFxd35X1k2H20Bayd7euH9fOOBlsNEW5HXkapG4VAOh/Ldm7+ZIC13zQnWt2 Hhdfy1Xw7YE3kWaCznEAvu4gKlM2EumynwGMgLBa6vLD0MARX7xRSPZCCxk9cxG3TQXq mIFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=9Ihp52r/N8AQVtk2+nIdKnbGvQl1W9qIWoEDdsBDPEU=; b=t4g4pvlDmxMtWmM1LQ1iW+QjjFovlW7zwkTRICEZmQUOSe9ppBgEflbLDsrp0vXrWH JIeYgiNvQHagt+TpK5xRnAxmqcc+LZE2ZGZVxTAfmZJpJgG2f6e676F8pIImPetHN6le hmTUBz2lOphAhchLEXB/iyMpdB7GaPiQ7e9/ZceNFUN1jY6n0lF4BnRhf9zF9PAjrjL6 kJEq46Dif8r3d6Tfy2ia3WA/LryNSBcsl94239EUTpXmcO4sjBoxybQh/IhPIDIq6qWD aLW7ge7BBtHVteJ/GoH8gSjXtVczM04bWhmgAGy61YRAiX+yICv0CFMPgjfU2egGF8Cd Wv3w== X-Gm-Message-State: AOAM531LJF5PDE/+kIfbroNGv9sV4lj+PiqTBctYToEj4qx5M0H1Q4vp NFVnAXfwy1sFf+r2SfmsxMBg9lEHfbC7pwBfnJ2Hf1oQ5sM= X-Google-Smtp-Source: ABdhPJzL68JM9O3dUGYDvwZqCnOg41SDExS2zoM/evJl0itPDRmU0cyp4v1CodXvTZhcA+cdKBqJpOGmz9/CGrxHzPw= X-Received: by 2002:a19:cc95:: with SMTP id c143mr416965lfg.99.1602155252777; Thu, 08 Oct 2020 04:07:32 -0700 (PDT) MIME-Version: 1.0 References: <160196962358.32230.13715353608421961233.asfpy@gitbox.apache.org> In-Reply-To: From: Ben Hutcheson Date: Thu, 8 Oct 2020 07:07:21 -0400 Message-ID: Subject: Re: Cost of Exceptions [was: chrisdutz commented on a change in pull request #192: Refactor Field Handler Classes] To: dev@plc4x.apache.org Content-Type: multipart/alternative; boundary="000000000000b7869205b126d6f1" --000000000000b7869205b126d6f1 Content-Type: text/plain; charset="UTF-8" Hi Niclas, I'm definitely in favour of handling errors better. There have been a few cases I've seen where errors are thrown but the actual error shown doesn't explain what went wrong, or the error reported is different to the initial error. When using the kafka connector (but is probably in the scraper or pooledconnection somewhere) I noticed that it will try to poll the device at the same rate as normal (1000ms) when an error occurs. I'm in favour of making this configurable or using a back-off algorithm. Kind Regards Ben On Tue, Oct 6, 2020 at 5:37 AM Niclas Hedhman wrote: > On Tue, Oct 6, 2020 at 9:33 AM GitBox wrote: > > > One thing I've learnt recently, is that exceptions are extremely > > expensive, as creating the stack trace is expensive. is this code that is > > likely to produce any of "InstantiationException | > IllegalAccessException | > > InvocationTargetException | NoSuchMethodException" in normal execution? > If > > yes, we should probably change this and other parts where we use similar > > patterns to check first instead of silently catching exceptions. > > > > Chris is right; Exceptions are incredibly expensive and I have seen > instances where a few PLCs are put offline, and the supervisory system goes > into a snail pace, either due to excessive exceptions, aggressive retries > (without back-off), or both and sometimes with other "oh, didn't think of > that" ooopsies. > > In general, all faults in "real world" should not throw exceptions, and > should be viewed as "normality". And unfortunately, Java programmers (even > those in this field) tend to not think in "error scenarios" and only in > "sunny day paths". > > Personally, I got over the "exception craze" about 20 years ago, and try to > be exception-free. A few tricks to get there; > > 1. Event driven systems doesn't need "return values", hence a lot less > exceptions. Error conditions are different events and subscribers can > specialize in the handling. Making a system event driven instead of the > request/response type, takes a fair amount of unlearning and mind bending, > but worth it. > > 2. Try to figure out ahead of time if exceptions may be thrown by code I > don't control. > > 3. Don't create nor rethrow exceptions. If in dev/test mode, log an error > report containing all possible states that could affect the outcome and > then System.exit() as to indicate that there is a serious problem that > should not be ignored. In production, the error report is sent to > "operations" (containing info to forward to developers if needed) and tries > to recover. > > > // Niclas > --000000000000b7869205b126d6f1--