A method for dynamic hardware acceleration, the method comprising the following steps executed at an internet-of-things, IoT, gateway: identifying a candidate task from a plurality of tasks executing in an operating environment, the operating environment within a hardware enclosure, the candidate task amenable to hardware optimization; instantiating, in response to identifying the candidate task, a hardware component in the operating environment to perform hardware optimization for the candidate task, the hardware component being previously inaccessible to the operating environment, wherein the hardware component includes a hardware accelerator (102A, 102B) configured to optimize or improve a class of task corresponding to a class of task of the candidate task; and executing, by the operating environment, the class of tasks amenable to the hardware optimization on the hardware component; wherein instantiating the hardware component includes: finding a component configuration in a database that corresponds to the class of tasks; configuring the hardware component with the component configuration; and allocating the configured hardware component to the operating environment; wherein the operating environment implements the IoT gateway; the IoT gateway is one of a plurality of IoT service devices serving an IoT device set; the plurality of IoT service devices are arranged hierarchically with IoT gateways directly serving the IoT device set at one end of the hierarchy and network-edge servers at the other end of the hierarchy; and the method further comprising: identifying a second candidate task from the plurality of tasks; failing to instantiate a second hardware component in the operating environment for a second class of tasks amenable to a same hardware optimization as the second candidate task; finding a second IoT service device in the hierarchy that can instantiate the second hardware component; and transferring the second class of tasks to the second IoT service device. identifying a candidate task from a plurality of tasks executing in an operating environment, the operating environment within a hardware enclosure, the candidate task amenable to hardware optimization; instantiating, in response to identifying the candidate task, a hardware component in the operating environment to perform hardware optimization for the candidate task, the hardware component being previously inaccessible to the operating environment, wherein the hardware component includes a hardware accelerator (102A, 102B) configured to optimize or improve a class of task corresponding to a class of task of the candidate task; and executing, by the operating environment, the class of tasks amenable to the hardware optimization on the hardware component; wherein instantiating the hardware component includes: finding a component configuration in a database that corresponds to the class of tasks; configuring the hardware component with the component configuration; and allocating the configured hardware component to the operating environment; wherein the operating environment implements the IoT gateway; the IoT gateway is one of a plurality of IoT service devices serving an IoT device set; the plurality of IoT service devices are arranged hierarchically with IoT gateways directly serving the IoT device set at one end of the hierarchy and network-edge servers at the other end of the hierarchy; and the method further comprising: identifying a second candidate task from the plurality of tasks; failing to instantiate a second hardware component in the operating environment for a second class of tasks amenable to a same hardware optimization as the second candidate task; finding a second IoT service device in the hierarchy that can instantiate the second hardware component; and transferring the second class of tasks to the second IoT service device. finding a component configuration in a database that corresponds to the class of tasks; configuring the hardware component with the component configuration; and allocating the configured hardware component to the operating environment; wherein the operating environment implements the IoT gateway; the IoT gateway is one of a plurality of IoT service devices serving an IoT device set; the plurality of IoT service devices are arranged hierarchically with IoT gateways directly serving the IoT device set at one end of the hierarchy and network-edge servers at the other end of the hierarchy; and the method further comprising: identifying a second candidate task from the plurality of tasks; failing to instantiate a second hardware component in the operating environment for a second class of tasks amenable to a same hardware optimization as the second candidate task; finding a second IoT service device in the hierarchy that can instantiate the second hardware component; and transferring the second class of tasks to the second IoT service device. identifying a second candidate task from the plurality of tasks; failing to instantiate a second hardware component in the operating environment for a second class of tasks amenable to a same hardware optimization as the second candidate task; finding a second IoT service device in the hierarchy that can instantiate the second hardware component; and transferring the second class of tasks to the second IoT service device.