An Internet of Things-Based Cluster System for Monitoring Lactating Sows’ Feed and Water Intake

: Acquiring real-time feeding information for monitoring lactating sows and their feeding requirements is a challenging task. Real-time data represent an important input for numerous tasks, such as disease monitoring, nutritional regulation, and feeding modeling. However, concurrently monitoring large numbers of sows and processing the real-time information for modeling is challenging using existing platforms. In this paper, we describe the design and development of a system that monitors and processes sows’ feed and water consumption in real time. The system was cus-tom-developed using open-source networking technologies. The system consists of three components: an electronic sow feeder connected to a central controller via a CAN network, an MQTT service cluster, and a data processing program. The MQTT service cluster uses Netty to develop a single service node, and it uses Zookeeper and Redis to complete node registration, discovery, and scheduling. The data processing program is based on Spark and Flink. We conducted comparative testing of three common codecs (Java Serializer, Marshalling, and Protostuﬀ) to further speed up data transmission. The results of the experiment show that, with three service nodes, the system can concurrently monitor up to 20,000 sows. Moreover, the system achieves optimal performance when monitoring 10,000 sows at the same time, with a TPS of 6399 pcs/s and an RT of 643 ms.


Introduction
The Internet of Things (IoT) is applied in various industries, including smart manufacturing [1], smart cities [2], smart healthcare [3], precision agriculture [4], and smart livestock farming [5], through various applications involving machine-to-machine and machine-to-human interactions [6].Intelligent machines continuously send data to cloud servers via the internet.The data are analyzed and presented as per the requirements of the end-users [7].The IoT has many applications in pig farming.Monitoring the parameters related to lactating sows is one of the most vital aspects [8,9].The feed intake and water consumption of lactating sows are required in real time for precision feeding in pig farms.These data are vital for improving feeding practices and enabling the timely prediction of diseases [10,11].
Electronic sow feeders (ESFs) are commonly used to record the feed information of lactating sows [12].ESF systems are used during the lactation period to control the delivery of feed to individual sows in a farrowing house.Depending on the system, ESFs may also record data for individual feed intake and the timing of eating events, and the data can be rapidly transmitted back to cloud servers through the network [13].With the help of ESFs and information technology, modern precision feeding systems for lactating sows have demonstrated their ability to meet individual requirements more efficiently [14].Ma et al. devised an intelligent feeding equipment and network service platform, which can provide a convenient and intelligent feeding method as well as multiple areas of pig management.The platform realizes the recording of the daily feeding amount of pigs from multiple areas [15].Chen et al. developed a precision feeding system consisting of intelligent feeders, environmental monitoring devices, a wireless data transmission module, and a remote monitoring terminal.The Alibaba Cloud server was connected using a longrange radio (LoRa) module and a general packet radio service (GPRS) module to achieve the long-distance transmission of feed and water intake data [16].Although the above systems have realized the collection and management of pig feeding information, there is little mention of the number of devices connected to the systems and the implementation details of data transmission.
With the intelligent development of pig farming devices, higher demands have been placed on the stability and concurrency of pig farm IoT systems [17,18].There are currently some commercial IoT platforms, such as ThingSpeak cloud platform, Microsoft Azure, and other platforms, that can support edge device access [19].However, in terms of actual use on pig farms, commercial IoT platforms face issues such as cumbersome configuration, difficulty in flexible customization, and high costs [20].With the application of technologies such as clusters, distributed systems, and microservices in animal husbandry, centralized servers are shifting towards distributed servers [21].This shift provides new solutions for the development of high-performance IoT systems.A previous study [22] used microservices and cloud paradigms to implement a highly scalable livestock IoT platform.The microservice architecture of a distributed IoT system discussed in detail in [23] consists of a group of microservices that communicate with each other synchronously or asynchronously.Another study [24] involved the design of a sensor network based on a microkernel operating system.Based on the idea of modular design, the functional modules and control modules were organically combined so as to realize the monitoring and collection of farmland and livestock management information.
The aim of this study was to design an Internet of Things-based cluster system for lactating sows utilizing electronic sow feeders, a message queue telemetry transport (MQTT) service cluster, and data processing programs to collect and monitor the feed and water intake of lactating sows in real time.The MQTT server developed based on Netty provides connection services for ESFs.In order to improve the concurrency and stability of the system, an MQTT server cluster suitable for real-time applications in pig farms was built based on Zookeeper.A scheduling server was added to ensure the reasonable distribution of MQTT service nodes.Moreover, this system also includes a data processing platform that can monitor and record feed intake, water consumption, and ESF operating status.Our main objectives were (1) to design and develop a stable ESF and central controller for monitoring lactating sows, (2) to develop a high-concurrency MQTT server cluster to collect real-time values of central controllers attached to the server node, (3) to develop a data processing platform for recording and tallying the collected values at the pig farm, and (4) to utilize a user-friendly interactive interface for displaying real-time information.The present study included the design, implementation, and verification of the system.
The details of this study are presented in Section 4. Section 1 provides a brief description of related work reported in the literature and outlines the objectives for the present study.Section 2 offers technical details regarding the development of the system, including the description of the system architecture, a brief overview of the design of the ESF and central controller, the MQTT server cluster, the data processing program, and the data transmission security.The experimental results, accompanied by case study data, are discussed in Section 3. Section 5 provides a summary, along with conclusions, and outlines the future scope of the study.

