A controller for controlling a control target, the controller comprising: a time-series database configured to store a record including data about the control target in chronological order; an executing engine configured to cyclically execute a control program in predetermined control cycles, wherein the control program includes a database writing program that functions as a data generator configured to generate data to be included in the record to enter the time-series database in every predetermined control cycle , the data generator is configured to complete a single process for generating the data within the predetermined control cycle, and the control program includes an instruction for starting the database writing program when a data writing condition is satisfied; and a nonblocking queue included in a volatile main memory that is configured to sequentially store the data generated by the data generator and is configured to store the data generated in a first control cycle of the predetermined control cycles, within the same first control cycle, wherein the time-series database includes a database manager configured to sequentially read the data stored in the nonblocking queue and store the read data into the time-series database , characterised in that the nonblocking queue includes a plurality of shared buffers (A, B) logically defined in the main memory and an occupancy list for managing a data storage status of each of the plurality of shared buffers (A, B), and data generated by the data generator is stored into a shared buffer specified from the plurality of shared buffers (A, B) by referring to the occupancy list , and the shared buffer storing the data is logically linked to another shared buffer storing preceding data. a time-series database configured to store a record including data about the control target in chronological order; an executing engine configured to cyclically execute a control program in predetermined control cycles, wherein the control program includes a database writing program that functions as a data generator configured to generate data to be included in the record to enter the time-series database in every predetermined control cycle , the data generator is configured to complete a single process for generating the data within the predetermined control cycle, and the control program includes an instruction for starting the database writing program when a data writing condition is satisfied; and a nonblocking queue included in a volatile main memory that is configured to sequentially store the data generated by the data generator and is configured to store the data generated in a first control cycle of the predetermined control cycles, within the same first control cycle, wherein the time-series database includes a database manager configured to sequentially read the data stored in the nonblocking queue and store the read data into the time-series database , characterised in that the nonblocking queue includes a plurality of shared buffers (A, B) logically defined in the main memory and an occupancy list for managing a data storage status of each of the plurality of shared buffers (A, B), and data generated by the data generator is stored into a shared buffer specified from the plurality of shared buffers (A, B) by referring to the occupancy list , and the shared buffer storing the data is logically linked to another shared buffer storing preceding data. <EOS>