The Architecture of the System
The system's architecture (Figure 1) includes three significant components: an electronic sow feeder (Figure 1a) connected to a central controller (Figure 1b) via a CAN network, an MQTT service cluster, and a data processing program.An electronic sow feeder was designed to monitor the feeding status of lactating sows.It was installed above each stall in the experiment and connected to a touch rod (which initiated feed and water discharge upon the sow's touch), a feed discharge pipe, and a water discharge pipe (Figure 1d) inside the feed trough.A central controller controls all electronic sow feeders within a unit through the controller area network (CAN).This is because the network signal is poor in the remote environment of the pig farm.The use of CAN lines can ensure the stable connection of equipment.In addition, we developed a PDA to set parameters for the electronic feeder through a QR code (Figure 1c).The electronic sow feeder records the daily feed and water intake, and the central controller transmits the data to the MQTT service cluster and data processing program running in the cloud through the MQTT protocol.(1) The central controller sends request to scheduling server, (2) permission information is verified for the central controller, (3) an MQTT server node is selected, (4) the internet protocol (IP) and port of the selected server node are returned, (5) the central controller establishes a connection with the service node, (6) the service node transfers the received data to the data processing program, (7) composition of data processing program, and (8) PC and phone.

ESF and Central Controller
Figure 1 shows the designed system architecture, which includes the ESF and central controller.Detailed information of the components and instrumentation is provided in Table 1.An entire circuit setup with its components is included inside the plastic container.The feeder control method adopts STM32 (ST Microelectronics 32-bit Microcontroller) embedded technology (Made by STMicroelectronics, Geneva, Switzerland).The core board chip uses STM32F103VET6 with large-capacity storage.The CPU is an ARM Cortex-M3, and the internal clock frequency of the main chip is increased to 72 MHz.The maximum power dissipation is 434 MW, and the operating temperature range is −40 °C to 85 °C.The main interfaces of the core circuit include CAN-bus communication, RS-232 serial communication, WiFi communication, motor control output, flow meter A/D acquisition, and alarm light display, as shown in Figure 2. The central controller is a 12-inch touchscreen all-in-one machine (Huaxiang Zhichuang Technology Co., Ltd., Shenzhen, China).The system runs on Windows 10 (Intel(R), Celeron(R) CPU J1900, 1.99 GHz, Intel Corp.Santa Clara, CA, USA), with a memory (RAM) capacity of 4.00 GB.The central controller dynamically records and displays the actual feed intake and water consumption of sows, with the operating interface programmed using the C++ language.

MQTT Service Cluster
The purpose of the MQTT cluster service is to complete the reception of data and the issuance of operation instructions [25].In this study, an MQTT server was designed based on the Netty [26] network communication framework to receive and parse data.

MQTT Service Node Design
Netty is a framework for quickly developing high-performance and reliable network servers that is easy to use [27].The MQTT protocol is a very simple, lightweight information transmission protocol designed for use with restricted equipment, low bandwidth, high latency, or unreliable networks [28].Many studies have shown that MQTT outperforms other protocols [29][30][31].
This section describes the design of a single-node server based on Netty and MQTT protocols.When the node starts, the ServerBootstrap component of Netty binds to a network port to listen to and process connection requests from the central controller.After a successful connection, the WorkerEventLoopGroup receives data sent by the central controller and allocates processing threads from the thread pool to the corresponding connection channels.The encoding and decoding of pig feeding data are achieved using MqttDecoder and MqttEncoder.Finally, data parsing is performed through a self-written MqttServerHandler.The feed and water intake data are sent to MySQL [32], while the electronic feeder log data are sent to Kafka [33].The process of the server handling Connect, Subscribe, and Publish requests is depicted in Figure 3.

MQTT Service Cluster Construction
As the number of central controllers in pig farms increases, single-node servers quickly reach performance bottlenecks, making it difficult to monitor a large number of sows in real time.The cluster architecture can upgrade system scalability, stability, and performance at a lower cost [34].Ensuring the cluster can provide services to the central controller of the pig farm normally during the cluster construction process, and the registration, scheduling, and management of nodes, are very important.The cluster organizational structure is shown in Figure 4.

A. Registration of cluster nodes
The registration of MQTT service nodes in the cluster is completed using ZooKeeper and Redis.After the successful initialization of MQTT service nodes, corresponding ephemeral nodes are created in Zookeeper.The ephemeral nodes store information such as the MQTT server name, IP (Internet Protocol), port, and the number of connected central controllers.The system utilizes Zookeeper as the registration center, with the scheduling server acting as the Zookeeper client.By employing the Zookeeper node listening mechanism, it detects the online and offline status of MQTT servers and synchronizes data to Redis.The node registration process is shown in Figure 5.

B. Connection and selection of cluster nodes
The central controller of the pig farm sends data based on the MQTT protocol, so the central controller needs to use socket information (IP and port) to establish a connection with the cluster.Each MQTT node in the cluster has its own socket information, making the central controller unable to establish a connection with the cluster through a unified entry point.Moreover, the service nodes of the cluster need to be scheduled reasonably.To address the issues of node connection and node scheduling in the cluster, we propose deploying a scheduling server in the MQTT service cluster.This provides a unified connection interface for the central controller and realizes the reasonable scheduling of service nodes.The scheduling server is implemented using the Netty framework, essentially functioning as an HTTP (Hypertext Transfer Protocol) server.The central controller accesses the HTTP interface provided by the scheduling server (Figure 1(1)).After receiving the HTTP request, the system performs authorization validation (Figure 1(2)) and then selects appropriate MQTT service nodes using a load-balancing algorithm (Figure 1(3)).The scheduling server returns the IP and port of the selected node as interface response values to the central controller (Figure 1(4)).After receiving the socket information, the central controller establishes a connection with the target node (Figure 1(5)).
The node-scheduling server selects suitable service nodes for the central controller of the pig farm by implementing load-balancing algorithms.The algorithmic selection result is primarily determined by two factors: the load of service nodes, which refers to the number of connected pig farm controllers, and the weight of server nodes, which represents the performance configuration of the servers.
The load-balancing algorithm adopts the concept of a weighted connection count.It selects nodes with higher weights and lower loads for the central controller each time.Assuming there are n server nodes, the selection rules are as shown in Equation (1).

i ( )
, ( 0,1, 2,..., 1) ( ) where i is the selected server node; C (Si) is the number of connections held by server node i; W (Si) is the weight of server node i; W(Si) > 0; and Csum = ∑C(Si) is the total number of connections held by server nodes in the cluster.
Because Csum is a constant, and division requires more CPU cycles than multiplication, the optimization of the judgment condition can be represented as in Equation ( 2).

( ) ( ) ( ) ( )
When there are multiple nodes in the cluster, this rule is utilized to sort and identify the node that currently has a lower load and higher weight.

Transmission Security Design
Devices may be subject to malicious connections from unrelated devices when service nodes provide MQTT connections externally [35].This can lead to increased server load and affect normal operation.Because the MQTT CONNECT message permits the inclusion of a username and password, the system is designed with a dynamic passwordgeneration algorithm for authentication during the establishment of connections by the central controller.
The core concept of dynamic password generation is illustrated in Figure 6   The algorithm incorporates the current system time into the calculation, enabling the addition of timeliness to the generated verification code.The summation of the split characters will ignore the seconds when the time format is set to "yyyy-MM-dd-hh-mm".The system will yield the same result when verifying the verification code within one minute.If the time format changes to "yyyy-MM-dd-hh", then the expiration time changes from one minute to one hour.Additionally, the efficiency of authentication is improved by sending the dynamic password only once for authentication.However, the password generation algorithm requires setting factory information for the central controller in the system, including registration string length (len), index (m), and time format.The algorithm is suitable for scenarios where device registration information can be prepared in advance.

Integration of ProtoStuff Encoder and Decoder
Netty can integrate third-party encoders to accelerate data transmission efficiency.We compared mainstream serializers such as Java Serializer, Marshalling, and Protostuff.The experimental results demonstrate that Protostuff exhibits the highest efficiency.Therefore, we ultimately finalized the integration with Protostuff.Due to the absence of corresponding encoders and decoders in Netty, users need to implement Protostuff encoders and decoders by themselves.The Protostuff encoder and decoder need to inherit from the MessageToByteEncoder class and the ByteToMessageDecoder class provided by Netty.It is also necessary to override the encode() and decode() methods within the inherited classes.Thus, the data flow sent and received by the MQTT server is directed to the Protostuff encoder and decoder for processing.

Data Processing Program
The system was built on a big data framework to establish a data processing platform for the statistical analysis of data.The platform was built upon HDFS (Hadoop Distributed File System) [36] and Spark [37] to establish an offline data warehouse, which is utilized for processing parsed sow production data.The data platform constructs hierarchical dimension tables, including fields such as pig farm ID, house number, stall number, entry time, exit time, and farrowing date.The data platform utilizes dimensional tables to perform statistical analyses on litter size, number of live births, feed intake, water intake, and other data at different time intervals and pig farm granularities.The system utilizes Kafka and Flink for the real-time collection and processing of controller log data.The system conducts filtering and aggregation operations in Flink to calculate the number of devices online, the quantity of alarms, alarm information, and operational dynamics for intelligent devices in each pig farm.The architecture of the data processing platform is illustrated in Figure 7.

Test Environment
The system described in this paper was deployed on three Alibaba Cloud servers.The servers are of the shared computing type n4 (ecs.n4.small).The configuration information parameters are as follows: Intel(R) Xeon(R) CPU E5-2682 v4 @ 2.50 GHz, 1 vCPU, 2 GB RAM, and 100 GB HDD.The operating system was Alibaba Cloud Linux release 3, and JDK version 1.8 was used.Additionally, two computers with 8-core CPUs were used as load-testing machines.The detailed configuration information parameters are as follows: Intel(R) Core(TM) i5-1035G1 processor, 16 GB RAM, 500 GB solid-state drive, and Windows 10 operating system.

Test Indicators
Transactions per second (TPS): TPS is a performance metric for system processing capability, indicating the number of messages processed per second.A higher TPS indicates better system performance.
System response time (RT): RT is the time it takes for the system to respond to user input or requests.A shorter system response time indicates better system performance.
Error rate (ER): ER is the number of request errors as a percentage of the total number of requests.

A. Performance Testing of the Scheduling Server
The test involved performance testing of the scheduling server.The performance of the scheduling server was tested and compared with mainstream Tomcat web applications.The Tomcat web application was written in the Java programming language.We employed JMeter to conduct separate tests on both the Tomcat web application and the scheduling server [38].The testing process was as follows: (1) Ten sets of HTTP requests were configured in JMeter.(2) The request threads were configured to start and complete within 3 s for each of the three cycles.(3) The comparison of the response time, throughput, and failure rate of the two systems was based on the JMeter aggregated report.

B. Load-balancing algorithm correctness testing
The test utilized three server nodes: node1, node2, and node3.The weight ratio among the three nodes was 6:3:1 with an initial connection count of 0. The testing machine sent HTTP requests to the scheduling server to trigger the load-balancing algorithm.After receiving responses, the testing machine recorded the node selection results to verify the correctness of the algorithm.The test evaluated the correctness of the algorithm under scenarios of node failure and reconnection after disconnection.The testing process was as follows: (1) Firstly, all three server nodes were simultaneously started.Then, during the test machine sending the request, we shut down the server node1.(2) Firstly, both server node2 and node3 were simultaneously started.Then, during the test machine sending the request, we opened server node1.(3) We recorded the node selection results.

C. Cluster Performance Testing
The average response time and the number of requests processed per unit time by the cluster in handling MQTT requests were tested using JMeter software (version: 5.6.2).The testing process was as follows: (1) We configured multiple sets of MQTT request counts and completed initialization within 1 s.(2) Each MQTT request sent a 507 byte JSON string to the server.(3) The cluster parsed the data and replied with a successful reception message.

D. Encoding and decoding efficiency testing
In order to test the impacts of different encoding and decoding methods on MQTT server data transmission, we compared the performances of three encoding and decoding methods: Java serialization, Marshalling, and Protostuff.The testing process was as follows: (1) The testing machine was configured with 100 thread groups and sent data three times.It sent 100, 500, and 1000 packets each time.The packet size was 1250 bytes and included the current timestamp information T1.(2) The tested program appended the current timestamp information T2 to the data packet after completing data parsing and sent the data packet back to the load-testing machine.(3) The testing machine calculated the response time Trs of the program based on the two timestamps (T1 and T2) in the packet.

Scheduling Server Performance Test Results
The test results are shown in Figure 8a,b.The response time of the scheduling server was within 250 ms under 22,000 requests.The overall response time of the scheduling server was faster than that of the Tomcat web application.The TPS of the Tomcat Web application peaked at 6301 pcs/s with 16,000 requests, accompanied by a response time of 153 ms.The TPS of the scheduling server peaked at 7351 pcs/s with 18,000 requests, accompanied by a response time of 145 ms.The scheduling server exhibited an increase of 1050 pcs/s compared to the Tomcat application.The Tomcat web application and the scheduling server experienced request failures at 20,000 and 22,000 request counts, respectively.The failure rates of both began to increase after the number of requests exceeded 20,000.Clearly, the increase in resource utilization led to a higher failure rate.

Load-Balancing Algorithm Correctness Test Results
The test results are shown in Figure 8c,d.Figure 8c shows the change in node connections when node1 crashes.When node1 was shut down after the 5000th request, the connection counts of node2 and node3 gradually approached a ratio of 3:1. Figure 8d illustrates the change in node connection count during the reconnection of node1.Node1 was prioritized for connection requests after it was started at the 1500th request.Finally, the connection ratio of the three nodes tended towards 6:3:1.
The test results indicate that nodes with higher weights received more connections, but they did not hold all connections.As the number of requests increased, the proportion of connections among all nodes tended to approach the ratio of node weights.The results demonstrate that the load-balancing algorithm was influenced by both weights and connection counts, and it functioned properly even during node failures and reconnects.

Cluster Performance Test Results
The test results are shown in Figure 8e.When the number of requests reached 4000, 6000, and 8000, the TPS of the cluster gradually increased to 3699 pcs/s, 5917 pcs/s, and 6050 pcs/s respectively.When the number of requests reached 10,000, the TPS peaked at 6399 pcs/s, with a corresponding response time of 643 ms.After the number of requests exceeded 10,000, the TPS gradually decreased as the system reached its bottleneck.When there were 20,000 requests, the TPS was 3738 pcs/s, with a response time of 1308 ms.The test results indicate that the system performed well with 10,000 connections.Overall, it was capable of meeting the communication requirements of the central controller in pig farms.

Encoding and Decoding Efficiency Test Results
The test results are shown in Figure 8f.Under the test with 10,000 data packets, Protostuff showed a response time of 258 ms, while Marshalling and Java serialization showed 348 ms and 376 ms.The test results indicate that Java serialization had the longest response time, while Protostuff had the shortest response time.The advantages of Protostuff are more obvious with many data.

PC and App Application Interface
The system supports real-time access from both mobile phones and computers.The equipment status interface (Figure 9a) provides real-time displays on the deployment, online, and abnormal status of electronic sow feeding in the pig farm, along with detailed alarm information prompts.When the sow's feed intake is less than 40% of the planned feeding amount set by the electronic sow feeding, the system determines that the sow's feed intake is insufficient.Clicking on the number allows for querying the location of the alarmed electronic sow feeding in the stall.Figure 9b provides a summary of information for each farrowing house, including the number of sows, total feed intake for the day, and total feed intake for the batch.The feeding status interface displays detailed information for each sow in the stall (Figure 9c), including its ear tag number, farrowing information, and feed intake level.The system also supports displaying historical feed intake data for the sow since its entry into the stall in the form of a line graph.The feeding scheme interface (Figure 9d) displays the feeding plan for sows throughout the entire farrowing cycle, including key information such as daily feeding schedules and feed-to-water ratios.As shown in Figure 10, the PC interface displays the online status and detailed information of the MQTT server nodes in the cluster.This information includes TCP (Transmission Control Protocol) connection count, weight information, and node IP addresses, as well as the CPU, memory, and disk usage of the servers.Additionally, the system monitors the resource usage of key components such as MySQL, Zookeeper, Redis, and Kafka.When the system encounters abnormalities, it will notify administrators via email for timely resolution.The system displays statistical data after the completion of data platform processing in the backend management interface (as shown in Figure 11).The interface presents data such as feed and water intake per farrowing house, daily farrowing statistics, sow feeding plans, and sow anomalies.Additionally, it allows for querying detailed meal information for each sow throughout the day.

Analysis of Feeding Behaviors in Pig Farms
This system is installed at the ZhongRenWang sow farm in Baise City, Guangxi Province, China (longitude: 105.465639, latitude: 24.595144).We installed equipment in five farrowing houses of the pig farm, with each farrowing house installing 1 central controller and 59 electronic sow feeders.In this section we analyze the feeding data of lactating sows collected from 1 June 2023 to 1 February 2024.The fields of the original data are shown in Table 2.We eliminated data with negative values for feed and water intake and discontinuous entry dates.The time range of the production data of each lactating sow is from the time of entry to the stall to the time of exit from the stall.After cleaning the data, the production data of 1447 lactating sows were obtained.Moreover, descriptive analysis of the obtained data was performed using SPSS.

Production Interval Days Frequency Statistics
We calculated the frequency of different production interval days by analyzing the time intervals between sows in the same stall within each farrowing house (i.e., the time from the end of one sow's lactation to the beginning of the next sow's lactation).The time interval was calculated by subtracting the entry time of the next sow from the exit time of the previous sow.Finally, after the calculation of all stalls was completed, the number of occurrences of different time intervals was counted.
The frequency distribution of production interval days for each farrowing house is shown in Figure 12a.SPSS statistical indicators are shown in Table 3  The data reflect the fact that the sow farms will wean the lactating sows around 20 days.Weaning in intensive pig production usually occurs between days 21 and 28 of age, which is beneficial for sow recovery and piglet survival [39].Another frequently occurring weaning day in the No. 5 farrowing house is Day 13.This indicates that early weaning occurred in the farrowing house during a specific period.

Distribution of Prepartum Days Frequency Statistics
Figure 12c shows the frequency distribution of prepartum days for sows.It represents the number of days before parturition during which lactating sows entered the farrowing house.The number of prepartum days was obtained by subtracting the entry date from the farrowing date of the lactating sow.
SPSS statistical indicators are shown in Table 3.The most frequent prepartum days in each farrowing house are 13 d, 3 d, 12 d, 6 d, and 11 d.In intensive pig production, sows will enter the farrowing house about 7 days before parturition [40].The average data indicate that the farm typically places lactating sows in the farrowing house around 5.03 d-13.16d before farrowing, which is basically in line with the production rules of intensive pig farms.It is noteworthy that 94 sows in the No. 2 farrowing house were placed in the farrowing house only 3 days before farrowing.This may have increased the sows' stress response.The cause of this situation may be related to the fast production pace of this farrowing house.Through the above analysis, it has been made evident that sows in this pig farm enter the farrowing house 10 days before farrowing and are weaned 20 days after farrowing.Therefore, the average feed intake and average water consumption levels of sows within this time range were calculated for analysis.The results are shown in Figure 13.Sows showed a noticeable decrease in both feed intake and water consumption in the 3 days before farrowing.Sows consumed only a small amount of water and hardly ate on the day of farrowing.After farrowing, the feed intake and water consumption of sows started to increase gradually day by day.The growth rate was fastest during the first 7 days, slowed down between days 7 and 14, and stabilized after 14 days.In some farrowing houses, feed intake and water consumption decreased between 18 and 20 days.After consulting with the farrowing house manager, this was found to be related to the early weaning practice employed by the farm.
It is difficult to collect accurate feeding data for each production batch in traditional pig farms.Digital devices and systems can effectively address this issue.The production interval days can effectively reflect the production efficiency of the farrowing house [41].The lactating sows at an average of 4.8 days after weaning have a lower anestrus rate [42].By 1 week after weaning, 90-95% of the multiparous sows are expected to exhibit estrus [43].Pig farm managers can utilize this system to track the duration between production cycles in the farrowing house.Additionally, the production rhythm of the farrowing house should be reasonably arranged based on the duration of the lactating sow's estrus cycle.
Related research indicates that extending the weaning age from 19 to 28 days has a positive effect on pig performance in the nursery, resulting in increased body weight sold per pig weaned.This suggests that 25 days is the optimal age for weaning [41,44].Furthermore, increasing the weaning age from 18.5 to 24.5 days positively affected pig performance by increasing the average daily gain and feed intake [45].Using digital technology to count the number of prepartum and weaning days can help correct erroneous production strategies on pig farms.Furthermore, tracking the feed and water intake of lactating sows on different days will aid in establishing appropriate feeding plans for future pig farms.

IoT of Pig farm
We focused on constructing an Internet of Things (IoT) system specifically designed for the feeding requirements of lactating sows.Table 4 shows the architectural layers of the present and earlier systems, as well as data displays, data transmission, and cluster technology, confirming that the proposed monitoring system is reasonable compared to other similar systems.As the level of technology in pig farms increases, an increasing number of intelligent devices are being employed.Various intelligent devices are used in farrowing houses, such as environmental monitoring equipment [47] and weighing devices [49].Different intelligent devices can complement each other's functional deficiencies.However, the data barriers between different devices result in poor interoperability among them.This phenomenon is attributed to the adoption of different communication protocols and data formats by intelligent devices produced by different manufacturers.It is important to research universal data formats and communication protocols applicable to intelligent devices in pig farming [50].Due to the lack of standardization in communication protocols for intelligent devices, the development of IoT platforms currently faces challenges, including high complexity and poor adaptability.The IoT platform struggles to meet the connectivity requirements of various types of intelligent devices.
With the further development of deep learning, intelligent cameras and recording devices have begun to be used in pig farms.They play an important role in disease monitoring [51], behavior monitoring [52], and video-based weight estimation [53].The collection and storage of unstructured data such as video and audio also face challenges.The next focus of our research will be on meeting the connectivity requirements of diverse intelligent devices and achieving the remote collection of unstructured data (with a focus on audio and video) based on the developed system.In addition, pig farms have a high demand for the digital management of personnel, pigs, vehicles, and materials.It will be important to improve the management level of pig farms and prevent African swine fever by building a comprehensive digital platform for the entire pig farm using digital technology [54].
Establishing a cluster effectively addresses the issue of system concurrency in order to cope with the increase in intelligent equipment in pig farms.The volume of data in the Internet of Things (IoT) is also enormous.Effective data processing and analysis are required to extract useful information and insights.However, this requires powerful computing and data analysis capabilities [55].The maturity of e-commerce platforms has a certain reference value for the pig farm IoT.E-commerce need to deal with large amounts of product information, order data, and user information.Pig farm IoT systems also need to manage large amounts of pig data, sensor data, and environmental data.Efficient data storage and processing systems can be established drawing from the data management experience of e-commerce platforms.By leveraging the data management experience of e-commerce platforms, efficient data storage and processing systems can be developed to effectively manage and analyze pig data.In the process of digitization in pig farming, drawing from the experiences of other industries can accelerate its development.However, it is necessary to customize the design according to the characteristics and needs of pig farming.

Accurate Acquisition of Feed and Water Intake for Lactating Sows
The feed and water intake data described in this article refer to the amounts dispensed by the sow electronic feeder.We assume that the sow consumes all the dispensed feed and water.However, this assumption may not always hold true, highlighting a limitation that needs to be addressed in future work.References [12,56,57] suggest that using load cells to accurately measure pig feed intake is an effective solution.

Multi-Dimensional Data Collection and In-Depth Data Analysis
This article describes the remote monitoring of feed and water intake for lactating sows.However, actual production requires the collection of additional data, such as feeding times, body weight, litter size, weaning litter size, and weaning litter weight.Gathering more comprehensive data and scientifically analyzing them in conjunction with feed and water intake will help pig farm managers develop more effective feeding plans and advance the intelligent feeding of lactating sows.

Conclusions
We developed a smart IoT feeding system for lactating sows.The system implements an MQTT server based on the Netty framework to collect, transmit, parse, and store information regarding feed intake, water consumption, and the operational status of electronic sow feeders from the cloud.The system implements clustered job scheduling based on an HTTP server and a custom load-balancing algorithm for node selection.Additionally, we utilized the Spark and Flink computing frameworks to construct a big data analytics platform.This study lays the foundation for further in-depth analysis of sow feeding data.In actual operation on a pig farm, the system runs stably and can provide real-time feedback on sow feeding conditions.It holds practical value for application in the production and construction of pig farms.

Figure 1 .
Figure 1.Architecture of the IoT-based intelligent feeding equipment and cloud components.(a) Electronic sow feeder, (b) central controller, (c) PDA, (d) feed discharge pipe and water discharge pipe.(1)The central controller sends request to scheduling server, (2) permission information is verified for the central controller, (3) an MQTT server node is selected, (4) the internet protocol (IP) and port of the selected server node are returned, (5) the central controller establishes a connection with the service node, (6) the service node transfers the received data to the data processing program, (7) composition of data processing program, and (8) PC and phone.

Figure 2 .
Figure 2. Main interfaces of the core circuit.

Figure 3 .
Figure 3.The process of the server handling Connect, Subscribe, and Publish requests.

Figure 4 .
Figure 4.The components and overall processes used in the cluster.

Figure 5 .
Figure 5.The registration process of the MQTT server in the cluster.
and can be summarized as follows: (1) randomly generate a string S of length len; (2) extract characters from indices m, m − m/2, and m + m/2, convert these three characters to decimals, and calculate Num; (3) calculate result by combining Num with the system time (Time); (4) convert the result to a hexadecimal and insert it at position S[m] in the original string S to generate a new string S'.

Figure 6 .
Figure 6.The core concept of dynamic password generation.

Figure 7 .
Figure 7.The architecture of the data processing platform.(1) ODS stands for operation data source, (2) DWD stands for data warehouse details, (3) DWM stands for data warehouse middle, (4) ADS stands for application data service, and (5) OLAP stands for Online Analysis Processing.

Figure 8 .
Figure 8. Test result graph.(a) TPS results of scheduling server and Tomcat application, (b) RT and ER results of scheduling server and Tomcat application, (c) the change in node connections when node1 crashes, (d) the change in node connection count during the reconnection of node1, (e) TPS and RT test results for cluster performance, and (f) TPS comparison results of three serialization methods.

Figure 9 .
Figure 9.The mobile interface.(a) The equipment status interface, (b) the farrowing house summary information interface, (c) the feeding status interface, and (d) the feeding scheme interface.

Figure 10 .
Figure 10.The online status and detailed information of the MQTT server nodes in the cluster.Blue means free, orange means used.

Figure 11 .
Figure 11.The backend management interface for displaying statistical data.
. The highest frequency days in each farrowing house are 8 d, 4 d, 5 d, 5 d, and 8 d.The average production interval days are 10.79 d, 8.06 d, 6.95 d, 12.29 d, and 12.29 d.These data show that the production interval days of the pig farm range from 6.95 d to 12.29 d, and the production rhythm of the No. 2 farrowing house is faster than that of other houses.

Figure 12 .
Figure 12.Frequency distribution figure of days.(a) The frequency distribution of production interval days for each farrowing house, (b) the frequency distribution of weaning days for lactating sows, and (c) the frequency distribution of prepartum days for lactating sows.4.1.2.Distribution of Weaning Days Frequency Statistics Figure 12b shows the frequency distribution of weaning days for lactating sows.It represents the number of days post-farrowing when sows finish lactation.The number of weaning days was obtained by subtracting the farrowing date from the exit stall date of the lactating sow.SPSS statistical indicators are shown in Table 3.The most frequent weaning days for each farrowing house are 21 d, 23 d, 19 d, 18 d, and 21 d.The data reflect the fact that the sow farms will wean the lactating sows around 20 days.Weaning in intensive pig production usually occurs between days 21 and 28 of age, which is beneficial for sow recovery and piglet survival[39].Another frequently occurring weaning day in the No. 5 farrowing house is Day 13.This indicates that early weaning occurred in the farrowing house during a specific period.

Figure 13 .
Figure 13.Feed and water intake of sows.(a) The average feed intake for each farrowing house and (b) the average water consumption for each farrowing house.

Table 1 .
Brief information of components used.

Table 2 .
Fields of original data.

Table 3 .
Statistical indicator data of production interval days, weaning days, and prepartum days.

Table 4 .
Comparison of other similar systems with the present system.